The client can do several actions per frame, for instance, requesting a movement, shooting etc. Should i send a packet to the server for each action the client performed during the frame, or should i stack them in an unique packet and send it at the end of the frame?

EDIT: i'm using Jmonkeyengine and the provided network API SpiderMonkey.

  • \$\begingroup\$ What technology do you use? \$\endgroup\$ – Markus von Broady Sep 28 '12 at 12:37
  • \$\begingroup\$ @MarkusvonBroady edited the question. I though it was not technology related and wanted to know how frequently the client state change have to be sent to the server. \$\endgroup\$ – nathan Sep 28 '12 at 12:40
  • \$\begingroup\$ I just wanted to make sure we're not talking about http requests. \$\endgroup\$ – Markus von Broady Sep 28 '12 at 13:00

It shouldn't be a problem to send many packets in one frame. Every packet has some overhead, but you won't feel the difference.

However, if you decide to send a packet every frame, even if there was no user action (or the action is holding a key), while your client will work just fine, and your local testing server will do the job as well, real server will be easily flooded if multiply clients send multiply packets, multiply times (30, 60 or even more) a second. This is same if you want to update mouse cursor position on server every time a user moves the mouse.

| improve this answer | |
  • \$\begingroup\$ So in conclusion, it does not matter? \$\endgroup\$ – nathan Sep 28 '12 at 13:26
  • \$\begingroup\$ In conclusion, it probably could matter in some extreme situations, but they don't fit your description. \$\endgroup\$ – Markus von Broady Sep 28 '12 at 13:45
  • \$\begingroup\$ I actually don't care of extreme situations at the moment :-) and my client/server architecture will never have to support crazy amount of connections so i ll consider you answered my question. \$\endgroup\$ – nathan Sep 28 '12 at 13:47


(if I refer to data as ,,packet", I mean a group of data you want to send. Not a packet in ISO OSI)

let's consider players, bullets and zombies. Sending one big data packet is possible, but not good, because as game gets bigger, you will send more and more data. You will also discover that sometimes, you send position data but not weapon data (because weapon did not change, so why...) and etc. Therefore that will result in checking: Is the data packet containing this? and this?

That is feasible for small projects, but not for a perspective game. Considering that you send one big data packet, sockets divide it anyway to small frames / iso osi packets (depends on iso osi layer you consider).

Sending small chunks

Lets say, that you send one small chunk C1. But it is too small, that socket will not send it. Instead, it waits for more data. That is possible, but depends on technology you use, and how the networking is implemented there. Definitelly I can imagine, that the system might wait a bit to see if more chuks are about to be send, that then sends it all together.

So when you send one big data chunk

  1. You will in fact be sending small chunks over network anyway
  2. Code will be big and difficult to read, having huge packet class
  3. You will have to check on client side: Is there weapon data? If so, call this function to draw that...is there zombie animation state...? etc.

Therefore, I vote for individual packets, consider zombie game as example

  • send packet for weapon - sent to individual players
  • packet containing user, zombie, bullet positions - sent to all players
  • packet containing user information - health

Lastly, I will add here something I have learned...

Never care about performance in first place

Now alot of people will say: well that is bad attitude. But, if you write a game, which is very difficult task, and it will ALWAYS be complex, get the code done. No matter how memory or gpu is wasted. You can optimize when the code is done. (I am talking about code chunks, developing iterations, like every week try to optimize something....not all at the very end)

Why? It happened to me many times. I overthink: Well, how this can be efficient? Do this and this, and it results in such a complex task that you will not make it work.

Therefore: write simple code towards functionality, but keep some space for futurer optimalizations

example: Develop a game, where you send position every frame to all. Then, modify it to send position to all only when it changes. Then, modify it to send position to selective players, if needed. Then, you can compress the sent data...etc.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.