Sending data through winsock
-
while( true ) { cout<<"Send: "; cin>>szBuffer; send( client, szBuffer, sizeof(szBuffer), 0 ); if( strcmpi(szBuffer,"exit") == 0 ) break; } if szBuffer is something like "Hello world" then the server recieves the string in two parts the first being "Hello" and the second being "world" so i think you get my point, it seems to be breaking the data by spaces and sending each word it may be appending the space too, (havnt tested) now i want it to send "Hello world" all at once instead of by each word, i thought about replacing the spaces with something else, but i dont really want to do that anyone know what i can to do to solve this?
-
while( true ) { cout<<"Send: "; cin>>szBuffer; send( client, szBuffer, sizeof(szBuffer), 0 ); if( strcmpi(szBuffer,"exit") == 0 ) break; } if szBuffer is something like "Hello world" then the server recieves the string in two parts the first being "Hello" and the second being "world" so i think you get my point, it seems to be breaking the data by spaces and sending each word it may be appending the space too, (havnt tested) now i want it to send "Hello world" all at once instead of by each word, i thought about replacing the spaces with something else, but i dont really want to do that anyone know what i can to do to solve this?
Take a look at the WSARecvEx routine - it will tell you if the received message is a partial message. Steve
-
while( true ) { cout<<"Send: "; cin>>szBuffer; send( client, szBuffer, sizeof(szBuffer), 0 ); if( strcmpi(szBuffer,"exit") == 0 ) break; } if szBuffer is something like "Hello world" then the server recieves the string in two parts the first being "Hello" and the second being "world" so i think you get my point, it seems to be breaking the data by spaces and sending each word it may be appending the space too, (havnt tested) now i want it to send "Hello world" all at once instead of by each word, i thought about replacing the spaces with something else, but i dont really want to do that anyone know what i can to do to solve this?
Look at the line
send( client, szBuffer, sizeof(szBuffer), 0 );
I presume szBuffer is comething like
LPTSTR
,LPSTR
,TCHAR *
orchar *
, in which case, the sizeof operator will return the size of the pointer, not the buffer. You need to pass in the size of the buffer, or use strlen (may be vulnerable to buffer overflows). -- Andrew. -
while( true ) { cout<<"Send: "; cin>>szBuffer; send( client, szBuffer, sizeof(szBuffer), 0 ); if( strcmpi(szBuffer,"exit") == 0 ) break; } if szBuffer is something like "Hello world" then the server recieves the string in two parts the first being "Hello" and the second being "world" so i think you get my point, it seems to be breaking the data by spaces and sending each word it may be appending the space too, (havnt tested) now i want it to send "Hello world" all at once instead of by each word, i thought about replacing the spaces with something else, but i dont really want to do that anyone know what i can to do to solve this?
-
Look at the line
send( client, szBuffer, sizeof(szBuffer), 0 );
I presume szBuffer is comething like
LPTSTR
,LPSTR
,TCHAR *
orchar *
, in which case, the sizeof operator will return the size of the pointer, not the buffer. You need to pass in the size of the buffer, or use strlen (may be vulnerable to buffer overflows). -- Andrew.actually, szBuffer is defined as TCHAR szBuffer[512]; notice its not defined as a pointer, im not stupid, if it were defined as a pointer then sizeof(szBuffer) would return 4 but since its not a pointer it should return 512 how did you get that line to show up with a tan background? i have tried [code]somecode[/code] before it doesnt seem to work
-
actually, szBuffer is defined as TCHAR szBuffer[512]; notice its not defined as a pointer, im not stupid, if it were defined as a pointer then sizeof(szBuffer) would return 4 but since its not a pointer it should return 512 how did you get that line to show up with a tan background? i have tried [code]somecode[/code] before it doesnt seem to work
> im not stupid, Are you sure? TCHAR szBuffer[512] makes szBuffer a pointer, without a subscript it is synonymous to saying &szBuffer[0]... Being rude won't get you any help in these forums. Hope that was useful. -- Andrew.
-
actually, szBuffer is defined as TCHAR szBuffer[512]; notice its not defined as a pointer, im not stupid, if it were defined as a pointer then sizeof(szBuffer) would return 4 but since its not a pointer it should return 512 how did you get that line to show up with a tan background? i have tried [code]somecode[/code] before it doesnt seem to work
»Archer282« wrote: how did you get that line to show up with a tan background? i have tried [code]somecode[/code] before it doesnt seem to work »Archer282« wrote: im not stupid How do you reconcile these two comments ?
Code blocks are easy, if you have the ability to read ( hint: check the formatting links below if you can't work it out for yourself ).
Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder