Skip to main content
gamedev.net
🔒 Locked

Message Truncation

Started by nprz Apr 11, 2005 at 1:28 PM 2 replies 450+ views
Original Post
nprz
nprz
I am trying to program a server/client, and when someone logs in the server sends everyone a text message welcoming the new user. The server then sends a message to everyone telling them that a there is a new user. The problem is that part of the second message overwrites the first message. I have a few bytes for the code and length of the message, then it reads the message. Part of that message ended up being the code and length for the next message. Then when it reads the next piece of data the code and length are completely messed up. Is there any settings I need to do so that two sends don't overwrite each other?
Anon Mike
Anon Mike
It's sounds like (1) you're using TCP and (2) you are reading a fixed amount of bytes every read. If both those are true then what you're seeing is completely normal and expected. There is no magic setting.

TCP has no concept of messages. You just have a bunch of bytes and you need to chop them into messages yourself. You need to read your header (code and length) and then read again and ask for 'length' bytes.

If that doesn't sound like the problem then you need to post some code.
-Mike
nprz
nprz
I am not reading a fixed amount of bytes each time. Only the first read is fixed. It reads 3 bytes, 1 for the code of the message, and 2 for the length of the message. Then it reads depending on what the second 2 bytes were for the message.
What is happening is the 2nd message's code and length seems to have overwritten part of the first message.

I will post some code after I return from the bank.

-edit- I am going to look over my code a bit more and see if I can find the problem.

[Edited by - nprz on April 11, 2005 6:43:10 PM]
nprz
nprz
I found my error. I fixed it on the client side's function, but forgot to fix it for the server. I guess this means I should put these functions in the same header space so that this type of thing doesn't happen again :)

When I put in the length of the message, I forgot to add 3 for the code and length of the message, so it was chopping off 3 bytes from the end (I'm an idiot)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.