Server Closing Port

I have currently written a client application that uses TCP/IP sockets
that connects to a server. I am trying to detect when the server closes
its port. Currently, I am using the select function to check the socket
descriptor for data. If the server closes the port, the select function
when called returns that the descriptor is ready (it has data pending).
When I call the receive function to get the data, it shows that the size
of the message is zero. My question is that is there a distict message
that can be received if the server closes the socket. It appears not.
Am I going about this wrong (is there a better way to detect a socket
port closing)?

Thank you.

Dan Szymanski

“Daniel A. Szymanski” <szymanski@sanyo-machine.com> wrote in message
news:3BF0812A.6982BA3@sanyo-machine.com

I have currently written a client application that uses TCP/IP sockets
that connects to a server. I am trying to detect when the server closes
its port. Currently, I am using the select function to check the socket
descriptor for data. If the server closes the port, the select function
when called returns that the descriptor is ready (it has data pending).
When I call the receive function to get the data, it shows that the size
of the message is zero. My question is that is there a distict message
that can be received if the server closes the socket. It appears not.
Am I going about this wrong (is there a better way to detect a socket
port closing)?

Thank you.

actually monitoring socket state is not so obvious task as it may seems to
you at both client or server sides. after a set of experiments i found that
it’s possibly to catch a socket disconnection only pinging it with OOB
(out-of-band) data with some reasonable period. it’s not too good or elegant
but it works some way. at least with TCP sockets. assumed, that your
protocol dosn’t care itself about OOB data. also mixing socket and SRR
(Send/Receive/Reply) IPC mechanisms together isn’t so easy also and afaik
undocumented.

Dan Szymanski

// wbr

When the server closes the port select will return readable on that fd. When
you in turn do a read read will return 0 and errno will be set to the
appropriate reason defined in errno.h so just check your return value from
read and then log based on errno if 0.

“Daniel A. Szymanski” wrote:

I have currently written a client application that uses TCP/IP sockets
that connects to a server. I am trying to detect when the server closes
its port. Currently, I am using the select function to check the socket
descriptor for data. If the server closes the port, the select function
when called returns that the descriptor is ready (it has data pending).
When I call the receive function to get the data, it shows that the size
of the message is zero. My question is that is there a distict message
that can be received if the server closes the socket. It appears not.
Am I going about this wrong (is there a better way to detect a socket
port closing)?

Thank you.

Dan Szymanski

Thank you Fred. I will give that a try.

Dan Szymanski


Fred Allen wrote:

When the server closes the port select will return readable on that fd. When
you in turn do a read read will return 0 and errno will be set to the
appropriate reason defined in errno.h so just check your return value from
read and then log based on errno if 0.

“Daniel A. Szymanski” wrote:

I have currently written a client application that uses TCP/IP sockets
that connects to a server. I am trying to detect when the server closes
its port. Currently, I am using the select function to check the socket
descriptor for data. If the server closes the port, the select function
when called returns that the descriptor is ready (it has data pending).
When I call the receive function to get the data, it shows that the size
of the message is zero. My question is that is there a distict message
that can be received if the server closes the socket. It appears not.
Am I going about this wrong (is there a better way to detect a socket
port closing)?

Thank you.

Dan Szymanski