I'm writing a socket server and flash game client. The game requires real-time commands such as movement and turning. It is important for these commands to be sent by the server to the client as soon as possible because the other clients will otherwise desynchronise a lot with the moving/turning client.
This is an example of the problem caused by the Nagle arithmetic:
Note: see the command table below if you wish to understand what these commands mean.
First one is the ship I moved (moved forward + right, forward was received but right not)
The client sending commands:
84796: Sending data: 2#4
84796: Sending data: 2#2
84904: Sending data: 2#3
84904: Sending data: 2#0
86187: Sending data: 2#4
86188: Sending data: 2#2
86374: Sending data: 2#3
86404: Sending data: 2#0
The client receiving commands:
79244: Raw receive: 3#3#4$
79244: New command: 3#3#4
79398: Raw receive: 3#3#2$3#3#3$3#3#0$
79399: New command: 3#3#2
79399: New command: 3#3#3
79399: New command: 3#3#0
80635: Raw receive: 3#3#4$
80635: New command: 3#3#4
80908: Raw receive: 3#3#2$3#3#3$3#3#0$
80908: New command: 3#3#2
80908: New command: 3#3#3
80908: New command: 3#3#0
"moment" is a strange term that doesn't mean what I am trying to say, but here it seems the amount of time in milliseconds after the previous command
move forward send by client A (moment: 0), received by client B (moment: 0)
turn right send by client A (moment: 0), received by client B (moment: 155)
stop moving send by client A (moment: 108), received by client B (moment: 0)
stop turning send by client A (moment: 0), received by client B (moment: 0)
move forward send by client A (moment: 1283), received by client B (moment: 1236)
turn right send by client A (moment: 1), received by client B (moment: 273)
stop movement send by client A (moment: 186), received by client B (moment: 0)
stop turning send by client A (moment: 30), received by client B (moment: 0)
This is the command table corresponding with the commands:
Client-> Server
2# (movement info)
0) now not turning
1) now turning left
2) now turning right
3) now not moving
4) now moving forward
Server-> Client
3# (movement info)
[shipId]#
0) now not turning
1) now turning left
2) now turning right
3) now not moving
4) now moving forward
So, what you can see is that the commands are totally desynched because of "Nagle". This causes the stop movement command to be received by other clients at the same time as the start movement command, causing that player to not move at all.
This is why I need these commands to be send in real-time, as fast as possible by the TCP server. An easy fix would be to simply disable Nagle. However, I have googled (note that his suggestion about tcp message partial is implemented in my system but has nothing to do with timing) a bit and noticed that people absolutely not recommend disabling Nagle.
Is it true that I should not disable the Nagle arithmetic for this cause and should instead look for an other solution? Why (not)?
Thanks in advance. - Tom