Hi,I have a problem in SDL_net.Server cannot receive packet properly.
Here is my client code:
.....
.......
getin->address.host = serveraddress.host;
getin->address.port = serveraddress.port;
getin->len = 1;
SDLNet_UDP_Send(sd, -1, getin);
while (!quit)
{
printf("Type anything and press enter:\n>");
scanf("%s", (char *)p->data);
p->address.host = serveraddress.host;
p->address.port = serveraddress.port;
p->len = strlen((char *)p->data)+1;
SDLNet_UDP_Send(sd, -1, p);
}
..
...
Here is my server code:
...
.....
while (!quit)
{
if (SDLNet_UDP_Recv(sd, getin)){
printf("An idiot is coming!\n");
}
if (SDLNet_UDP_Recv(sd, p))
{
printf("That idiot has left a message: %s\n", (char *)p->data);
}
}
..
...
Then I open server and client.
After that,I send many thing in client.
Then I get the following output in server:
Quote:That idiot has left a message: <-- strange that I have not receive packet "p"
An idiot is coming! <-- strange that I have not receive packet "getin"
An idiot is coming! <-- strange that I have not receive packet "getin"
That idiot has left a message:aabbccdd <-- Great that server receive a correct packet :)
That idiot has left a message:lol
That idiot has left a message:OOO
An idiot is coming! <-- omg...It seem receive packet randomly... :(
That idiot has left a message:hahahaha
An idiot is coming!
An idiot is coming!
That idiot has left a message:Really strange.
I don't understand why it receive package randomly....
Please help.
Thanks a lot!
-Game Over.
EDIT:I am just modify the code of client.
.....
.......
while (!quit)
{
printf("Type anything and press enter:\n>");
scanf("%s", (char *)p->data);
p->address.host = serveraddress.host;
p->address.port = serveraddress.port;
p->len = strlen((char *)p->data)+1;
SDLNet_UDP_Send(sd, -1, p);
}
...
.....
I get same output in server,it is mean there is no wrong in sending packet but I still don't know what wrong in server. Any idea? Thanks.
[Edited by - game over on February 17, 2010 8:50:48 AM]