On Jul 18, 6:49 pm, [EMAIL PROTECTED] (Monty) wrote: > In studying network programming (and I'm just beginning at it), I see > where listen() is called to set up a socket that waits for incoming > connection requests. The next step appears to be a call to accept() > where the request is granted and the connection made on a new socket, > as in this code snippet: > > listen(SOCK,SOMAXCONN); > > while(1) { > next unless my $remote_addr = accept(SESSION,SOCK); > ...additional code here > > } > > Disregarding any limitations of this code, do I understand that > accept() spawns another socket with the file handle of SESSION?
Yes that is correct. > I presume this allows SOCK to go back to listen()ing, and since > SESSION is already in use, another connection might not be possible > until SESSION is closed...am I getting ahead of mysefl? Right there are two things here. The first is the Unix-like socket library listen(), socket() etc... You seem to have got that bit OK. But now you can forget it - it's useful to know but almost nobody ever uses it directly. The limit of only supporting a single client is a limitation of doing everything in a single process with blocking IO operations. (The fact that SESSION is a global variable doesn't help). If you want multiple concurrent clients you need either to fork() off a child for each client (within "additional code here") or re-write the whole thing with a more complex event loop with select(). There are numerous modules on CPAN (and even in standard Perl) to provide warm fuzzy wrappers around all this low level socket stuff IO::Socket and even to do the event loops for you. Even if you are going to use the low-level functions I'd recommend ditching the Perl4-style global handles. listen( $SOCK,SOMAXCONN); while(1) { next unless my $remote_addr = accept(my $SESSION,SOCK); ...additional code here } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/