Results 1 to 17 of 17

Thread: Problem with CL_NetGameClient::disconnect()

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

    Default Problem with CL_NetGameClient::disconnect()

    Ok, so I've simplified my application to check game client and I think the class has a bug. Or I'm not using the class properly.

    To start a server press S, than press C. You can check it starting two applications or just one, it doesn't matter.

    On server side sig_client_disconnected() is emitted only when you close the client window, not on calling client->disconnect().

    Tested it on Ubuntu 10.
    Attached Files Attached Files

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

    Default

    On server side sig_client_disconnected() is emitted only when you close the client window, not on calling client->disconnect().
    I have not tried it, currently I do not have access to a development PC

    As stated on your other post

    I cannot see how the code would work.

    For example:
    1) Key press: Start the Server
    2) [Server polled via CL_KeepAlive::process()]
    3) Key press: Start the Client via "client->connect(address, port);"
    4) Sleep the entire application for 1 second via "CL_System::sleep(1000);"
    5) Disconnect the client via "client->disconnect();"
    6) [Server polled via CL_KeepAlive::process()]

    Between steps 3 and 5, the server is never polled, only at 6.

    A way to test this, it to put "CL_KeepAlive::process()" after the "CL_System::sleep(1000);" before the disconnect

    I do not know clanNetwork internals, so I could be wrong

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

    Default

    It's not a problem with calling CL_KeepAlive:rocess().
    All signals should be emitted even after one second passed.
    And if you start two instances of application, the one with server calls CL_KeepAlive:rocess() about 20 times a second.
    So even if client freezes for one second it's not the problem with CL_KeepAlive:rocess().

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

    Default

    Ah, okay. So adding that CL_KeepAlive after the sleep did not work.

    The reason I suggested it was from a low-level point of view.

    Normally this is what happens
    1) Server socket flagged to accept connections
    2) Client socket connect
    3) Server socket accepts the connection
    4) Client socket disconnects
    5) Server disconnects

    Assuming ClanLib "connect" is non-blocking, and performs a connection in a different thread. (I don't know how clever clanNetwork is)

    ... I thought step 3 was missing, thus the server would never receieve either the connect or disconnect.

    Never mind

    Maybe someone could try the code on a windows machine.

    (I won't have access to a development PC for a while)

  5. #5
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Thank you for minimizing the problem into a small application - it really helps us tracking down bugs or unexpected behaviors.

    You are right your approach does not work and I've also located why. When calling disconnect() on the client manually, the sig_disconnected signal is not currently raised in the code. It is only raised when the disconnection happens from the server side.

    If you want to fix this in your local Clanlib copy, change the disconnect function as follows:

    Code:
    void CL_NetGameClient::disconnect()
    {
    	if(impl->connection != 0)
    		impl->sig_game_disconnected.invoke();
    	
    	impl->connection.reset();
    	impl->events.clear();
    }
    I'm not completely sure this is the correct way to fix the problem officially so I haven't included it in the SVN yet, but for now it should do for you I guess

  6. #6
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Oh, and the question is really why you want this signal to fire? After all, if you are calling disconnect manually, you know you are disconnecting..

    The signal was intended for the situation where something else disconnected you.

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

    Default

    Thanks sphair for help, I almost got what I need.

    I don't need to fire this signal (the one in client) cause as you mentioned if I call the disconnect manually I know the client will disconnect.

    I want the server side on_client_disconnect to be invoked. And now it doesn't happen on calling client's disconnect manually.

  8. #8
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    That seems to be a bug yes. Unfortunately, I have no time to look into this at the moment, so I guess you'll have to do some debugging in CL_NetGameConnection...

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

    Default

    Thanks sphair, I'll wait for 2.2.6 and now I'll try to send an event like 'disconnect' from client before calling client->disconnect manually. Maybe not elegant but I think it will work.

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

    Default

    ClanLib developer philosophy is: “I will only fix/enhance {insert anything here} if I require it and find it interesting”

    So, it is possible ClanLib 2.2.6 will not contain a fix.

    (ClanLib 2.2.6 probably will be released in late January)

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

    Default

    It's difficult for me to dig in the clanlib code. I think fixing bug will take much less time someone familiar with clanlib internals. I think developers make clanlib for free so I do not demand anything. Just in my naive way of seeing the world I think, there's a man with big clanlib commit button. And this man before pushing button looks at all bug reports and decides to fix smth if it's not time expensive or leave it alone if it's difficult, time consuming or smth else. I can't imagine situation where every developer does what he finds interesting and then new clanlib version is released. There must be a plan and someone taking strategic decisions.

  12. #12
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Actually, Rombust is very right. We all do this in our spare time and for fun. So there is no master plan, no bug lists or similar. We just do whatever we feel like at any time, and do releases when we feel like it. Somehow that turns out to work just fine

    It is important to know that our main motivation is not to make a SDK that is going to be used by everyone and save the world, but rather use it in our own projects. Thats how most of us ended up as ClanLib developers - we starting using it, found some bugs and started fixing them.

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

    Default

    But is there any leading developer like the one in rombust signature?
    Bigger project means more problems and every developer has its own philosophy...

  14. #14
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Yes, there is one guy (a really cool and brilliant guy), that is responsible for much of the architecture in ClanLib, and we try to follow his ideas and guidelines to the best of our abilities. Yet, he does not tell anyone what to do, its all voluntarily.

  15. #15
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    You make it sound like there's actually such a thing as a master plan, Sphair - there's not.

    One of the reasons ClanLib does not have a bug tracker is that it implies that anyone actually cares if you enter an entry. The truth about open source development is that almost everyone does it for their own personal reasons.

    It is NOT some big huge altruistic thing where people are doing it for "the cause", which usually implies some unicorntastic marxistic ideas ala the GNU FSF. Reality is closer to how Linus Torvalds described it where he just wanted an open license and GNU GPL seemed like a good solution.

    So why did Linus want an open license? Well, because the truth is that most open source development is done simply because some coders love to code and then find it useful to share their results with the world. It varies from person to person why they want to share it, but in my case it simply seemed like a good way to get some kind of feedback from others and see how far it would take me.

    This doesn't mean you can't come across someone that really do believe in those bigger ideals (I'm not not one of them), but keep in mind that they are rarely the hardcore developers of open source projects. If they were, they would be busy coding and not posting their PR all over the web. There also exist really cool people like Rombust or Sphair that spends a lot of time trying to tie up the lose ends and if you catch him on a good day he just might fix the problem for you. But its your lucky day if he does!

    Yes, it is true that I could probably have debugged and fixed your particular bug in an hour or two. But I'm not going to do that. To fix it, I would have set a break point in the NetGame worker thread on the server to see why on earth it doesn't detect the disconnect properly. With some luck I could probably have fixed the problem in less time than it took me to write this mail.

    So why don't I do it? For the same reason you don't do your neighbors dishes. After all, it would only take you a couple of minutes. Its not too much to ask, is it? Fixing bugs is really boring. Fixing bugs that aren't even triggered in your own projects is even worse.

    What I seek with ClanLib is feedback on the architectural designs and the fun of coding things with other developers. I did not do it to get an unpaid first level supporter job. I can get better jobs than that.

    (sorry if I sound grumpy in this post - its not personal.)

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

    Default

    Thank you Magnus for your post, yeah, you sound grumpy.
    But for me it's better to try to fix your code than write it from scratch.
    I've looked into your (I found your name in headers ) code and after some hours, days, weeks or even longer (I think for you it is a matter of minutes) I've made two changes.

    In Network/Netgame/client.cpp I've added one line (first after brace):
    Code:
    void CL_NetGameClient::disconnect()
    {
    	if (impl->connection != NULL) impl->connection->disconnect();
    	impl->connection.reset();
    	impl->events.clear();
    }
    And in file Network/NetGame/connection_impl.cpp I've commented line 151:
    Code:
    // site->add_network_event(CL_NetGameNetworkEvent(base, CL_NetGameNetworkEvent::client_disconnected));
    i think it was responsible of invoking sig_disconnected on client side but I can be wrong.

    Now my little example works as I expect it to. But I could have broken smth else.
    So please, can you look at these to small changes and tell that it will work with your code?

  17. #17
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    Thanks for your patch. Seeing nothing obvious wrong with it I've applied it.

    Two notes:

    Please send the patch as an unified diff file next time. It makes it much easier to read and apply. You create such patch files by doing subversion checkout of ClanLib. Then you change the source code and use the Create Patch feature in TortoiseSVN (or svn diff under Linux). See the PATCHES file for more details.

    Your bug fixes that the client didn't send a proper disconnect message to the server when logging off and that's good. However, there is still the possibility that the server doesn't react to disconnects caused by other things (such as the client being killed). So the original bug may still be there, although no longer happening in clean disconnect situations. Just so you know.

Similar Threads

  1. Problem with CL_NetGameClient::disconnect()
    By pkowal1982 in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 12-09-2010, 10:40 AM
  2. CL_NetGameConnection disconnect patch
    By genail in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 03-20-2010, 02:16 PM
  3. [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
  •