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.


In reply to Re: UDP and IO::Socket::INET by ikegami
in thread UDP and IO::Socket::INET by tcf03

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.