tags:

views:

253

answers:

4
+1  A: 

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
Where would i add that never messed with this before new to sockets
H4cKL0rD
right after `recv()` so after `bytes = recv(sClient, cClientMessage, 599, 0)` you could do something like `cClientMessage[bytes] = '\0';`
Patrick Gryciuk
A: 

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().

James Sutherland
Just added a new character before the message"Hello=.2
H4cKL0rD
A: 

Why don't you place first 4 bytes to be the length of the message?

dempl_dempl
How do i do that ???
H4cKL0rD
A: 

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.

tim