Re: Asynch Sockets over UDP: How do you Know when a socket dissconnects



"DaTurk" <mmagdits@xxxxxxxxxxx> wrote:

Would it make sense then, since there esentially won't be any
disconnect, to just check for a SocketException, and assume that if we
catch one that the socket is unable to send receive, and attempt to
reconnect?

UDP is unreliable and *connectionless*. It makes a best-effort to
deliver, but the packets may simply disappear into the ether. Any errors
you get may disappear with the next packet you send, but on the other
hand, the packets might simply have been dropped somewhere along the
way.

There is no "connection" process, so attempting to "reconnect" doesn't
actually do *anything*. That is, at the low level of the BSD socket API,
calling "connect" on a connectionless (i.e. UDP over IP) socket that you
already called "connect" on, does *absolutely* *nothing*.

The Windows API docs have this to say (connect function, Winsock):

---8<---
For a connectionless socket (for example, type SOCK_DGRAM), the
operation performed by connect is merely to establish a default
destination address that can be used on subsequent send/ WSASend and
recv/ WSARecv calls.
--->8---

There is no connection established when you call connect, and no bytes
leave your machine when you call connect.

If you *need* to know if the other application is listening, it either
has to echo your packets in some way, or send back a heartbeat of some
kind.

-- Barry

--
http://barrkel.blogspot.com/
.



Relevant Pages

  • Overhead, UDP: Many packets on 1 socket vs. one packet and many sockets.
    ... gigabit LAN network using UDP. ... information in the data packets. ... Create a new socket for each of these new pieces of data. ...
    (comp.unix.programmer)
  • Re: Socket connect vs. bind? What is the difference
    ... Actually, if you're doing UDP Multicast, you don't need to connect. ... to call Connect to establish a TCP connection to the remote IPEndPoint. ... is connectionless, so it isn't even necessary to establish a connection to ... It can be set with an overload of the Socket constructor. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Send-Q on UDP socket growing steadily - why?
    ... Send-Q on a moderately active UDP socket keeps growing steadily until it reaches ~128K at which point socket writes start failing. ... The application in question is standard ntpd from Fedora 7, kernel is the latest available for the distro, that is ... "I don't know how to send these packets" mode forever. ...
    (Linux-Kernel)
  • Re: Socket timeout on recv()
    ... > My program just listens on a UDP (connectionless) socket so I haven't ... > tested closing a connected socket. ... timeout if possible), handle errors and reconnect ...
    (microsoft.public.windowsce.embedded)
  • Re: Loosing UDP packets...
    ... The applications I support send lots of UDP via ... Sometimes all the packets hit the wire, ... Perhaps that is only for a non-blocking socket - per my stuff above? ... as I don't send> MTU datagrams. ...
    (comp.os.linux.networking)