SFML community forums
Help => Network => Topic started by: EiTkoCaT on August 19, 2011, 12:47:26 pm
-
Hey,
My server is using SFML c++ for TCP connections. If a user closes the client program, the server needs to know that he is now disconnected. Whenever I close the program in the client, the server does says that the client disconnected. But if the client lost connection or something, and did disconnected from the server, the server still sees him as connected. Why is that happening? My check is always:
status = (Client.Receive(MessageLivea, sizeof(MessageLivea), Receiveda));
if ( status != sf::Socket::Done)
{
cout << "disonnected" << endl;
} else ....
-
So... Receive returns sf::Socket::Done after the client is disconnected? What are the contents of the received message?
-
OK I found out that it happens when ever I send, not Receive.. That's really weird...
-
OK Here's my full code:
CountinewWithPlayer = 1;
while (CountinewWithPlayer)
{
std::size_t Receiveda = 0;
sf::Socket::Status status;
char MessageLivea[25600];
cout << "2" << endl;
status = (Client.Receive(MessageLivea, sizeof(MessageLivea), Receiveda));
cout << "3" << endl;
if ( status != sf::Socket::Done)
{
cout << "disonnected" << endl;
CountinewWithPlayer = 0;
}
}
If I just close the client program, it's ok, disconnected. If lost connection on client, it prints 1, 2, but not 3, and not disconnecting the player. Why is that happening?
Thanks!
-
OK Here's my full code:
snippet removed
If I just close the client program, it's ok, disconnected. If lost connection on client, it prints 1, 2, but not 3, and not disconnecting the player. Why is that happening?
Thanks!
That's not your full code. We can't even compile it. We need a complete (can be compiled on its own) and minimal (only contains code relevant to the problem, one file, and preferably all in main) code to help effectively.
-
int main() {
sf::SocketTCP Listener;
if (!Listener.Listen(4567))
{
cout << "error listening" << endl;
}
sf::IPAddress ClientAddress;
sf::SocketTCP Client;
if (Listener.Accept(Client, &ClientAddress) != sf::Socket::Done)
{
bool CountinewWithPlayer = 1;
while (CountinewWithPlayer)
{
std::size_t Receiveda = 0;
sf::Socket::Status status;
char MessageLivea[25600];
cout << "2" << endl;
status = (Client.Receive(MessageLivea, sizeof(MessageLivea), Receiveda));
cout << "3" << endl;
if ( status != sf::Socket::Done)
{
cout << "disonnected" << endl;
CountinewWithPlayer = 0;
}
}
}
return 0;
}