Sign in to follow this  
Exiled

SDLNet - Advice on Sending and Receiving Packets

Recommended Posts

Exiled    105
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...
[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). *** */
[/CODE]

...and here's my receiving code.
[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.
[/CODE]

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
Xanather    782
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
Tribad    981
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
Exiled    105
[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
[/quote]

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
Exiled    105
[quote name='Xanather' timestamp='1338892085' post='4946374']
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). *** */
[/quote]

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
BeerNutts    4400
[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
[/quote]

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_[b]socket[/b]" not "player_[b]sockSet[/b]"

Share this post


Link to post
Share on other sites
Exiled    105
[quote name='BeerNutts' timestamp='1338927940' post='4946571']
[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
[/quote]

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_[b]socket[/b]" not "player_[b]sockSet[/b]"
[/quote]

Ah, it's all good.

Share this post


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

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