Developing Network Games with SDL Net

Hi All :slight_smile:

Hope you’ve having a nice Christmas (and for those that don’t celebrate it,
hope you’re having a nice break!).

Anyway… I’m playing around with SDL Net and I need some help,

Is it possible to develop a game with SDL Net and have the server and client
running on the same machine? Unless I’m going about it the wrong way I assume
that both the client and server must be able to both send a receive messages.

So the client will be doing,

SDLNet_TCP_Send(server, packet, length) and SDLNet_TCP_Recv(server, &packet,
length)

But the server will also be doing,

SDLNet_TCP_Send(client, packet, length) and SDLNet_TCP_Recv(client, &packet,
length)

Now, I can get this working but it tends to lock up a lot… so… what’s the
secret of developing net games and testing them?

Stevie :slight_smile:

Hi,

Hope you’ve having a nice Christmas (and for those that don’t celebrate
it, hope you’re having a nice break!).

THX, and You too :slight_smile:

Is it possible to develop a game with SDL Net and have the server and
client running on the same machine? Unless I’m going about it the wrong
way I assume that both the client and server must be able to both send a
receive messages.

I didn’t develop anything SDL_net based yet, but i know it is possible
because i had Wesnoth server and Wesnoth game running at the same time
here (on BeOS). I connected fine and could play it (though i didn’t play
it for long, just tested quickly).

So unless that’s something platform-specific, or maybe it’s a "long run"
bug, it works :slight_smile:
Maybe those lockups You had were because socket was not set to
non-blocking mode (it should be, but maybe on Your platform something
doesn’t work right)?

Anyway look into Wesnoth sources, or if it’s too big try SDL_net chat demo

  • IIRC it could also be run on the same machine.

Regards
ahwayakchih

Hi,

Is it possible to develop a game with SDL Net and have the server and
client running on the same machine? Unless I’m going about it the wrong
way I assume that both the client and server must be able to both send a
receive messages.
[…]
Now, I can get this working but it tends to lock up a lot… so…
what’s the secret of developing net games and testing them?

Should be possible without any changes. If it doesn’t work, your code is
not right. However, since you did get it to work, that’s covered.

Maybe those lockups You had were because socket was not set to
non-blocking mode (it should be, but maybe on Your platform something
doesn’t work right)?

The sockets are set to blocking mode for the actual TCP connection, only
the “server socket” ist non-blocking. So you should either use Select
(which will still not completely help you with Send, since it still
potentially blocks, but this should rarely really happen), or do
networking in its own thread(s).

Or you can use the Net2 library from Bob Pendleton:
http://gameprogrammer.com/net2/net2-0.html
It moves networking to the event queue, if I understood it correctly; I
haven’t worked with it yet.

I had a patch floating around for non-blocking TCP in SDL_net, but there
were some API disputes and it was only for Win32 and Unix/POSIX.

Bye,
Benjamin

Ah, it’s cool guys, I’ve got it working now, SDLNet_TCP_Recv() was blocking on
the client (didn’t know it that this). I just changed the timeout :slight_smile:

Ta,

Stevie :)On Tuesday 28 Dec 2004 10:28, Benjamin Deutsch wrote:

Maybe those lockups You had were because socket was not set to
non-blocking mode (it should be, but maybe on Your platform something
doesn’t work right)?

The sockets are set to blocking mode for the actual TCP connection, only
the “server socket” ist non-blocking. So you should either use Select
(which will still not completely help you with Send, since it still
potentially blocks, but this should rarely really happen), or do
networking in its own thread(s).