Jump to content

  • Log In with Google      Sign In   
  • Create Account


SDLNet - Advice on Sending and Receiving Packets


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Exiled   Members   -  Reputation: 105

Like
0Likes
Like

Posted 05 June 2012 - 04:07 AM

I've been working on a server for a game I'm working on. I'm having some trouble with sending and receiving packets...

Here's my sending code...
SDLNet_TCP_Send(sock, "EX_DC", 6);
/* *** this is placed at the end of int main(), to determine a disconnect.  (EX_DC = Exiled(prefix), Disconnect(action). *** */

...and here's my receiving code.
for(int x = 0; x < connectedPlayers; x++) {
	int ready = SDLNet_CheckSockets(player_sockSet, 0);
	if(ready != -1) {
		result = SDLNet_TCP_Recv(players[x].sock, msg, 256);
		consoleOut("Received data!");
	}
}

//This is placed inside of a for loop that loops through an array of clients.

When I send the data, the server doesn't print anything to the console. What am I doing wrong?

Sponsor:

#2 Xanather   Members   -  Reputation: 703

Like
0Likes
Like

Posted 05 June 2012 - 04:28 AM

Uhh, Ive never used SDL but where is the call to consoleOut? there is no other methods/calls in the sending code you have provided?
SDLNet_TCP_Send(sock, "EX_DC", 6);
/* *** this is placed at the end of int main(), to determine a disconnect. (EX_DC = Exiled(prefix), Disconnect(action). *** */

#3 Tribad   Members   -  Reputation: 795

Like
0Likes
Like

Posted 05 June 2012 - 05:53 AM

I think the receive call waits until 256 bytes are complete.
The ready variable should contain the amount of bytes that are ready for receiving.
If working with streams always be aware that you can receive parts of a message the other ends sends to you.
So you may receive 3 Bytes in the first try another 3 bytes in second.

#4 BeerNutts   Crossbones+   -  Reputation: 2551

Like
0Likes
Like

Posted 05 June 2012 - 08:59 AM

You check if player_socket has data available, but then you try to receive from player[x].sock. I believe you should change the check to player[x].sock
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#5 Exiled   Members   -  Reputation: 105

Like
0Likes
Like

Posted 05 June 2012 - 12:50 PM

You check if player_socket has data available, but then you try to receive from player[x].sock. I believe you should change the check to player[x].sock


I check if player_sockSet has data available. A sock set is exactly what it states: a socket set. I have a socket set of all the player sockets... I check it every loop of the for loop.

#6 Exiled   Members   -  Reputation: 105

Like
0Likes
Like

Posted 05 June 2012 - 12:51 PM

Uhh, Ive never used SDL but where is the call to consoleOut? there is no other methods/calls in the sending code you have provided?
SDLNet_TCP_Send(sock, "EX_DC", 6);
/* *** this is placed at the end of int main(), to determine a disconnect. (EX_DC = Exiled(prefix), Disconnect(action). *** */


consoleOut(); is just a function I made for outputting stuff to a console I made with graphics rather than a console window. I'm actually using Allegro 5 for graphics and SDL_net for networking.

#7 BeerNutts   Crossbones+   -  Reputation: 2551

Like
0Likes
Like

Posted 05 June 2012 - 02:25 PM


You check if player_socket has data available, but then you try to receive from player[x].sock. I believe you should change the check to player[x].sock


I check if player_sockSet has data available. A sock set is exactly what it states: a socket set. I have a socket set of all the player sockets... I check it every loop of the for loop.


My bad, I read it as "player_socket" not "player_sockSet"
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#8 Exiled   Members   -  Reputation: 105

Like
0Likes
Like

Posted 05 June 2012 - 04:01 PM



You check if player_socket has data available, but then you try to receive from player[x].sock. I believe you should change the check to player[x].sock


I check if player_sockSet has data available. A sock set is exactly what it states: a socket set. I have a socket set of all the player sockets... I check it every loop of the for loop.


My bad, I read it as "player_socket" not "player_sockSet"


Ah, it's all good.

#9 Rasterman   Members   -  Reputation: 206

Like
0Likes
Like

Posted 11 June 2012 - 11:26 AM

try sending a lot more data, or using some kind of flush calls, maybe its waiting for a buffer to be filled. use wireshark on the client and server to see if anything is actually being sent or received.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS