How to detect the server is disconnected....

This is a discussion on How to detect the server is disconnected.... within the Networking/Device Communication forums, part of the General Programming Boards category; Hey all, I am writing a multithreaded server/client application. One server is handling multiple clients and server is executing separate ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    1

    How to detect the server is disconnected....

    Hey all,
    I am writing a multithreaded server/client application. One server is handling multiple clients and server is executing separate thread for each client. Now my question is that is there any way for the client application to detect that the server has been shut down? i.e during communication (sending and receiving data) if the server application is suddenly shut down/terminated, then how can the client application(s) detect this event and perform action accordingly?

    Any help in this regard will be highly appreciated....

    Regards
    Waqas Arshad

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    At least on linux: you may get a SIGPIPE, SIGHUP, or error on read/write, but the most reliable clue is that read/write returns 0 -- that is, no error, but nothing done.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    If worse comes to worse, you could always create another thread which select()ed on a PF_PACKET socket and then used pthread_cond_broadcast if a FIN/RST was captured.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dfs on a disconnected graph
    By nik in forum C++ Programming
    Replies: 2
    Last Post: 01-01-2011, 01:50 PM
  2. detect UDP server failure
    By trinli in forum Networking/Device Communication
    Replies: 10
    Last Post: 03-17-2009, 10:57 AM
  3. Socket Client Detect Disconnected Equip.
    By sergioms in forum C# Programming
    Replies: 2
    Last Post: 01-25-2009, 06:49 AM
  4. I'm so disconnected from C++ these days.
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 12-11-2008, 06:46 AM
  5. Generate Disconnected Graph in C
    By anirban in forum C Programming
    Replies: 3
    Last Post: 06-08-2008, 10:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21