Thread: Checking for server disconnect

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    51

    Checking for server disconnect

    I understand, using sockets, how I can tell that the server has been disconnected..... is there a way the client can retry connecting for a given time automatically before giving up??

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Martin_T View Post
    I understand, using sockets, how I can tell that the server has been disconnected..... is there a way the client can retry connecting for a given time automatically before giving up??
    If the server disconnects CORRECTLY, then your client will return 0 from the next call to recv() or send(). That's how you know the connection has terminated gracefully. If the server disconnects improperly there is no way to know that anything has happened. You just won't receive packets from the server any more, and any attempt to transmit packets to the server just goes into the void.

    In other words, if a network connection goes down because, say, a rat is chewing on a cable somewhere, you won't get any special message like E_RAT_CHEWING_ON_CABLE.

    TCP is a robust protocol. You should never "give up." The operating system (in particular, the TCP/IP networking stack) will make that decision for you by eventually returning 0 from recv() or send().
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Buidl Library with ./configure script
    By Jardon in forum C Programming
    Replies: 6
    Last Post: 07-24-2009, 09:36 AM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  4. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  5. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM