Jump to content
  • Advertisement
Sign in to follow this  
rogerdv

designing my protocol, essential information

This topic is 4702 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

Im in the process of creating the protocol for my udp based client-server communication. Im figuring out what info should go in all packets. Right now, I know I have to include a packet counter to ensure correct order of processing. All packets from client side includes a player unique id to speed up player search in server side. What else could be included?

Share this post


Link to post
Share on other sites
Advertisement
The Forum FAQ has some links.

Including a player ID isn't all that useful, because an attacker could put in a fake ID, so you'd have to compare against a known authentication token, or the remote IP address, anyway. Doing a hash-lookup on source IP address+port isn't noticeably slower than a direct array index anyway (two cache misses vs one); I'd just save the network bytes and not send that ID.

Depending on what your protocol needs to do, I'd look at the design of TCP (there are good books on the subject), or the implementation of something like Enet for inspiration.

Share this post


Link to post
Share on other sites
Here's my packet layout; dunno if it's any good, but it works for me...

1 byte packet flags; currently just Encrypted
[per message:
1 byte message flags Reliable|Sequenced|Ordered|LargePayload|Fragmented|System
1 byte sequence channel
2 byte sequence number
1 or 2 byte payload length
[payload]
]

Acks (positive and negative) are sent as a "regular" message.

Share this post


Link to post
Share on other sites
Yes, positive acks are piggybacked on regular sends and negative acks are sent when "holes" in the sequence is detected.

Share this post


Link to post
Share on other sites
You don't need to use a sequence number per message in a packet; you just need a sequence number per packet, because you know what you put into each packet. It's slightly trickier to implement, but it saves on the overhead per message.

Share this post


Link to post
Share on other sites
Aw shucks, that sounds like it might work; back to the drawing board ;-) The only downside I can think of, except extra bookkeeping, is that ordered packets would still need a sequence number per message...

Share this post


Link to post
Share on other sites
I think its sufficient; sequence numbers are wrapped which means you'll only run into problems if a packet is more than 65535 packets late; and that's per channel (255 channels)

Share this post


Link to post
Share on other sites
Is a packet going to be even the least bit relevant if it's 100 packets late? I would think that using a single-byte sequence number would be sufficient for most game protocols. You'd detect that something's amiss long before you wrap around.

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!