SDL_net latency

Hi, I’mwriting the network part of a multiplayer game, and I’m using
SDL_net for it, but I’m having some problems.

I use TCP as the protocol, and I’m finding it very slow. I can only get
about 5-6 frames per second.But maybe I’m doing something bad.

I show you here a sketch of the protocol I use:

1 - the server sends a message to all the clients requesting for updates
(4 bytes per client)
2 - all the clients send the updated states of their local players to
the server (about 8bytes)
3 - the server sends to all the clients the informtion of the rest of
the clients so that every one is updated (about 12 bytes per client)
4 - Every client executes one cycle of the game, and the protocol moves
back to 1.

In total, with only 2 computers there should be only 32bytes of
information per frame, but I can only achieve 5-6 frames per second!
Is my protocl a very bad one? I’m starting to suspect that SDL_net makes
some kind of internal buffering that delays my mesages. Am I right?

thanks

santi

i won’t wait for net messages when drawing. put the net part in a seperat
thread or use the functions without wating for packets.

i believe you won’t get acceptable fps with your method. (maybe on a 1gb
lan…)> ----- Original Message -----

From: santi.ontanon@terra.es (Santi Ontanon)
To:
Sent: Monday, August 18, 2003 1:55 PM
Subject: [SDL] SDL_net latency

Hi, I’mwriting the network part of a multiplayer game, and I’m using
SDL_net for it, but I’m having some problems.

I use TCP as the protocol, and I’m finding it very slow. I can only get
about 5-6 frames per second.But maybe I’m doing something bad.

I show you here a sketch of the protocol I use:

1 - the server sends a message to all the clients requesting for updates
(4 bytes per client)
2 - all the clients send the updated states of their local players to
the server (about 8bytes)
3 - the server sends to all the clients the informtion of the rest of
the clients so that every one is updated (about 12 bytes per client)
4 - Every client executes one cycle of the game, and the protocol moves
back to 1.

In total, with only 2 computers there should be only 32bytes of
information per frame, but I can only achieve 5-6 frames per second!
Is my protocl a very bad one? I’m starting to suspect that SDL_net makes
some kind of internal buffering that delays my mesages. Am I right?

thanks

santi


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Florian Hufsky wrote:

i won’t wait for net messages when drawing. put the net part in a seperat
thread or use the functions without wating for packets.

Actually, I don’t wait for the net to redraw, but to execute one game
cycle. So it’s better to say that I get “5-6 cycles per second”, and the
game should do 25 cycles per second to run at full speed.
You say to put the network code in a separate thread: but if I need to
execute a game cycle, I cannot do it until I get the information from
the other computers, so even that, I can only execute 5-6 cycles per
second!!

i believe you won’t get acceptable fps with your method. (maybe on a 1gb
lan…)

Is there any standard way or protocol to do synchronize all the
computers in a networked game?

i think it’s almost impossible to synchronise computers in a network with
more than 4-5 game cycles per sec.

you should think about a asynchron client/server way like quake,hallife etc
uses.

how does your protocoll work now? maybe we can find a solution for a faster
one.> ----- Original Message -----

From: santi.ontanon@terra.es (Santi Ontanon)
To:
Sent: Monday, August 18, 2003 3:35 PM
Subject: Re: [SDL] SDL_net latency

Florian Hufsky wrote:

i won’t wait for net messages when drawing. put the net part in a seperat
thread or use the functions without wating for packets.

Actually, I don’t wait for the net to redraw, but to execute one game
cycle. So it’s better to say that I get “5-6 cycles per second”, and the
game should do 25 cycles per second to run at full speed.
You say to put the network code in a separate thread: but if I need to
execute a game cycle, I cannot do it until I get the information from
the other computers, so even that, I can only execute 5-6 cycles per
second!!

i believe you won’t get acceptable fps with your method. (maybe on a 1gb
lan…)

Is there any standard way or protocol to do synchronize all the
computers in a networked game?


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I found that using UDP in combination with TCP works well(sending duplicate
packets using both protocols, and discarding duplicates and bad UDP packets
at the receiving end). It can be a bit complex, and not feasible if you’re
sending large amounts of data(doesn’t sound like you are), and I don’t know
how easy it would be to do that with the SDL_net api.

