(sockets) why does it do this?
-
Hi, i've been trying to learn how to send data to other computers, i've looked at this article: http://www.codeproject.com/internet/Client\_Server.asp i can't understand why it "adds" new text to the old text. example: the server sends a message to a client saying "Testing" then the server sends another message to the client saying "Hi"... and the data recieved will read "Histing". it just replaces the letters... i am probably overlooking something very obvious, but could someone take a look and tell me why it is doing this? thanks in advance
-
Hi, i've been trying to learn how to send data to other computers, i've looked at this article: http://www.codeproject.com/internet/Client\_Server.asp i can't understand why it "adds" new text to the old text. example: the server sends a message to a client saying "Testing" then the server sends another message to the client saying "Hi"... and the data recieved will read "Histing". it just replaces the letters... i am probably overlooking something very obvious, but could someone take a look and tell me why it is doing this? thanks in advance
That's because when you reuse the buffer and receive two bytes in the second message, the bytes are stored at the beginning of the buffer. Pay attention to the number of bytes that the read-socket call returns, don't assume everything is null-terminated.
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
Hi, i've been trying to learn how to send data to other computers, i've looked at this article: http://www.codeproject.com/internet/Client\_Server.asp i can't understand why it "adds" new text to the old text. example: the server sends a message to a client saying "Testing" then the server sends another message to the client saying "Hi"... and the data recieved will read "Histing". it just replaces the letters... i am probably overlooking something very obvious, but could someone take a look and tell me why it is doing this? thanks in advance