My code is below.
//Receiving Code
result = SDLNet_CheckSockets(player_sockSet, 0);
//loop through each client
for(int client = 0; client < maxPlayers; client++) {
//check the socket for activity
int clientSocketActivity = SDLNet_SocketReady(players[client].sock);
if(players[client].connected == true && clientSocketActivity > 0) {
//attempt to read from the socket.
//non-positive return values indicate error
int bytesRecv = SDLNet_TCP_Recv(players[client].sock, msg, 256);
if(bytesRecv > 0) {
//display the result
stringstream ss;
ss << "Received " << bytesRecv << " bytes from client " << client << "!";
consoleOut(ss.str());
}
else {
//there was an error
stringstream ss;
ss << "Player " << client << " has disconnected.";
consoleOut(ss.str());
players[client].connected = false;
connectedPlayers--;
//disconnect the socket
}
}
}
Please excuse the bad indenting, it's because of copy + paste.
Thanks in advance!
-Ex






