Results 1 to 5 of 5

Thread: Problem with CL_NetGameClient::disconnect()

  1. #1
    Lesser Knight
    Join Date
    Dec 2010
    Posts
    35

    Default Problem with CL_NetGameClient::disconnect()

    Hi

    I've got problem with clean disconnecting my client from server.
    I simplified my code so it looks like this below.
    I start the server:
    Code:
    server = new CL_NetGameServer();
    slotClientConnected = server->sig_client_connected().connect(this, &PuzzleApp::onClientConnected);
    slotClientDisconnected = server->sig_client_disconnected().connect(this, &PuzzleApp::onClientDisconnected);
    slotEventReceived = server->sig_event_received().connect(this, &PuzzleApp::onEventReceived);
    server->start("2222");
    And then connect client and disconnect it:
    Code:
    client = new CL_NetGameClient();
    slotDisconnected = client->sig_disconnected().connect(this, &PuzzleApp::onDisconnected);
    client->connect("127.0.0.1", "2222");
    CL_System::sleep(1000);
    client->disconnect();
    Problem is, the
    Code:
    PuzzleApp::onClientDisconnected
    is not being called.
    And I've discovered that client without
    Code:
    CL_System::sleep(1000)
    just end with seg fault.
    I'm using 2.2.5 on Ubuntu 10. Any ideas what I'm doing wrong?

  2. #2
    Lesser Knight
    Join Date
    Dec 2010
    Posts
    35

    Default

    I've checked that
    Code:
    PuzzleApp::onClientDisconnected
    is called on closing client window.

  3. #3
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    "CL_System::sleep();" is the problem

    It does not call CL_KeepAlive::process(), that clanNetwork requires

    Try the following instead (Not tested):

    Code:
    void process_sleep(int timeout)
    {
    	unsigned int time_start = CL_System::get_time();
    	while(true)
    	{
    		remaining = timeout - (CL_System::get_time() - time_start);
    		if (remaining) break;
    		CL_KeepAlive::process(remaining)
    	} 
    }
    For interest, the signal is called in:
    Code:
    void CL_NetGameClient_Impl::process()
    {
    	...
    		case CL_NetGameNetworkEvent::client_disconnected:
    			sig_game_disconnected.invoke();
    	...
    }

  4. #4
    Lesser Knight
    Join Date
    Dec 2010
    Posts
    35

    Default

    Thanks rombust. It doesn't solve my problem. I've replaced sleep with process but on server side sig_client_disconnected() is not emitted (I call CL_KeepAlive:: process() on server side in main loop).

    Code:
    client = new CL_NetGameClient();
    slotDisconnected = client->sig_disconnected().connect(this, &PuzzleApp::onDisconnected);
    client->connect("127.0.0.1", "2222");
    CL_KeepAlive::process(1000);
    client->disconnect();

  5. #5
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Note, CL_KeepAlive::process(1000) may exit befores 1000ms.

Similar Threads

  1. CL_NetGameConnection disconnect patch
    By genail in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 03-20-2010, 02:16 PM
  2. [HELP] CL_Socket always disconnect
    By Valrandir in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 07-17-2008, 08:59 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •