Jump to content
  • Advertisement
Sign in to follow this  
ViperG

TCP stream breakup/merge

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've going to add networking into my game, but im confused on how to deal with the whole packet thing being split up or merged into multiple/one packet, respectivly. If it's a stream protocal, this means that it can split my data anywhere it wants. So what if I sent a few variables. How would I take the data, in parts, make them into 1 part, then pass them into the variable they belong into. I understand how to read the packets if they are split or merged, but how the hell do I parse it and merge split data, then make a variable= to my merged data...? Not looking for code, just theory/flow chart/step by step.

Share this post


Link to post
Share on other sites
Advertisement
Send: Write your packets to the socket (send(), etc.). TCP will buffer the data.

Receive: read data from the TCP socket (multiple reads are required; data will show up in (different sized) chunks through time). Your packets should contain a header that tells you what kind of packet it is which will tell you its size implicitly, or if the packet length is variable, the length is included in the header.

When you have read enough data from the socket to parse a header, read the header to determine how much more data is required before the packet is complete.

When enough data is available to dispatch the packet, cast the buffer to the appropriate packet type and process (implement inline (process directly from the buffer) or copy packet to another buffer if later processing is required (more expensive, as with a threaded implementation)).

The concept is exactly the same as reading and parsing data from a binary file on disk (serialization, etc.).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!