Jump to content
  • Advertisement
Sign in to follow this  
NQ

SDL_net : client doesnt recieve all sends (?) or something

This topic is 3924 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

Hey, I got a problem and I've been trying to figure it out for several days now. I haven't gotten anywhere. Maybe you can help? When I do a SDLNet_TCP_Accept() I've got a working connection to the client at the server side. Naturally I do it like this on the server:
TCPsocket new_tcpsock=SDLNet_TCP_Accept(server_tcpsock);
if(new_tcpsock)
{
	packet = new packettype13(with stuff in it);

	int isend = 13;
	SDLNet_TCP_Send(new_tcpsock,&isend,sizeof(int));
	SDLNet_TCP_Send(new_tcpsock,&packet ,sizeof(packettype13));
}
which sends first an int, and then my packet. And on the client side I've got this:
for (all sockets to all clients)
	if (SDLNet_SocketReady((*ii)))
	{
		SDLNet_TCP_Recv((*ii),&thetype,sizeof(int));
		if (thetype==11)
		{
			packettype11 packet;
			SDLNet_TCP_Recv((*ii),&packet,sizeof(packettype11));
			// printf("hey i got a packet 11 !!!");
			continue;
		}
		if (thetype==13)
		{
			packettype13 packet;
			SDLNet_TCP_Recv((*ii),&packet,sizeof(packettype13));
			// printf("hey i got a packet 13 !!!");
			continue;
		}
	}

And it works!! Yeah. I send a packet 13, and the client first reads the int which says which kind of packet it is. Then it reads the following data as a packet 13. Problem: When I try to send more packets. Somewhy, they dont pop up on the client side. At all. Only the first initial packet gets sent and recieved. The client fails to recieve the one after packettype13 when I change the above server code to this:
TCPsocket new_tcpsock=SDLNet_TCP_Accept(server_tcpsock);
if(new_tcpsock)
{
	packet = new packettype13(with stuff in it);

	int isend = 13;
	SDLNet_TCP_Send(new_tcpsock,&isend,sizeof(int));
	SDLNet_TCP_Send(new_tcpsock,&packet ,sizeof(packettype13));

	packet_2 = new packettype11(with stuff in it);

	int isend_2 = 11;
	SDLNet_TCP_Send(new_tcpsock,&isend_2,sizeof(int));
	SDLNet_TCP_Send(new_tcpsock,&packet_2 ,sizeof(packettype11));
}
The client doesn't even get packets with scrambled data! It gets nothing! Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
You should be checking what SDLNet_TCP_Recv and SDLNet_TCP_Send actually return. They have return values for a reason!

Share this post


Link to post
Share on other sites
Well, alright, but I was kindof expecting them to fail only in very exotic situations, so I hadn't bothered adding that check yet. Still kindof odd that one would work and the next one would not, but I'll try adding that check when I get home today. Thanks for the tip.

Share this post


Link to post
Share on other sites
Nope, not yet, because I'm reasonably certain I'm the one at fault here, not the libs or network hardware.... but if things get fishy I'll do that.

[EDIT: problem solved; SDL_net didn't cause this behaviour. Everything was sent properly, it was just that I accidentally interrupted the process of reading the packets after the first type... in a piece of code which I didn't include above because I thought it was unrelated]

[Edited by - NQ on October 4, 2007 7:43:59 PM]

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!