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

Author Topic: Is disconnected  (Read 3873 times)

0 Members and 1 Guest are viewing this topic.

Ptlomej

  • Newbie
  • *
  • Posts: 48
    • ICQ Messenger - 353167418
    • View Profile
    • Local
Is disconnected
« on: March 20, 2012, 01:43:48 pm »
Where can i handle that the TcpClient is disconnected from the TcpSocket i have a complete Chat but i dont know where i can handle that ? or how ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Is disconnected
« Reply #1 on: March 20, 2012, 01:51:36 pm »
You can be notified of disconnection only after a send or receive operation, by checking the returned status.
Laurent Gomila - SFML developer

Ptlomej

  • Newbie
  • *
  • Posts: 48
    • ICQ Messenger - 353167418
    • View Profile
    • Local
Is disconnected
« Reply #2 on: March 20, 2012, 02:13:34 pm »
I do every time this.
in a Thread

Code: [Select]

for(std::list<sUser*>::iterator it = UserList.begin(); it != UserList.end(); ++it){
if(Selector.isReady(*User.Client)){
sf::Packet Data;
if(User.Client->receive(Data) == sf::Socket::Done){
HandleData(Data,User);
}
}

}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Is disconnected
« Reply #3 on: March 20, 2012, 02:47:34 pm »
Ok, so just check sf::Socket::Disconnected too in return to the receive call.
Laurent Gomila - SFML developer

Ptlomej

  • Newbie
  • *
  • Posts: 48
    • ICQ Messenger - 353167418
    • View Profile
    • Local
Is disconnected
« Reply #4 on: March 20, 2012, 03:03:42 pm »
I done that it work but now i have another problem
if anyone User disconnected the server shuting down but there is nothing like shutdown oô in code


The server Loop
Code: [Select]

void Main::Loop(){
while(Run){
if(Selector.wait()){
if(Selector.isReady(Server)){
sf::TcpSocket* User = new sf::TcpSocket;
if(Server.accept(*User) == sf::Socket::Done){
sUser *theUser = new sUser;

theUser->Client = User;
theUser->State = 0;
theUser->Remove = false;

UserList.push_back(theUser);
Selector.add(*User);
cout << "User connected" << endl;
}
}else{
for(std::list<sUser*>::iterator it = UserList.begin(); it != UserList.end(); ++it){
sUser& User = **it;
if(Selector.isReady(*User.Client)){
sf::Packet Data;
sf::TcpSocket::Status State = User.Client->receive(Data);
if(State == sf::Socket::Done){
HandleData(Data,User);
}else if(State == sf::Socket::Disconnected){
User.Remove = true;
PublicMessage(User.ClientName + " has left the Chat.");
}else if(State == sf::Socket::Error){
cout << "Error" << endl;
}
}
}
UserList.remove_if(CanRemove);
}
}
}
}


OHH ifound it self :)

i have forgett to remove the client from selector
Code: [Select]
Selector.remove(*User.Client);
and add the client RIGHT to the selector
Code: [Select]
Selector.add(*theUser->Client);

 all is okay CLOSED :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Is disconnected
« Reply #5 on: March 20, 2012, 03:09:09 pm »
Quote
if anyone User disconnected the server shuting down but there is nothing like shutdown oô in code

Sorry, but I don't understand what you mean.
Laurent Gomila - SFML developer

Ptlomej

  • Newbie
  • *
  • Posts: 48
    • ICQ Messenger - 353167418
    • View Profile
    • Local
Is disconnected
« Reply #6 on: March 20, 2012, 03:11:28 pm »
all is okay ;) i have found my misstake by myself.
i have post waht was wrong ;)

 

anything