in reply to UDP and IO::Socket::INET

Two quickies first.

Now on to the meat.

TCP requires that a connection be made before high-level communication can begin. This requires the exchange packets (handshacking), and will fail if the peer is not listening for incoming connections on the specified port.

UDP, on the other hand, is a connection-less protocol. There is no handshacking during socket creation, so it's impossible to know if the other end is listening at that time.

Even sending a datagram to the peer is insufficient to detect if the peer is listening, because UDP is also an unreliable protocol. An unreliable protocol is one that doesn't notify its sender whether the data was sent successfully or not.

To ping a UDP port, it is necessary to send a datagram to the peer which provokes a response from the peer. I don't know of a generic way of doing this for UDP. As far as I know, it requires knowing how to communicate with the application using the UDP port. ( Now I do. See betterworld's reply )

Because UDP is unreliable, you need to try a few times in case the request or the response are lost in transit.

Replies are listed 'Best First'.
Re^2: UDP and IO::Socket::INET
by betterworld (Curate) on Aug 08, 2006 at 19:57 UTC
    To ping a UDP port, it is necessary to send a datagram to the peer which provokes a response from the peer. I don't know of a generic way of doing this for UDP. As far as I know, it requires knowing how to communicate with the application using the UDP port.
    You send an empty datagram to the port. If you get an ICMP port unreachable, the port is closed. If you don't, it's open. (In either case, it might as well have been because of the firewall.) (See man nmap.)
Re^2: UDP and IO::Socket::INET
by tcf03 (Deacon) on Aug 08, 2006 at 19:34 UTC
    I ended up parsing /cat/proc/ip_conntrack - which, isn't perfect - but good enough for what Im doing.

    Thanks

    Ted
    --
    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
      --Ralph Waldo Emerson