Network SDL

I am working on getting my sdl bomberman network code working. Sam said
I should look at the netlib example in the demos collection, which I did.
Totally against the spirit of a multiplatform library :^). I’d like to see
another init flag like SDL_INIT_NET which would call the windows socket
init stuff (and cleanup later). Then the berkeley sockets stuff would work
as is. That’s what through me, my program was not working (I couldn’t
allocate a socket). Under windows you have to call
WSAStartup(…)
and on exit you need to call
WSACleanup()
Certainly these should be inside SDL, so the code doesn’t have to deal with
including windows.h and all those issues. To me #if defined (WIN32)
code sections are a kludge, they indicate SDL isn’t complete.

Bomberman is working now under win32, but sometimes crashes on exit related
to the WSACleanup or that I’m not doing it correctly.

-Dave

I am working on getting my sdl bomberman network code working. Sam said
I should look at the netlib example in the demos collection, which I did.
Totally against the spirit of a multiplatform library :^). I’d like to see
another init flag like SDL_INIT_NET which would call the windows socket
init stuff (and cleanup later). Then the berkeley sockets stuff would work
as is. That’s what through me, my program was not working (I couldn’t
allocate a socket). Under windows you have to call
WSAStartup(…)
and on exit you need to call
WSACleanup()
Certainly these should be inside SDL, so the code doesn’t have to deal with
including windows.h and all those issues. To me #if defined (WIN32)
code sections are a kludge, they indicate SDL isn’t complete.

Well, actually, I have never intended to put networking into SDL, but there
was a demand for it, so I stuck an example in the demos. :slight_smile:

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

Well, actually, I have never intended to put networking into SDL, but there
was a demand for it, so I stuck an example in the demos. :slight_smile:

The network code works perfectly now, all I would like is the simple
windows startup and shutdown stuff, to avoid the #if defined (WIN32)
stuff. I don’t know why the windows socket stuff needs to be initialized
whereas the unix stuff doesn’t…but it’d be cool if that part were taken
care of by SDL. Just add the SDL_INIT_NET and have sdl do the init under
win32 only.

The bug I refered to in another email was due to doing SDL_Quit before
shutting the sound down. Now bomber is quite stable. Cool playing it on
linux vs running on windows–they work fine together.

Later–
Dave

I don’t want network support in SDL.
I want to use the berkeley socket library. My code already has a nice,
working mechanic using the berkeley socket library. I look at the network
sample code you’ve put in one of the demos, the netlib stuff. It is a probably
convenient library built on top of berkeley sockets library. No one wants
that or needs it built into SDL.

My code, using the berkeley sockets library, compiles and works without
changes, on win32–providing I do that single mysterious
#if defined (WIN32)
WSAStartup(…)
#endif

and on shutdown
#if defined (WIN32)
WSACleanup()
#endif

All I’m saying is move those two single calls into SDL_Init, and add a
new flag to invoke them, SDL_INIT_NET. No compatibility issue as no one
is using that anyway. No bloat because it is just 2 routines which are
OS specific and thus should be abstracted, IE put in the library so the
code base is the same.

The reason I want this is because I don’t want to have to sprinkle lots
of #if/endif things in the code. To me those are very ugly. And the whole
point of using SDL is to avoid stuff like that. The sound, video and
user input stuff works perfectly, without knowing what OS it is running
on (ie no #if/endif’s). I just would like the network stuff to enjoy that
same beauty. And the only thing marring that is 2 simple routine calls
which can be put into the win32 DLL.

Maybe I’m not understanding it all. It seems to me to be a no-brainer–
I can’t see any downside to it.>From my email archive:
To: David Ashley
Cc: sdl at surfnetcity.com.au
Subject: Re: New documentation for SDL
From: slouken@libsdl.org (slouken)
Date: Tue, 23 Jun 1998 18:47:16 -0700
Reply-To: sdl at surfnetcity.com.au
Status: R

What of network support for SDL? I didn’t see anything about that in the
online docs. Online multiplayer games, each player on Win95, linux or BeOs,
all compatible—the idea gives me a woody :^).

Each of those operating systems support the Berkeley sockets interface.
You can write your own network support, and it will be compatible with
each OS. :slight_smile:

Just for grins, the Win95 and UNIX versions of networked Maelstrom
are compatible (though not available for general release.)

See ya!
-Sam Lantinga (slouken at devolution.com)


Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/


I’d have not been able to find out why my working berkeley sockets code
didn’t work under win32 unless I’d dug into the network example you had in
the demos. But the implication of that email is that the code would have
worked without modification. The implication of the library is that one
must learn how to program the library to do what one wants, and thus need
never bother learning the specific OS issues. In this case that isn’t true,
I had to somehow find out that the win32 version required an init library
call to unlock the berkeley sockets stuff. Then the idea of including
windows.h in my code…Ugh. Dirty! That’s not the right path.

Um.I’m rambling.
Later—
Dave
PS I’ll put up the sdlbomber code shortly and give you a link to it. I
need to clean up a few things first.

I don’t want network support in SDL.

Okay, suppose I add SDL_INIT_NET…
What happens when someone on say MacOS uses the flag?
For that matter, what does SDL have to do with Berkeley sockets, anyway?
You’re absolutely right in that the WSASocket() stuff should be hidden away
from the application code, it’s just that I don’t think SDL is a good place
for it, other than it’s a nice platform independent layer.

I’ll add it for kicks and see what happens.

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

I don’t want network support in SDL.

What about this? This is something that definitely shouldn’t go into SDL,
but is absolutely necessary to do cross-platform sockets code:

/* Include system network headers /
#if defined(WIN32) || defined(WIN32)
#define Win32_Winsock
#include <windows.h>
#else /
UNIX /
#include <sys/time.h>
#include <unistd.h>
#ifndef BEOS
#include <arpa/inet.h>
#endif
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#endif /
WIN32 */

/* System-dependent definitions */
#ifndef Win32_Winsock
#define closesocket close
#define SOCKET int
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#endif


Another example is the fact that on Win32 you need to use closesocket()
instead of close() on a socket file handle.

These are things that IMHO shouldn’t be in SDL.

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec