[SDL] portable network
David Olofson
david at olofson.net
Wed Jan 3 09:20:50 PST 2007
On Wednesday 03 January 2007 17:52, Viktor Dick wrote:
> This is not really a question concerning SDL, but I think many SDL
> developers have experience in this because SDL is concerned to be
> portable and many games are designed to be played over network.
> Does anyone know some portable (especially running on Windows and
> Linux) libraries that offer an interface to deal a network?
> Something that would run under Mingw-make and under Gnu/Make(Linux)
> without rewriting the whole code? Does anyone have a link to a
> turorial or at least a reference?
Well, there is SDL_net, for the basic TCP and UDP stuff.
http://www.libsdl.org/projects/SDL_net/
For a nice and clean event driven layer over SDL_net, try NET2:
http://gameprogrammer.com/net2/net2-0.html
Of course, you still need to implement your protocol, as both of the
above deal with "raw" TCP and UDP. Most importantly (for
portability), if you want to communicate anything other than strings
of 8 bit characters, you'll need to make sure the protocol
implementation deals with endianness. (Or PPC Macs won't be able to
talk to Intel Macs or other x86 machines, for example.)
There are various higher level, more domain specific solutions as
well, but I haven't used any of them. If all you need is non real
time TCP, it's pretty trivial to roll your own, but making proper use
of UDP can be a bit trickier. You'll need to deal with packets
arriving out of order och being dropped, and for a real time game,
you'll probably need to implement interpolation and prediction to
deal with "high ping" and dodgy connections.
//David Olofson - Programmer, Composer, Open Source Advocate
.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
'-- http://www.reologica.se - Rheology instrumentation --'
More information about the SDL
mailing list