It is intrinsic in the nature of TCP that long packets may be broken up and small packets may be combined. The bytes will eventually arrive in the same order, but you can't count on the grouping. You may send 800 bytes and another 800 bytes and the 1600 bytes may arrive as packets of 100, 900, and 600. A typical transmission unit over Ethernet is 1500 bytes. (You may have some control over this via socket options such as MTU, but any router the packets flow through can change the divisions.)
The recv call returns when any data is available; the LENGTH parameter is a maximum, not a minimum. So, either you have to loop, or you use a method that implicitly loops, like readline, also known as <>. If your data always ends with a CR and there's no CR in the data, you can:
$/ = "\r";
$buf = <$new_sock>;
You don't have to use binmode on sockets. They use bytes by default.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.