winsock tcp lag *UPDATE* Corrupted messages

Started by
18 comments, last by MichaeldeJong 12 years, 3 months ago
Hello,

I'm programming an online RPG using c++ and winsock (TCP-only / client-server based).
I tested it on my LAN network and it worked fine on my own computer. It sends like 1 position update message every 60 ms.
But when I'm testing this on another PC, there is a huge lag. It is only receiving a message every 500 ms or so.
So it's really slow when youre testing on another computer that is not running the server. (it's still LAN)
Is it actually a good idea to send position updates (17 times a second) using TCP?
Thanks a lot.
Advertisement
I'm going to guess these messages are pretty small? TCP will merge messages for a number of reasons, including to ensure that packets are reasonably large, minimizing overhead. Locally, there's no reason for the driver to do this, so you get the updates essentially immediately (1/17th second is ~58 ms) but as soon as you're actually broadcasting over a network, you get delays while the transmission buffer fills up.
[TheUnbeliever]
First - check you haven't got Nagle's enabled.
Secondly.
Is it actually a good idea to send position updates (17 times a second) using TCP?[/quote]
UDP would be MUCH better suited for this.
I turned off nagle's algorithm but still the same problem.works perfectly on local host ( server-side). Only receives a few of those 17 messages per second on another pc on my LAN.

I'm going to guess these messages are pretty small? TCP will merge messages for a number of reasons, including to ensure that packets are reasonably large, minimizing overhead. Locally, there's no reason for the driver to do this, so you get the updates essentially immediately (1/17th second is ~58 ms) but as soon as you're actually broadcasting over a network, you get delays while the transmission buffer fills up.


I think you are right, because it's like receiving 3 messages at once and then having a delay, etc.
So how can I solve this problem?
What's likely going on is that you have confused TCP for a packet-oriented protocol. TCP is a stream protocol. You put stuff in, you take stuff out - there is no guarantee that what you put in will be the same size as what you get out. All TCP guarantees is that (A) everything will arrive and (B) it will arrive in the same order it was sent.

See the Multiplayer and Network Programming forum FAQ for a lot of solutions to this.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]


What's likely going on is that you have confused TCP for a packet-oriented protocol. TCP is a stream protocol. You put stuff in, you take stuff out - there is no guarantee that what you put in will be the same size as what you get out. All TCP guarantees is that (A) everything will arrive and (B) it will arrive in the same order it was sent.

See the Multiplayer and Network Programming forum FAQ for a lot of solutions to this.


Thanks, I think the problem is still TCP_NODELAY. Let's see how I can turn it off the right way.
I'm not sure which socket tho.
I'll go with Neglected and ApochPIQ, have a look at the forum FAQ especially UDP. It's not as hard as it sounds at first and will give you much better results.
Thanks for your help. It's working now. I disabled nagle's.
Sometimes I get these kind of corrupted messages, though:
Howker_corruptedmessage.PNG

This topic is closed to new replies.

Advertisement