Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: New at socket programming

by jeffenstein (Hermit)
on Apr 19, 2002 at 09:47 UTC ( [id://160474]=note: print w/replies, xml ) Need Help??


in reply to New at socket programming

With the listed code, the program will only read one line from the client when it connects, and then it will disconnect from the client.

You might want to do something like this:

$server = IO::Socket::INET->new ( LocalPort => 1116, Type => SOCK_STREAM, Reuse => 1, Listen => 5 ) or die "Could not open port.\n"; while ($client = $server->accept()) { # # start a new process for each new connection # my $pid = fork; if( $pid < 0){ die "fork error: $!"; }elsif( $pid == 0){ # # child process # do whatever you want with the connection here # while( my $line = <$client>){ print $line; } close($client); } # # parent falls through to listen for new connections # } # should never reach here #close( $server);

This lets you do whatever processing you want with the client, while still accepting new client connections.

Replies are listed 'Best First'.
Re: Re: New at socket programming
by Anonymous Monk on Apr 19, 2002 at 13:50 UTC
    Thanks for the advice. I think your recommendation is the way to go.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-25 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found