Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
How could I go about making this work for multiple connections? If I connect from one client, and try to connect from another, the second client is blocked until the first one quits. Is there a way to have multiple simultaneous connections? Thanks#!/usr/bin/perl -w use File::Copy; use IO::Socket; use Net::hostent; # for OO version of gethostbyaddr #open(CONFIG, "GremlinServerConfig.txt") || die("Can't open GremlinSer +verConfig.txt: $!"); my($resultsDir) = ".\\results"; my(@romFile, @baseState, @appName, @currentSeed, @maxSeed, @seedsPerPa +cket, @switchEvent, @maxEvent, @outputFile,@status); my($currentJob); my($CONNECTION_FAILLURE) = -1; my($SUCCESS) = 0; $PORT = 9000; # pick something not in use $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; print "[Server $0 accepting clients]\n"; while ($client = $server->accept()) { $client->autoflush(1); $hostinfo = gethostbyaddr($client->peeraddr); printf "[Connect from %s]\n", $hostinfo->name || $client->peerhost +; print $client "Command? \n.\n"; while (<$client>) { next unless /\S/; # blank line if (/quit|exit/i) { last; } elsif (/date|time/i) { printf $client "%s\n", scalar localt +ime; } elsif (/request/i ) { # Check if there are any jobs to process if ($#romFile > -1) { $test = $#romFile; print $client "something there...$test\n"; HandleRequest($client); } else { print $client "All jobs finished\n"; } redo; } elsif (/results/i ) { HandleResults($client); } elsif (/add/i) { CreateProject($client); } elsif (/view/i) { PrintAll($client); } else { print $client "Commands: quit date add view\n"; } } continue { print $client "Command?\n.\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: multiple socket connection
by tye (Sage) on Sep 25, 2001 at 22:17 UTC | |
|
Re: multiple socket connection
by perrin (Chancellor) on Sep 25, 2001 at 22:05 UTC |