SDL_net: SDLNet_TCP_Open & windows

what can i say, SDLNet_TCP_Open & windows dont mix.
Windows fails to open a tcp socket.

Is there a fix fir this? or a way around it? anything?-------------------------------
Fabian “SupaGu” Mathews


MSN 8 with e-mail virus protection service: 2 months FREE*
http://join.msn.com/?page=features/virus

I’ve never had a problem myself. Other than that, I’m not too sure what to
tell you - wait, I shall use my psychic powers to debug your malfunctioning
code!

ommmMMmmMMmmmmm…
ommmMMmmMMmmmmm…

…sorry, it’s just not happening today. :wink:

j/k, but I think you get my point - could you please post your source code so
that we can take a look? :slight_smile: If it is a bug in SDL_net we need to know what
conditions it happens in, and if it isn’t an SDL_net bug we might be able to
help you.On Wednesday 18 February 2004 05:00, Fabian Mathews wrote:

what can i say, SDLNet_TCP_Open & windows dont mix.
Windows fails to open a tcp socket.

thats my code below:

bool Server::Create( int port )
{
reliableClientsSet = SDLNet_AllocSocketSet( MAX_CONNECTIONS );
if( !reliableClientsSet )
{
printf(“SDLNet_AllocSocketSet: %s\n”, SDLNet_GetError());
return false;
}

if(SDLNet_ResolveHost( &ip, NULL, port ) == -1 )
{
	printf("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
	return false;
}

return OpenReliable( port );

}

bool Server::OpenReliable( int port )
{
serverReliable = SDLNet_TCP_Open(&ip);
if( !serverReliable ) //crashes here!!!
{
printf(“SDLNet_TCP_Open: %s\n”, SDLNet_GetError());
return false;
}
/*
//add to server socket to set
int noUsed = SDLNet_TCP_AddSocket( reliableClients, serverReliable );
if( noUsed == -1 )
{
printf(“SDLNet_AddSocket: %s\n”, SDLNet_GetError());
return false;
}*/

bServer = true;

return true;

}

is there not init function for sdl_net?-------------------------------
Fabian “SupaGu” Mathews

From: tsm@accesscomm.ca (Tyler Montbriand)
Reply-To: sdl at libsdl.org
To: sdl at libsdl.org
Subject: Re: [SDL] SDL_net: SDLNet_TCP_Open & windows
Date: Wed, 18 Feb 2004 10:38:02 -0600

On Wednesday 18 February 2004 05:00, Fabian Mathews wrote:

what can i say, SDLNet_TCP_Open & windows dont mix.
Windows fails to open a tcp socket.
I’ve never had a problem myself. Other than that, I’m not too sure what to
tell you - wait, I shall use my psychic powers to debug your malfunctioning
code!

ommmMMmmMMmmmmm…
ommmMMmmMMmmmmm…

…sorry, it’s just not happening today. :wink:

j/k, but I think you get my point - could you please post your source code
so
that we can take a look? :slight_smile: If it is a bug in SDL_net we need to know what
conditions it happens in, and if it isn’t an SDL_net bug we might be able to
help you.


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


Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail

I think you just defined your own solution there. :slight_smile:

When your program initializes, it should do this:

 SDL_Init(0); // just 0 if you're only using network
 SDLNet_Init(); //Necessary to use SDL_net!

And on exit, after all sockets are closed etc. it should do this:

 SDLNet_Quit();
 SDL_Quit();

Hope that helps!On Thursday 19 February 2004 01:19, Fabian Mathews wrote:

is there not init function for sdl_net?

Fabian “SupaGu” Mathews

I have the same problem here, it works fine with linux but
never work on linux.
Here is where it fails:

int Taee::startServer() {
cout << “Starting in server mode.” << endl;
cout << “Waiting for a connection on port 1973…”;
if (SDLNet_ResolveHost(&ip, NULL, 1973) == -1) {
cout << “Error!” << endl;
cout << "Couldn’t resolve host: " << SDLNet_GetError() << endl;
return -1;
}
serverSocket = SDLNet_TCP_Open(&ip); // fails here on windows but works
fine on linux
if (serverSocket == NULL) {
cout << “Error!” << endl;
cout << "Couldn’t open a connection: " << SDLNet_GetError() << endl;
return -1;
}
do {
sock = SDLNet_TCP_Accept(serverSocket);
} while (!sock);
cout << “connected!” << endl;
return 0;
}

ThanksOn Wednesday 18 February 2004 05:00, Fabian Mathews wrote:

what can i say, SDLNet_TCP_Open & windows dont mix.
Windows fails to open a tcp socket.


Mohammed Yousif

Mohammed Yousif wrote:

I have the same problem here, it works fine with linux but
never work on linux.

What were you exactly trying to say? :slight_smile:

My guess is that you guys either already have some other app. running at
those ports, or TCP/IP isn’t installed.

Anyway, here’s how I do it in Njam (copy/pasted from njamnet.cpp). It
works on Windows, Linux, MacOSX, BSDs, BeOS, …etc.

I’d be interested to know if you can run Njam on problematic OS. HTH.

-------------------------- server ---------------
IPaddress ip;
if(SDLNet_ResolveHost(&ip,NULL,5547) == -1)
{
printf(“SDLNet_ResolveHost: %s\n”, SDLNet_GetError());
return false;
}

m_ServerSocket = SDLNet_TCP_Open(&ip);
if(!m_ServerSocket)
{
printf(“SDLNet_TCP_Open: %s\n”, SDLNet_GetError());
return false;
}

---------------------------- client --------------

IPaddress ip;
LogFile(“CLIENT: Resolving server name…\n”);
if(SDLNet_ResolveHost(&ip, m_GameOptions.ServerIP, 5547) == -1)
{
printf(“SDLNet_ResolveHost: %s\n”, SDLNet_GetError());
continue;
}

LogFile(“CLIENT: Connecting to server…\n”);
m_PeerSocket = SDLNet_TCP_Open(&ip);
if(!m_PeerSocket)
{
printf(“SDLNet_TCP_Open: %s\n”, SDLNet_GetError());
LogFile(“CLIENT: Failed.\n”);
continue;
}–
Milan Babuskov
http://njam.sourceforge.net

Mohammed Yousif wrote:

I have the same problem here, it works fine with linux but
never work on linux.

What were you exactly trying to say? :slight_smile:

Sorry, replace the first linux with MS Windows :wink:

My guess is that you guys either already have some other app. running at
those ports, or TCP/IP isn’t installed.

I finally figured it out, it was an ‘if statement’ that always works one way
causing SDLNet_Init to never be called!
I’m assuming that the implementation of SDLNet_Init in linux is an almost
empty function and that that of MS Windows isn’t.

Anyway, here’s how I do it in Njam (copy/pasted from njamnet.cpp). It
works on Windows, Linux, MacOSX, BSDs, BeOS, …etc.

I’d be interested to know if you can run Njam on problematic OS. HTH.

Yes, it works just fine on Losedos XP, that is the only problematic OS I
have :stuck_out_tongue:
I also spent some time playing it (nice work really, keep it up).

Thanks all for your help, finally my monopoly-like game is working under
MS Windows.On Tuesday 20 April 2004 18:48, Milan Babuskov wrote:


Mohammed Yousif
Egypt

I have the same problem here, it works fine with linux but
never work on linux.
Here is where it fails:

int Taee::startServer() {
cout << “Starting in server mode.” << endl;
cout << “Waiting for a connection on port 1973…”;
if (SDLNet_ResolveHost(&ip, NULL, 1973) == -1) {
cout << “Error!” << endl;
cout << "Couldn’t resolve host: " << SDLNet_GetError() << endl;
return -1;
}
serverSocket = SDLNet_TCP_Open(&ip); // fails here on windows but works
fine on linux
if (serverSocket == NULL) {
cout << “Error!” << endl;
cout << "Couldn’t open a connection: " << SDLNet_GetError() << endl;
return -1;
}
do {
sock = SDLNet_TCP_Accept(serverSocket);
} while (!sock);
cout << “connected!” << endl;
return 0;
}

ThanksOn Wednesday 18 February 2004 05:00, Fabian Mathews wrote:

what can i say, SDLNet_TCP_Open & windows dont mix.
Windows fails to open a tcp socket.


Mohammed Yousif