Hey, when to my server connect first client everything work fine, but then i want connect other clients server stop receiving packets from other clients. I use tcp sockets with blocking mode and timeout use, what's wrong? : /
bool Client::Recv()
{
sf::Socket::Status status = Socket.receive( recv );
if ( status == sf::Socket::Done ) { recv >> family >> action; return true; }
else return false;
}
bool Client::Recv(float t)
{
send.clear();
recv.clear();
sf::SocketSelector selector;
selector.add(Socket);
if( selector.wait(sf::milliseconds(t)))
{
if(Socket.receive(recv)== sf::Socket::Done)
{
recv >> family >> action;
return true;
}
else return false;
}
else return false;
}
void Server::update() /// stupid sending packets...
{
for( std::list<Client*>::iterator it = clients.begin(); it!= clients.end(); ++it )
{
Client &client = **it;
if(Selector.wait(sf::milliseconds(50)))
{
if ( client.Recv(0.3) )
{
/// std::cout<<Packet::GetFamilyName(client.family)<< " "<<Packet::GetActionName(client.action)<<std::endl;
/// std::cout<<client.family<< " "<<client.action<<std::endl;
if( client.family == Packet::PACKET_A_INIT )
{
if( client.action == Packet::PACKET_REQUEST ) /// connection initialize
{
client.InitA();
}
else /// error in init1
{
Selector.remove( client.Socket );
clients.erase(it);
--it;
}
}
else if( client.family == Packet::PACKET_B_INIT )
{
if( client.action == Packet::PACKET_REQUEST )
{
client.InitB();
}
else /// as above but with init2
{
Selector.remove( client.Socket );
clients.erase(it);
--it;
}
}
else if( client.family == Packet::PACKET_ACCOUNT && client.action == Packet::PACKET_REQUEST)
{
if(client.CreateAccount())
{
}
}
else if( client.family == Packet::PACKET_LOGIN && client.action == Packet::PACKET_REQUEST )
{
client.Login();
}
else if( client.family == Packet::PACKET_CHARACTER && client.action == Packet::PACKET_CREATE )
{
client.CreateCharacter();
}
else if( client.family == Packet::PACKET_CHARACTER && client.action == Packet::PACKET_REQUEST )
{
client.LoginChar();
}
else if( client.family==Packet::PACKET_MOVE && client.action==Packet::PACKET_REQUEST )
{
client.RMsg();
client.Move(maps[client.Char.MapID]);
}
else if( client.family == Packet::PACKET_DISCONNECT && client.action==Packet::PACKET_REQUEST ) /// disconnecting xD
{
if( client.Disconnect() )
{
Selector.remove( client.Socket );
clients.erase(it);
--it;
}
}
}
// else if(client.inGame)
// {
//SendMapInfo();
// }
}
}
}
@solved
i change in update selector.wait to selector.isReady and now work with small bugs :v