Maybe I misunderstood: you are not trying to design or invent a protocol, you are trying to write Perl code that uses a protocol that's already been defined?

Knowing when you have read enough data: you start reading what you have thus far. The length is defined by that, somehow. Is the length given first, followed by the data? Or is there a mark at the end? Or perhaps some of each?

To check the checksum, look up the protocol specification for the definition of that checksum. There are many ways to formulate such a value. You have to know how they are doing it, to match that.

Broken: depends on what you want to do, and perhaps the protocol definition. It might be designed as being intolerant of errors, such as the medical imaging protocols I've worked with. The specification defines what to do in such cases, going into an error state. Or, it might be like recieiving digital TV over the air, where it must be able to resync after an error so you get some static but then continue. The design of the data protocol facilitates this. So, what is the situation, and what are your requirements?


In reply to Re^3: deal data transfer by John M. Dlugosz
in thread deal data transfer by xiaoyafeng

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.