Hi, I've written up a client and a server. They both work fine if I have only one client connected at a time. Here is the begining code of my server:
#!/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"; } }
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

In reply to multiple socket connection by Anonymous Monk

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.