Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to reduce the delay in TCP?  (Read 4131 times)

0 Members and 2 Guests are viewing this topic.

aratnon

  • Newbie
  • *
  • Posts: 24
    • View Profile
How to reduce the delay in TCP?
« on: December 19, 2013, 05:26:36 am »
I'm making a networking game for my network class. I have not done any game with network before.
I use server-client for my game. It works okay with 2 clients, but when 3 player connect the delay occurs like when I move one player I have to wait about 3-5 secs on others screen to see the result.
I show in this video.


I send all x and y to server every frame. Is it too much for sending data?

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: How to reduce the delay in TCP?
« Reply #1 on: December 19, 2013, 09:39:30 am »
I send all x and y to server every frame. Is it too much for sending data?
Yes.

You are instantly filling up the send and receive buffers if you send everything every frame. This is made worse if you don't limit the framerate of your game because it means that your client will just send as fast as it can, and considering all data sent by clients have to be received by a single server over the same kind of "connection" (since you are testing this locally), the server will have to spend longer and longer processing all the queued data, which is what you are seeing when more clients connect.

If you tried to play over the internet with this system, you would notice it will be unplayable because generally the internet only provides you with throughput an order of magnitude smaller than what is available on a local network.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

aratnon

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: How to reduce the delay in TCP?
« Reply #2 on: December 19, 2013, 01:59:24 pm »
Thank you so much. Can you give me an idea of how to limit the frame rate?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: How to reduce the delay in TCP?
« Reply #3 on: December 19, 2013, 02:03:25 pm »
By reading the tutorial. ;)

But once again, don't tie the network updates to your frame rate!
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

aratnon

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: How to reduce the delay in TCP?
« Reply #4 on: December 19, 2013, 02:22:00 pm »
I put everything in the game loop, including function for network. Is that bad?

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: How to reduce the delay in TCP?
« Reply #5 on: December 19, 2013, 02:23:06 pm »
I send all x and y to server every frame. Is it too much for sending data?

It would be better if you only send the keystrokes and let the other clients work with this information and update the position on a regular basis every, i don't know, 1second or send the position with the keystrokes.

There are a lot of useful threads in the network subforum you should have a look on them.


AlexAUT
« Last Edit: December 19, 2013, 02:27:03 pm by AlexAUT »

 

anything