Jump to content
  • Advertisement
Sign in to follow this  
MichaeldeJong

winsock tcp lag *UPDATE* Corrupted messages

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

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!