Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: IO:Socket question... sort of :)

by djbiv (Scribe)
on Aug 25, 2003 at 16:37 UTC ( [id://286397]=note: print w/replies, xml ) Need Help??


in reply to IO:Socket question... sort of :)

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"; } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-16 15:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found