Question on SDL_net and hostnames

Started by
3 comments, last by clayasaurus 18 years, 6 months ago
disclaimer: network newb Hey, I've got the SDL_net chat example and I got it to work on my linux box connecting to its own host name, using ./chat myhostname, and watch it send text to another chat program that connected the same way, as well as seeing the server accept connections. I'm testing it on windows now. I first tried to connect a windows box to itself and then connect a chat from another computer to the server, but I get the same error messages. hostname pixel (on itself or from another computer, server is on pixel) chat pixel 'couldn't resolve hostname' 'couldn't create UDP endpoint' i've also tried chat 'IPaddress' and then I just get 'connection failed' Both these methods work on my linux box. What name do I use to connect from two different computer's, as 'chat hostname' doesn't work, and 'chat ipaddress' fails. And... what do these errors mean? Thanks. ~ Clay
Advertisement
While I'm not entirely sure which example you're using, I'd guess the TCP single threaded chat example, but you mention not being a UDP endpoint error, which gives me pause. The full out error messages from the example might be helpful (i.e. the "SDLNet_ResolveHost: could'nt resolve hostname"). If you post more details it might make it easier to figure out what's going wrong.

The could not resolve hostname generally means either your DNS isn't working or you've entered in the hostname wrong: it means it can't look up the IP address for the hostname you've given it. Another thing to check is to make sure you're using the internal IP adress of the server if you're on a LAN.

The connection failing I would suspect means either that the server or the client are firewalled, you'll have to allow your server to listen for connections on the port you're using, and allow your client to make connections.
Here's the code I've written (D programming lang, but fairly straight forward)

   int i;   char[] server;   IPaddress serverIP;   // Check command line arguments    if ( args.length == 1 ) {      writefln("Usage: ", args[0], " <server>\n");      return 0;   }      // Allocate a vector of packets for client messages    packets = SDLNet_AllocPacketV(4, CHAT_PACKETSIZE);   if ( packets is null ) {      writefln("Couldn't allocate packets: Out of memory\n");      exit(2);   }   server = std.string.toString(args[1]);   writefln("Connecting to ", server, "...");   SDLNet_ResolveHost(&serverIP, server, CHAT_PORT);   if ( serverIP.host == INADDR_NONE ) {      writefln("Couldn't resolve hostname");      return 0;   } else {      tcpsock = SDLNet_TCP_Open(&serverIP);      if ( tcpsock is null ) {         printf("SDLNet Error (1): %s", SDLNet_GetError());         return 0;       } else {         writefln("Connected");      }   }


When I give it 'chat pixel', I get the "coudln't resolve host name"
When I give it 'chap IPaddr', I get "SDLNet Error (1): Couldn't create socket"

I'm going to try it on different computers that arn't on a LAN and see if there's a difference.

Quote:Original post by clayasaurus
When I give it 'chap IPaddr', I get "SDLNet Error (1): Couldn't create socket"


I doesnt see your CHAT_PORT defined in this piece of source...
Anyway, the "couldn't create socket" seems like the port you try to open is already in use by another program.
You tried already different ports to connect to your server?
Here's my CHAT_PORT "define"

int MAKE_NUM(char A, char B, char C, char D){   return (((A+B)<<8)|(C+D));}/* Defines shared between the server and client */int CHAT_PORT(){   return MAKE_NUM('C', 'H', 'A', 'T'); }


No, I didn't try using different ports, though I guess I should try just by messing around with the CHAT_PORT.

This topic is closed to new replies.

Advertisement