SDL_net TCP connection error

Hi

I’m trying to write a realy simple network game but it doesn’t work.
I read the chatd.c and I can’t see why my code doesn’t work…

    IPaddress addr = {INADDR_NONE, GAMPORT};
    if (argc > 1)
    {
            /* client */
            SDLNet_ResolveHost(&addr, argv[1], GAMPORT); // port =

3942
sock = SDLNet_TCP_Open(&addr);
if (!sock)
{
printf("%s\n", SDL_GetError());
cleanup();
return -1;
}
SDLNet_TCP_AddSocket(sset, sock);
if (SDLNet_TCP_Send(sock, &argc, sizeof(int)) !=
sizeof(int))
printf(“Cannot send anything to server\n”);
}
else
{
/* server */
TCPsocket server = NULL;
server = SDLNet_TCP_Open(&addr);
if (!server)
{
fprintf(stderr, “Cannot create server : %s\n”,
SDL_GetError());
cleanup();
return -1;
}
SDLNet_TCP_AddSocket(sset, server);
hop:
if (!SDLNet_CheckSockets(sset, ~0))
printf(“error\n”);
printf(".");
if (!SDLNet_SocketReady(server))
goto hop;
sock = SDLNet_TCP_Accept(server);
if (!sock)
{
printf("%s\n", SDL_GetError());
cleanup();
return -1;
}
SDLNet_TCP_DelSocket(sset, server);
SDLNet_TCP_Close(server);
SDLNet_TCP_AddSocket(sset, sock);
}

there is another thing quite funny : if I make the client loop on the
TCP_Open, it connect to the server after hundreds attempts and the send
doesn’t return a bad value, but the server still doesn’t notice that
there is a client and wait at the CheckSocket…

Does anyone has a hint please?

Thanx, bye!

ChewI

shouldn’t this be htons(GAMPORT)? --^
and why initialize it here since you reinicialize it for the client? why don’t initialize it only at the server block…?
that’s what I found… the rest I can’t check very much 'cose I don’t know about SDL_net… didn’t work with that yet…
Without the htons you’re binding the wrong port at the server, so the client would never reaches it…
—end quoted text—

was it helpful?

[]'sOn Thu, Sep 27, 2001 at 11:18:33AM +0200, Yann LEYDIER - ChewI LEE / BYG wrote:

Hi

I’m trying to write a realy simple network game but it doesn’t work.
I read the chatd.c and I can’t see why my code doesn’t work…

    IPaddress addr = {INADDR_NONE, GAMPORT};


Marcelo R Leitner
ICQ #: 29966851
Kill’em All … And Justice For All.

Hi!

    IPaddress addr = {INADDR_NONE, GAMPORT};
    shouldn't this be htons(GAMPORT)?  --^

I’m not sure but I tried and it changed nothing… Actualy, as the
client and the server are initialized with the same value, even if the
port is not the one I expected, it should work…

and why initialize it here since you reinicialize it for the client? why don’t
initialize it only at the server block…?
I changed it.

was it helpful?
Unfortunatly not!
But thanx for trying to help! :o)
Too bad there is still no doc…

Anyone else has an idea?

Thanx, bye!

ChewI

    IPaddress addr = {INADDR_NONE, GAMPORT};
    shouldn't this be htons(GAMPORT)?  --^

I’m not sure but I tried and it changed nothing… Actualy, as the
client and the server are initialized with the same value, even if the
port is not the one I expected, it should work…
Where GAMPORT is defined and how?
they are not declared with the same value, since on the client you have to resolv the hostname with the portnumber as parameter… so it will automaticaly htons() the port number for you…

Too bad there is still no doc…
Yes… that’s why I didn’t work with it yet…
—end quoted text—On Sat, Sep 29, 2001 at 10:09:57AM +0200, Yann LEYDIER - ChewI LEE / BYG wrote:


Marcelo R Leitner
ICQ #: 29966851
Kill’em All … And Justice For All.