Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I have written a server application which has select for both incoming new client connection requests and incoming data from client. I am able to process incoming connection requests ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2006
    Location
    Harrisburg, PA, USA
    Posts
    56

    Closing Multiple Client Sockets in Server


    Hi,

    I have written a server application which has select for both incoming new client connection requests and incoming data from client. I am able to process incoming connection requests and client data.

    For example, server has 8 clients connected to it. If client 3 disconnects from server, how will server come to know this client has disconnected and to close its client socket fd gracefully? Does server's select get data on that client socket fd as 'close' data or any error code in recv() function that notifies server to close this client socket fd? Also if client disconnects abruptly without sending close request to server, how should server handle this? Does server get "EPIPE" error?

    Regards,
    Sumit

  2. #2
    Just Joined!
    Join Date
    Nov 2006
    Location
    Harrisburg, PA, USA
    Posts
    56
    I debugged and found out that, when client closes a socket connection with server gracefully, server receives 0 as return value of socket recv() system call on that client socket fd. That is the indication of client closing the socket gracefully. This mechanism is working fine for me.

    I still have to solve one more scenario, what if client connection gets closed abruptly? For example, abrupt network disconnection, lan cable removal, loosing wireless connectivity. In this case, client will not send any data to server and server will not come to know about this abrupt disconnection. I was thinking how to get rid of this problem.

    One way is to define maximum number of connections in server. Whenever maximum number of connections gets fulfilled and new client tries to connect to server, server should send "dummy data of 0 bytes" using socket send() system call. All send() system calls on valid client socket descriptors should return value as greater than 0 indicating that they are alive. The abruptly closed client socket will return 'EPIPE' error indicating it is no more alive/connected. This way we can close that client socket fd and accept connection from new client.

    Will this work all the time? Is there any alternative for this.

    Regards,
    Sumit

Posting Permissions

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