Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: long text message problem

by Thelonius (Priest)
on Mar 11, 2006 at 03:01 UTC ( [id://535862]=note: print w/replies, xml ) Need Help??


in reply to long text message problem

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.

Replies are listed 'Best First'.
Re^2: long text message problem
by ikegami (Patriarch) on Mar 11, 2006 at 04:23 UTC
    Don't use \r in portable applications, especially in use for communication with other systems. \r is LF (\x0A) on the Mac, and CR (\x0D) on other ASCII platforms. \x0D is always CR.
      \r is LF (\x0A) on the Mac, ...
      Huh? Where does this assertion come from, and how exactly would it apply to macosx? Could it be obsolete residue from the bad old os9/mac-perl days? It doesn't seem to hold true on the macosx(10.4.5) that I'm using at the moment:
      $ perl -e 'print "\r"' | od -t xC -a 0000000 0d + cr
      update: Just to make sure there wasn't some asymmetry:
      $ perl -e 'print "\r"' | perl -e '$_=<>; print "got CR\n" if (/\r/)' | + od -t xC -a 0000000 67 6f 74 20 43 52 0a g o t sp C R nl
      (this is perl 5.8.6, btw; presumably, running the latter script on a windows box would yield 8 bytes of output)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://535862]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-26 05:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found