Why don’t you change your protocol to one in which the clients send their
updates, and then wait for an update from the server. At the server end,
compile any incoming packets, and send them out to the clients. So
essentially the clients would be the only ones waiting for new data. The
server would never block(unless it had major network problems). That’s just
an idea, there are some implementation problems to figure out, but it does
work well for emulators at least.On Monday 18 August 2003 06:55, Santi Onta??n wrote:

Hi, I’mwriting the network part of a multiplayer game, and I’m using
SDL_net for it, but I’m having some problems.

I use TCP as the protocol, and I’m finding it very slow. I can only get
about 5-6 frames per second.But maybe I’m doing something bad.

I show you here a sketch of the protocol I use:

1 - the server sends a message to all the clients requesting for updates
(4 bytes per client)
2 - all the clients send the updated states of their local players to
the server (about 8bytes)
3 - the server sends to all the clients the informtion of the rest of
the clients so that every one is updated (about 12 bytes per client)
4 - Every client executes one cycle of the game, and the protocol moves
back to 1.

In total, with only 2 computers there should be only 32bytes of
information per frame, but I can only achieve 5-6 frames per second!
Is my protocl a very bad one? I’m starting to suspect that SDL_net makes
some kind of internal buffering that delays my mesages. Am I right?

thanks

santi


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

how does your protocoll work now? maybe we can find a solution for a faster
one.

I show you here a sketch of the protocol I use:

1 - the server sends a message to all the clients requesting for updates
(4 bytes per client)
2 - all the clients send the updated states of their local players to
the server (about 4-8 bytes)
3 - the server sends to all the clients the informtion of the rest of
the clients so that every one is updated (about 8-12 bytes per client)
4 - Every client executes one cycle of the game, and the protocol moves
back to 1.

Why don’t you change your protocol to one in which the clients send their
updates, and then wait for an update from the server. At the server end,
compile any incoming packets, and send them out to the clients. So
essentially the clients would be the only ones waiting for new data. The
server would never block(unless it had major network problems). That’s just
an idea, there are some implementation problems to figure out, but it does
work well for emulators at least.

I’ll try to do that. It’s a good idea. However, I’m going to be away
during one week. I’ll tell you more the next week when I’ve time to make
more tests.

[santi == sdl at libsdl.org on Mon, 18 Aug 2003 21:56:35 +0200]

santi> I show you here a sketch of the protocol I use:

Some games may require a completely synchronous game loop like you’ve
described. What’s more commonly done, though is to have each desktop
be fairly autonomous. The implementation has a current state, and
assumes that the world will stay the same unless a network update is
received. So if 10 characters/sprites are heading in 10 different
directions, they will keep going that direction (on that one desktop)
until a network update is received. If it’s been a long time since a
network update was received, the desktop might need to make the
characters “jump” a bit to get things up to speed.

The need for this style of implementation is what someone was hinting
at when they suggested putting the network code in another thread.

With current networking technology, you’ll just not get the framerates
you’re hoping for if you stick with a fully “lock-step, don’t proceed
until next packet is received”. You’ll might be able to do ok over a
LAN (though you’re already seeing performance problems), but with any
open-Internet implementation, you’ll end up freezing the game
frequently. The problem people see with your design is that the whole
game will freeze for every single dekstop if just one computer has a
bit of a lag in sending out one single packet, which most people would
consider unacceptable gameplay.

Also, on a hub-based LAN, you’ll can run into packet collisions, which
will cause a client to pause a random delay before trying again. This
will also freeze the game.

Consider redesigning your game loop around the “everything keeps
moving in the direction it was last moving” style, updating that state
whenever a packet happens to arrive (to a different thread).

None of this has anything to do with SDL, though.

@Jared_Rhine

“We suffer primarily not from our vices or our weaknesses, but from our
illusions. We are haunted, not by reality, but by those images we have put
in place of reality.” - Daniel J. Boorstin

Thanks for all your advises.

Ill try to make it work using all the hints you have given me.

cheers

santi