Jump to content
  • Advertisement
Sign in to follow this  
Exiled

SDLNet - Advice on Sending and Receiving Packets

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

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?

Share this post


Link to post
Share on other sites
Advertisement
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). *** */

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

[quote name='BeerNutts' timestamp='1338908351' post='4946461']
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.
[/quote]

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

Share this post


Link to post
Share on other sites

[quote name='Exiled' timestamp='1338922235' post='4946545']
[quote name='BeerNutts' timestamp='1338908351' post='4946461']
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.
[/quote]

My bad, I read it as "player_socket" not "player_sockSet"
[/quote]

Ah, it's all good.

Share this post


Link to post
Share on other sites
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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!