Help checking a TCP/IP socket connection

From: Bob (noboby_at_nobody.com)
Date: 06/30/03


Date: Mon, 30 Jun 2003 16:39:01 +0100

Hi,

We have an in-house communication system running on Tru64 unix. It employs
non-blocking TCP/IP sockets for IPC within a single host. We wish to test
the connection between a pair of processes prior to attempting to send a
message - a method called "isConnected()".

Our current implementation of isConnected() follows these steps:

1. Attempt a recv() from the target with the MSG_PEEK flag set.
2. If recv() returns a value >0 we return true.
3. If recv() returns -1 and errno is set to EWOULDBLOCK we return true.
4. Otherwise we return false.

We are frequently finding that both errno and the return value from recv()
are 0. This suggests that the connection to the target has been lost.
However, this would seem to incorrect as subsequent messages are sent
correctly.

Can anyone help understand the behaviour of recv() or suggest a better way
of checking the connection.

Many thanks
Jeff



Relevant Pages

  • Re: RAS connection and Socket status
    ... You don't need a timer to check the current RAS status. ... recv) to ensure that status messages can be processed. ... RasGetConnectStatus to check it during the connection process ...
    (microsoft.public.pocketpc.developer)
  • Re: Socket Server... Why two?
    ... I hope you meant non-blocking way ... The accept just accepts a connection and returns as soon ... It is just an information to the application that now one more socket ... nothing to do without that data, you can do a blocking recv(). ...
    (comp.unix.programmer)
  • Re: how to know if socket is still connected
    ... connection is still ok, if not will reconnect. ... If the server has closed the connection, then a recv() on the ... socket will raise an exception. ...
    (comp.lang.python)
  • Re: Socket Server... Why two?
    ... I hope you meant non-blocking way ... The accept just accepts a connection and returns as soon ... It is just an information to the application that now one more socket ... nothing to do without that data, you can do a blocking recv(). ...
    (comp.unix.programmer)
  • Re: Newbie Sockets Question
    ... listen: errno = 0 ... Got connection from 169.254.154.3 ... try to recv() from new_fd ... ... sockfd is still in listening state. ...
    (comp.unix.programmer)