Overview
Features
Download
Documentation
Community
Add-Ons & Services

Closing sockets

Please post support and help requests here.

Closing sockets

Postby marlondean » 26 Jul 2012, 13:53

Hi,

I have a small client network app and a small server network app that makes use of POCO. When I close either of these, the OnReadable function in the other one still gets called the entire time. How can I tell the server to stop listening when the client closes and visa versa? Must I create and send a packet of my own, or is there a nice automatic way?

My programs makes use of StreamSockets and ServerSockets.

Regards.
marlondean
 
Posts: 7
Joined: 25 Jul 2012, 12:58

Re: Closing sockets

Postby alex » 26 Jul 2012, 14:32

You mean OnWritable gets called all the time, right?
As to automating the reactor shutdown, google for SO_KEEPALIVE. Depending on the nature of your application, you may have to employ additional application-layer logic to signal client shutdown to the server.
alex
 
Posts: 1117
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Closing sockets

Postby marlondean » 26 Jul 2012, 14:49

Hi Alex,

Thank you for the speedy reply. When I say that OnReadable gets called, I mean that I keep on getting ReadableNotifications. Even after the client/server gets closed the other one keeps on getting ReadableNotifications

Code: Select all
constructor...
{
    m_reactor.addEventHandler(m_socket, NObserver<MyClass, ReadableNotification>(*this, MyClass::OnReadable));
}

   void OnReadable(const AutoPtr<ReadableNotification>& pNf)
   {
      long waitingBytes = m_socket.available();

      if (waitingBytes != 0)
      {
         // do stuff
      }
   }


I will google SO_KEEPALIVE now. Thanks again for you help
marlondean
 
Posts: 7
Joined: 25 Jul 2012, 12:58

Re: Closing sockets

Postby marlondean » 26 Jul 2012, 15:51

So after more investigation I found this quote from here : http://stackoverflow.com/questions/2742708/socket-select-handling-abrupt-disconnections

I don't know anything about Poco, but in general, select() does not report any differentiation between a readable socket and a disconnected socket. It reports a socket is readable when closed/lost/terminated


So if I keep on getting readablenotifications on the client after the server closed, how do I see that the server is actually gone? I can see that m_socket.available(); returns 0, so can I assume that if I get a readablenotifications and m_socket.available(); returns 0 that the server has gone missing (either due to a crash or closing or simply network loss)?
marlondean
 
Posts: 7
Joined: 25 Jul 2012, 12:58

Re: Closing sockets

Postby alex » 26 Jul 2012, 17:33

marlondean wrote:So if I keep on getting readablenotifications on the client after the server closed, how do I see that the server is actually gone? I can see that m_socket.available(); returns 0, so can I assume that if I get a readablenotifications and m_socket.available(); returns 0 that the server has gone missing (either due to a crash or closing or simply network loss)?

You could do that. See Detection of Half-Open (Dropped) Connections for a discussion on this problem. Proposed solutions mostly revolve around various SO_KEEPALIVE related strategies.
alex
 
Posts: 1117
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Closing sockets

Postby marlondean » 27 Jul 2012, 14:16

Thanks alex, I will look into it.
marlondean
 
Posts: 7
Joined: 25 Jul 2012, 12:58


Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron