Jump to content
  • Advertisement
Sign in to follow this  
game over

SDL_net:Problem in sending and recvice multi packet.

This topic is 3040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!