0

I have made a game and have roughly implemented P2P networking. I am sending packets currently every 20th of a second. At the moment i am sending one packet for each NPC telling the client its current position, so if i have 20 NPCs that is 20 packets being sent every 20th of a second.

My question is should i have one packet sent every 20th of a second containing all of the current NPCS position ? And if so is there a max size this packet should be ? And also any sources on game peer to peer networking are welcomed.

Student123
  • 323
  • 1
  • 5
  • 14
  • Curious, are you even using P2P or is this just a server-client set up? Is each client sending status to all other clients in this time frame? Either way, I don't think you should be operating on the packet layer, let TCP/IP take care of that. It's best to try to package as much as you can together and let the network stack take care of breaking it down into individual pacets if necessary. In general, I'd suggest doing some research on existing software that might help you achieve some of the lower level p2p functions. – Jack Straw Apr 07 '15 at 19:04
  • I have a host which sends information to the client about the NPCS, Collisions and its bullets fired. The client sends information to the host about bullets it fired and its position and velocity. Also it is two player only. – Student123 Apr 07 '15 at 19:23
  • gotcha. that sounds like a server-client architecture as opposed to p2p (peer to peer), which is a different animal all together. you'll want to keep the payloads relatively small, especially if you're firing off several per second, but testing/profiling is the only way to determine the 'proper' packet sizes. best advice i can give you is to keep the data you're sending at every click to a minimum. if NPC locations are more important to relay than some other information (Score updates, etc), then you would want them to happen more frequently. save where you can – Jack Straw Apr 07 '15 at 20:50

1 Answers1

0

That depends on which protocol you're using, UDP or TCP. In gaming, especially FPSs, UDP tends to be the chosen protocol because it's much less "chatty" than TCP. The trade off is that UDP can lose packets because delivery is not guaranteed.

With that in mind you should be sending all position data with each single packet. That way, if you lose a packet here or there, the game can go on and you will mostly be synced.

For the packet size, keep it as small as possible. You definitely want to stay away from needing multiple packets for a single update, especially with UDP. Your data set does not sound like it would be large but I'm just guessing.

Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
  • I am using UDP and for each movement packet i am sending contains 5 floats and an unsigned int. I have been reading articles on P2P and the question i asked wasn't really answered by them. What would you consider a large packet to be ? – Student123 Apr 07 '15 at 19:26
  • 1
    Check out this SO post: http://stackoverflow.com/questions/1098897 It recommends a max UDP payload of 512 bytes and is backed up by a number of members with high SO reputation. (I almost suggested 256 but I realized that was a number from the mind-90s and turned to Google instead :-) – Paul Sasik Apr 07 '15 at 19:35
  • @Student123: Also check out this Wikipedia article which covers MTUs in depth: http://en.wikipedia.org/wiki/Maximum_transmission_unit It's a good backup to the recommendations/answers presented in the SO post I linked with the previous comment. – Paul Sasik Apr 07 '15 at 19:39
  • Thanks a lot this should be perfect for what i need! – Student123 Apr 07 '15 at 19:49