Click here to Skip to main content
15,915,086 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: hooks Pin
alex.barylski18-Oct-02 8:50
alex.barylski18-Oct-02 8:50 
GeneralRe: hooks Pin
Nick Hodapp18-Oct-02 9:05
sitebuilderNick Hodapp18-Oct-02 9:05 
GeneralDeleting toolbar icon. Pin
WREY18-Oct-02 8:12
WREY18-Oct-02 8:12 
GeneralRe: Deleting toolbar icon. Pin
Shog918-Oct-02 8:15
sitebuilderShog918-Oct-02 8:15 
GeneralRe: Deleting toolbar icon. Pin
WREY18-Oct-02 13:16
WREY18-Oct-02 13:16 
GeneralMS Access Bulk Insert Pin
perlmunger18-Oct-02 8:01
perlmunger18-Oct-02 8:01 
GeneralCan't get tooltips in win32 API to work. Pin
jwarns1318-Oct-02 7:38
jwarns1318-Oct-02 7:38 
GeneralPleas help me correct a strange bug. Pin
Redeemer-dk18-Oct-02 7:12
Redeemer-dk18-Oct-02 7:12 
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:
<font face="Courier New" size=2>
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;}

}
</font>



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


<font face="Courier New" size=2>
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_NORMAL, NULL)) != ERROR_SUCCESS)

                dwCurrentFileSize = GetFileSize(hCheckFile, NULL);

            else    

                dwCurrentFileSize = 0;

            CloseHandle(hCheckFile);

            sprintf(szRecvBuff, "%d", dwCurrentFileSize);

            send(sckClient, szRecvBuff, strlen(szRecvBuff)+1, 0);

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

        }

    }

}
</font>



The strange thing that happens is that the second time the sender's function runs the "i = recv(sckClient, szRecvBuff, 8, 0);" the result in the szRecvBuffer is "\0GETSIZE" without a termunating null. Now everytime the loop has run the string gets shifted one place to the right, so the second time the sender tried to receive "GETSIZE" it received "\0\0GETSIZ" and the same thing happens with the "GETFILENAME" it gets shifted one to the right afer each loop. I've beed fiddling with this for a long time now but can't figure it out, any ideas?

Thankyou

-Rune Svendsen
GeneralRe: Pleas help me correct a strange bug. Pin
User 988518-Oct-02 8:46
User 988518-Oct-02 8:46 
GeneralRe: Pleas help me correct a strange bug. Pin
valikac18-Oct-02 10:16
valikac18-Oct-02 10:16 
GeneralSelect the all lines on a CListCtrl Pin
Walote18-Oct-02 7:11
Walote18-Oct-02 7:11 
GeneralRe: Select the all lines on a CListCtrl Pin
Shog918-Oct-02 8:25
sitebuilderShog918-Oct-02 8:25 
GeneralRe: Select the all lines on a CListCtrl Pin
Walote18-Oct-02 10:25
Walote18-Oct-02 10:25 
GeneralRe: Select the all lines on a CListCtrl Pin
Ravi Bhavnani18-Oct-02 10:48
professionalRavi Bhavnani18-Oct-02 10:48 
GeneralRe: Select the all lines on a CListCtrl Pin
Shog918-Oct-02 11:08
sitebuilderShog918-Oct-02 11:08 
QuestionCan we insert an icon into menu bar? Pin
Nguyen Huynh Hung18-Oct-02 5:57
Nguyen Huynh Hung18-Oct-02 5:57 
AnswerRe: Can we insert an icon into menu bar? Pin
alex.barylski18-Oct-02 8:54
alex.barylski18-Oct-02 8:54 
QuestionHow to change date format? Pin
Nguyen Huynh Hung18-Oct-02 5:44
Nguyen Huynh Hung18-Oct-02 5:44 
AnswerRe: How to change date format? Pin
Daniel Turini18-Oct-02 5:55
Daniel Turini18-Oct-02 5:55 
QuestionIs this standard? Pin
Jawache18-Oct-02 5:39
Jawache18-Oct-02 5:39 
AnswerRe: Is this standard? Pin
dabs18-Oct-02 5:52
dabs18-Oct-02 5:52 
AnswerRe: Is this standard? Pin
Pavel Klocek18-Oct-02 5:54
Pavel Klocek18-Oct-02 5:54 
GeneralRe: Is this standard? Pin
Jawache18-Oct-02 6:01
Jawache18-Oct-02 6:01 
AnswerRe: Is this standard? Pin
Jim A. Johnson18-Oct-02 6:39
Jim A. Johnson18-Oct-02 6:39 
AnswerRe: Is this standard? Pin
Michael Dunn18-Oct-02 13:14
sitebuilderMichael Dunn18-Oct-02 13:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.