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

Author Topic: [SOLVED]tcpsocket selector problem  (Read 1938 times)

0 Members and 1 Guest are viewing this topic.

Soul

  • Newbie
  • *
  • Posts: 44
    • View Profile
[SOLVED]tcpsocket selector problem
« on: March 01, 2013, 03:07:15 pm »
i don't know why but Client can't connect to the server when i use selector...

Server
void Server::Init( int Port )
{
    Listener.listen( Port );
    std::cout << "***************** Game Test Server beta version 0.01 *****************" << std::endl;
}
void Server::Select()
{
    if( Selector.wait() )
    {
        if( Selector.isReady( Listener ) )
        {
            Client *client = new Client;
            if ( Listener.accept( client->Socket ) == sf::Socket::Done )
            {
                clients.push_back( client );
                Selector.add( client->Socket );
                std::cout << "Client connected: " << client->Socket.getRemoteAddress() << std::endl;
            }
        }
    }

}

Client

void Client::Connect( const char *IP, int port )
{
    Server.setBlocking( false );
    if( Server.connect( IP, port) == sf::TcpSocket::Status::Done )
    {
        std::cout << "Connected with server: " << IP << std::endl;
        Connected = true;
    }

    else if( Server.connect( IP, port ) == sf::TcpSocket::Status::Error )
    {
        std::cout << "Can't connect with server: " << IP << std::endl;
        Connected = false;
    }
}
 

when i remove selector client can connect but function shout Cant' connect with...
it's so fuckin strange...
« Last Edit: March 02, 2013, 12:23:10 pm by Soul »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: next problem...
« Reply #1 on: March 01, 2013, 04:56:46 pm »
Don't use non-blocking connect.

And please edit your post to give the thread a more precise title, "next problem..." is totally useless. Everybody has a problem here.
Laurent Gomila - SFML developer

Soul

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: tcpsocket selector problem
« Reply #2 on: March 01, 2013, 05:32:08 pm »
it didn't help, Client says that it is connected, but Server didn't show anything : /

#edit
it's problem with Listener, any ideas?


#edit2

problem solved, I forgot to add the listener to the selector
« Last Edit: March 01, 2013, 11:08:05 pm by Soul »