my 2 cents... (This is a snippet of code from a Server using IO::Socket, all of the code is not there but this is the main server portion..... take it for what you like...
my ($acceptSock, $pid, $apprCode, $bufHdr, $buf, $length, $hdr, $req); my ($p1, $rsp, $rspMsg, $rspHdr, $msg); while (1) { printf("%sListening on port $args{p}\n", prHdr()); if (!($acceptSock = $listenSock->accept())) { print "bkpt 1: Accept failed: $!\n" if ($debug > 2); next; } # Spawn off a child to handle this connection $pid = fork(); die "Cannot fork: $!" unless defined($pid); # PID is zero when we're the child if($pid) { print "Parent continues\n" if ($debug > 2); next; } printf("%sAccepted connection from: %s\n", prHdr(), $acceptSock->pee +rhost()); srand(time); $apprCode = sprintf("%06d", int(rand 99999)+1); # Wait indefinitely for a message while (1) { print "Error reading 2-byte header: $!\n", last if (sysread($acceptSock, $bufHdr, 2) != 2); printf("%sReceiving request\n", prHdr()); # We got the 2-byte (data length) header $length = unpack("n", $bufHdr); print "$$: Length from request header = $length\n" if($debug > 2); print "Error length ($length) is < e-Header size ($EHDR_SIZE)\n", +last if ($length < $EHDR_SIZE); print "Error reading $length bytes of data: $!\n", last if (sysread($acceptSock, $buf, $length-2) != $length-2); if($debug > 1) { # Got the data, display it &hexDump($bufHdr . $buf); print "\n"; } }

In reply to Re: IO:Socket question... sort of :) by djbiv
in thread IO:Socket question... sort of :) by marcs

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.