Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Pleas help me correct a strange bug.

Pleas help me correct a strange bug.

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structures
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Redeemer dk
    wrote on last edited by
    #1

    I'm programming winsock. In my app i'm building in a feature for sending multiple files over the internet. In the filesend request i set up a loop where i send the filename and -size of the files the user has chosen to send. My problems is this: the second time the sender of the files calls the recv function to receive the "GETSIZE" string, then, instead of receiving "GETSIZE" it receives the "GETSIZE" string but shifted one place to the right, so it's actually "\0GETSIZE" without a terminating null but with a starting null instead. Here are the loops how they look on the sender's and the receiver's side. Receiver's side:

    char szTempChar[512];

    DWORD dwTotalFileSize = 0;

    char szFileName[MAX_PATH+1];

    bool bStop = false;

    char szRecvBuff[513];

    i = send(sckClient, "GETFILENAME", 12, 0);

    i = recv(sckClient, szRecvBuff, 512, 0);

    while (bStop == false)

    {

    strcpy(szFileName, szRecvBuff);
    
    i = send(sckClient, "GETSIZE", 8, 0);
    
    i = recv(sckClient, szRecvBuff, 512, 0);
    
    
    dwTotalFileSize = dwTotalFileSize + atoi(szRecvBuff);
    
    sprintf(szTempChar, "%s, %s bytes\\r\\n", szFileName, szRecvBuff);
    
    AddText(ghMultipleWnd, IDC\_MULTIPLEFILENAMEREQUEST, szTempChar);
    
    i = send(sckClient, "GETFILENAME", 12, 0);
    
    i = recv(sckClient, szRecvBuff, 512, 0);
    
    
    
    if (!strcmp(szRecvBuff, "\\\\DONE"))
    
        bStop = true;}
    

    }

    and the sender's side (szCompleteFileName is an array of char * pointing to a string that is the path to one of the files the user wants to send. GetFileName is a function that strips the path away from the complete filename

    HANDLE hCheckFile

    char szTempChar[512];

    DWORD dwCurrentFileSize = 0;

    char szFileName[MAX_PATH+1];

    bool bStop = false;

    char szRecvBuff[513];

    int iFileCount = 0;

    DWORD dwCurrentFileSize = 0;

    i = recv(sckClient, szRecvBuff, 12, 0);

    while (iFileCount+1 <= SendMessage(GetDlgItem(ghWnd, IDC_FILES), LB_GETCOUNT, 0, 0))

    {

    if (!strcmp("GETFILENAME", szRecvBuff))
    
    {
    
        strcpy(szRecvBuff, szCompleteFileName\[iFileCount++\]);
    
        GetFileName(szRecvBuff);
    
        send(sckClient, szRecvBuff, strlen(szRecvBuff)+1, 0);
    
        i = recv(sckClient, szRecvBuff, 8, 0);
    
        if (!strcmp("GETSIZE", szRecvBuff))
    
        {
    
            if ((hCheckFile = CreateFile(szCompleteFileName\[iFileCount\], GENERIC\_READ, FILE\_SHARE\_READ, NULL, OPEN\_EXISTING, FILE\_ATTRIBUTE
    
    L V 2 Replies Last reply
    0
    • R Redeemer dk

      I'm programming winsock. In my app i'm building in a feature for sending multiple files over the internet. In the filesend request i set up a loop where i send the filename and -size of the files the user has chosen to send. My problems is this: the second time the sender of the files calls the recv function to receive the "GETSIZE" string, then, instead of receiving "GETSIZE" it receives the "GETSIZE" string but shifted one place to the right, so it's actually "\0GETSIZE" without a terminating null but with a starting null instead. Here are the loops how they look on the sender's and the receiver's side. Receiver's side:

      char szTempChar[512];

      DWORD dwTotalFileSize = 0;

      char szFileName[MAX_PATH+1];

      bool bStop = false;

      char szRecvBuff[513];

      i = send(sckClient, "GETFILENAME", 12, 0);

      i = recv(sckClient, szRecvBuff, 512, 0);

      while (bStop == false)

      {

      strcpy(szFileName, szRecvBuff);
      
      i = send(sckClient, "GETSIZE", 8, 0);
      
      i = recv(sckClient, szRecvBuff, 512, 0);
      
      
      dwTotalFileSize = dwTotalFileSize + atoi(szRecvBuff);
      
      sprintf(szTempChar, "%s, %s bytes\\r\\n", szFileName, szRecvBuff);
      
      AddText(ghMultipleWnd, IDC\_MULTIPLEFILENAMEREQUEST, szTempChar);
      
      i = send(sckClient, "GETFILENAME", 12, 0);
      
      i = recv(sckClient, szRecvBuff, 512, 0);
      
      
      
      if (!strcmp(szRecvBuff, "\\\\DONE"))
      
          bStop = true;}
      

      }

      and the sender's side (szCompleteFileName is an array of char * pointing to a string that is the path to one of the files the user wants to send. GetFileName is a function that strips the path away from the complete filename

      HANDLE hCheckFile

      char szTempChar[512];

      DWORD dwCurrentFileSize = 0;

      char szFileName[MAX_PATH+1];

      bool bStop = false;

      char szRecvBuff[513];

      int iFileCount = 0;

      DWORD dwCurrentFileSize = 0;

      i = recv(sckClient, szRecvBuff, 12, 0);

      while (iFileCount+1 <= SendMessage(GetDlgItem(ghWnd, IDC_FILES), LB_GETCOUNT, 0, 0))

      {

      if (!strcmp("GETFILENAME", szRecvBuff))
      
      {
      
          strcpy(szRecvBuff, szCompleteFileName\[iFileCount++\]);
      
          GetFileName(szRecvBuff);
      
          send(sckClient, szRecvBuff, strlen(szRecvBuff)+1, 0);
      
          i = recv(sckClient, szRecvBuff, 8, 0);
      
          if (!strcmp("GETSIZE", szRecvBuff))
      
          {
      
              if ((hCheckFile = CreateFile(szCompleteFileName\[iFileCount\], GENERIC\_READ, FILE\_SHARE\_READ, NULL, OPEN\_EXISTING, FILE\_ATTRIBUTE
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      send(sckClient, "GETSIZE", 8, 0); There are only 7 chars in this. I do not know what the behaviour will be in this case. you have to send a null character if you want it to go. i would assume send(sckClient, "GETSIZE", 7, 0); would be more appropriate

      1 Reply Last reply
      0
      • R Redeemer dk

        I'm programming winsock. In my app i'm building in a feature for sending multiple files over the internet. In the filesend request i set up a loop where i send the filename and -size of the files the user has chosen to send. My problems is this: the second time the sender of the files calls the recv function to receive the "GETSIZE" string, then, instead of receiving "GETSIZE" it receives the "GETSIZE" string but shifted one place to the right, so it's actually "\0GETSIZE" without a terminating null but with a starting null instead. Here are the loops how they look on the sender's and the receiver's side. Receiver's side:

        char szTempChar[512];

        DWORD dwTotalFileSize = 0;

        char szFileName[MAX_PATH+1];

        bool bStop = false;

        char szRecvBuff[513];

        i = send(sckClient, "GETFILENAME", 12, 0);

        i = recv(sckClient, szRecvBuff, 512, 0);

        while (bStop == false)

        {

        strcpy(szFileName, szRecvBuff);
        
        i = send(sckClient, "GETSIZE", 8, 0);
        
        i = recv(sckClient, szRecvBuff, 512, 0);
        
        
        dwTotalFileSize = dwTotalFileSize + atoi(szRecvBuff);
        
        sprintf(szTempChar, "%s, %s bytes\\r\\n", szFileName, szRecvBuff);
        
        AddText(ghMultipleWnd, IDC\_MULTIPLEFILENAMEREQUEST, szTempChar);
        
        i = send(sckClient, "GETFILENAME", 12, 0);
        
        i = recv(sckClient, szRecvBuff, 512, 0);
        
        
        
        if (!strcmp(szRecvBuff, "\\\\DONE"))
        
            bStop = true;}
        

        }

        and the sender's side (szCompleteFileName is an array of char * pointing to a string that is the path to one of the files the user wants to send. GetFileName is a function that strips the path away from the complete filename

        HANDLE hCheckFile

        char szTempChar[512];

        DWORD dwCurrentFileSize = 0;

        char szFileName[MAX_PATH+1];

        bool bStop = false;

        char szRecvBuff[513];

        int iFileCount = 0;

        DWORD dwCurrentFileSize = 0;

        i = recv(sckClient, szRecvBuff, 12, 0);

        while (iFileCount+1 <= SendMessage(GetDlgItem(ghWnd, IDC_FILES), LB_GETCOUNT, 0, 0))

        {

        if (!strcmp("GETFILENAME", szRecvBuff))
        
        {
        
            strcpy(szRecvBuff, szCompleteFileName\[iFileCount++\]);
        
            GetFileName(szRecvBuff);
        
            send(sckClient, szRecvBuff, strlen(szRecvBuff)+1, 0);
        
            i = recv(sckClient, szRecvBuff, 8, 0);
        
            if (!strcmp("GETSIZE", szRecvBuff))
        
            {
        
                if ((hCheckFile = CreateFile(szCompleteFileName\[iFileCount\], GENERIC\_READ, FILE\_SHARE\_READ, NULL, OPEN\_EXISTING, FILE\_ATTRIBUTE
        
        V Offline
        V Offline
        valikac
        wrote on last edited by
        #3

        I believe the server and client are out sync. Use a diagram to plot your algorithm and make sure the server sends the exact size and the exact data; and the client receives the correct size and read the exact data. Kuphryn

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups