Sign in to follow this  
game over

SDL_net:Problem in sending and recvice multi packet.

Recommended Posts

game over    100
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]

Share this post


Link to post
Share on other sites
game over    100
Quote:
Are you checking errors/result codes.

Are you mean error output?
I don't see any error output :(
All the output is on my first post.
If you are not mean error output,please explain what is "errors/result codes".(I am not good at english)

Please make a reply either you thing my code is right or wrong.
Thanks.

Share this post


Link to post
Share on other sites
game over    100
Problem fixed but I have another question:
I changed the code of server:

...
.....
bool connect = false; //New variable
while (!quit)
{
if (!connect && SDLNet_UDP_Recv(sd, getin)){
printf("An idiot is coming!\n");
connect = true;
}
if (connect && SDLNet_UDP_Recv(sd, p))
{
printf("That idiot has left a message: %s\n", (char *)p-&gt;data);
}
}
..
...



It's works!
Thank for replies but I have another question:Is it a noob way(or good way) to solve this problem? If you have a better way to solve it.Please reply if you like.Thanks. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this