recv()
doesn't append a '\0'
to the end of the bytes written. You need to use the return value of recv()
and add the '\0'
yourself.
Patrick Gryciuk
2009-07-05 22:20:23
recv()
doesn't append a '\0'
to the end of the bytes written. You need to use the return value of recv()
and add the '\0'
yourself.
If you don't care about the extra byte of bandwidth, the quickest fix is probably just to send strlen(buffer)+1 bytes insead of strlen(buffer) bytes in your call to send().
Why don't you place first 4 bytes to be the length of the message?
To keep it simple (I don't think performance or style are a concern here), you should probably memset the entire cClientMessage (eg. memset(cClientMessage, 0, 600)) in the function Thread. Then also do the same from the sender with message in main.
You are getting stale characters from the previous message since the \0 is not being transmitted or set by the receiver.