On One side of the connection i am trying to receive a buffer of size 200 three times, and on the other side i am sending 3 times (a string between 4 and 6 bytes)
but when i run this the receiver gets all 3 calls to send in the big buffer...
Then i did try to run this in debug-mode to comprehend what is happening:
the funny thing is, that now everything is working fine... somehow... i dont get this O_o...
char RecvBuf[200];
int rc;
rc = send(sock,"WHAT?",5,0);
if(rc < 1)
{
closesocket(sock);
sock = INVALID_SOCKET;
return;
}
rc = recv(sock,RecvBuf,200,0);
if(rc < 1)
{
return;
}
RecvBuf[rc] = '\0';[...] <- followed by the two other calls to recv in another ,ethod/function
maybe what you are trying to tell me is the point, that when i call recv(sock,buf,200,0);
that it will stay receiveing untill the 200 bytes are received?...
but why does it 'work' while stepping through this?...
-i normally bind , listen connect etc... just the standard stuff
i think i should loop through the send and receive buffer and clear them.
then i copy the string into it and send the whole 200 bytes to fill 'RecvBuf'
or maybe i could send the data with less bytes and send oob-data to inidicate that the main buffer does not need to be filled any more?...
or doesn´t it work, since the socket is in blocking mode...
You arent properly initing buffer. Clear it before every use or append an null char at the position returned by recv. This also explains the debug mode because your compiler probaby inits the buffer for you.
'\0' would do it you would be working with c string functions. You are not. The recv does not put a '\0' at the end of the buffer. Hope you solved the problem
i tried to fix the Original Problem by sending 200 bytes (since the recv waits for 200 bytes)...
Now - if i dont send the ending '\0' char on my strings i cant figure out the length of the buffer i did send on my receiving method...
But -as above- when i am trying to send 5 bytes (e.g.) on someone who waits for 200 bytes (but does not need them all [a password with variable length, for example]), the receiver still waits for the last 195 bytes to fill until it returns :(...
You can't just send on one side and receive on the other without agreeing how much to send/receive. The number of times you call send doesn't not correlate to how many times you have to call receive.