Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem when client is diconnecting  (Read 3811 times)

0 Members and 1 Guest are viewing this topic.

EiTkoCaT

  • Newbie
  • *
  • Posts: 47
    • View Profile
Problem when client is diconnecting
« 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 ....

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem when client is diconnecting
« Reply #1 on: August 19, 2011, 02:03:20 pm »
So... Receive returns sf::Socket::Done after the client is disconnected? What are the contents of the received message?
Laurent Gomila - SFML developer

EiTkoCaT

  • Newbie
  • *
  • Posts: 47
    • View Profile
Problem when client is diconnecting
« Reply #2 on: August 20, 2011, 12:57:57 am »
OK I found out that it happens when ever I send, not Receive.. That's really weird...

EiTkoCaT

  • Newbie
  • *
  • Posts: 47
    • View Profile
Problem when client is diconnecting
« Reply #3 on: August 20, 2011, 01:36:21 am »
OK Here's my full code:

Code: [Select]
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!

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Problem when client is diconnecting
« Reply #4 on: August 20, 2011, 02:23:14 am »
Quote from: "EiTkoCaT"
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.
I use the latest build of SFML2

EiTkoCaT

  • Newbie
  • *
  • Posts: 47
    • View Profile
Problem when client is diconnecting
« Reply #5 on: August 20, 2011, 10:52:00 am »
Code: [Select]
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;
}