"Ah-ha!", sez I,"This must be where non-blocking IO comes in". I read up on non-blocking IO, and this seems to be totally wrong.
But, while reading about non-blocking IO, I come across the idea of servers forking off processes to handle the details.
I've made a few attempts on this, but I can still maintain only one connection. Could someone elucidate me on this concept?
Below is the script that I'm using as a "base", and as a final note, I'm working on win32 (with fork capabilities, so that's not the issue, mmkay? :) )
#!/usr/bin/perl -w use IO::Socket; use Net::hostent; # for OO version of gethostbyaddr $PORT = 23; # pick something not in use $crlf = "\015\012"; $server = IO::Socket::INET->new(Proto => 'tcp', LocalPort => $PORT, Listen => 10, #SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; print "[Server $0 accepting clients]\n"; while ($client = $server->accept()) { $client->autoflush(1); print $client "Welcome to $0; type help for command list.$crlf"; $hostinfo = gethostbyaddr($client->peeraddr); printf "[Connect from %s]\n", $hostinfo->name || $client->peerhost +; print $client "Command? $crlf"; while ( <$client>) { print "got $_";; next unless /\S/; # blank line if (/quit|exit/i) { last; + } elsif (/date|time/i) { printf $client "%s$crlf", scalar loc +altime; } elsif (/who/i ) { print $client $client->peerhost,$cr +lf; } elsif (/cookie/i ) { print $client "cookie$crlf"; } elsif (/motd/i ) {print "showing motd\n"; print $clien +t "motd$crlf"; } else { print $client "Commands: quit date who cookie motd$crlf"; } } continue { print $client "Command? $crlf"; } close $client; }
In reply to Creating a server that accepts more than one client. by boo_radley
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |