With UDP what you see is what you get -- you can launch a packet towards its destination, but that's as far as it goes. The network will do its best to deliver, but it offers no guarantee of success, and cannot tell whether it succeeded or not.

If you want to send more than one packet's worth of data, you'll have to wrap each fragment of data in something to tell the other end which part of the data each packet contains -- so the receiver can tell if any fragment goes missing. If you want to know the data has arrived, you'll need to get the receiver to send packet(s) back, telling you how it is for them (consider what happens if those packets do not arrive). From that information, you might be able to deduce that some packets need to be resent. There's a bit of a special case to deal with when you've sent all the data. Alternatively, if you are confident that UDP packets will be delivered, you could get the client to repeat the entire request when it finds a packet has gone astray. (Don't forget to deal with the case of packets being delayed in the network and turning up at the receiver some time later; in particular in the middle of a different request/response cycle.)

Or you could use TCP. The obvious model here is DNS. Most DNS requests are dealt with using UDP. The client gets to repeat the request if it doesn't hear a response in some reasonable time, and there's a mechanism to detect multiple responses rolling up (the server does not attempt to care -- a request arrives, a response is sent, job done). If the response is too big for a single UDP packet (of minimum size), the server says so -- it's up to the client to repeat the request, but using TCP.

I recommend Stevens.


In reply to Re: Sending problem in UDP by gone2015
in thread Sending problem in UDP by deewanagan

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.