Now I have another interesting issue, although it makes since I cannot figure where to put a portion of my write code to allow proper functionality.
Now in the above server code each time a new connection comes in it is forked along with current circuit data such as already existing sockets that are both readable and writable. Now every new socket that comes in gets a more and more complete array list of sockets and this list does not match across all connection. For example, I ran this with 4 clients and the first cleint launched can only talk to the server and itself. The second one can talk to the server, first one, and itself. The third one can talk to the server, first, second, and itself. Finally the fourth can talk to the server, first, second, third, and itself.#!/usr/bin/perl -w use strict; use IO::Socket; use IO::Select; $| = 1; # Make program hot! my $sock = IO::Socket::INET->new(Proto => 'tcp', LocalAddr => '192.168.0.100', LocalPort => 7778, Broadcast => 1, Blocking => 0, Reuse => 1, Listen => 1) or die "Can't bind : $@\n"; my $sel = new IO::Select($sock, undef, undef, 0); print "Server now listening for connections!\n" if ($sock); while(my @queues = $sel->can_read()) { my @canWrite = $sel->can_write(); foreach my $obj (@queues) { my $new; if($obj == $sock) { # Create a new socket $new = $sock->accept; $sel->add($new); }else { # Process socket if (my $pid = fork()) { # parent: close the connection so we can # keep listening $sel->remove($obj); $obj->close(); }else { # child: deal with connection while ($obj) { if (defined($obj->recv(my $data, 1024))) { last if (($data =~ /^quit/i) || ($data eq "")); print STDOUT "Input detected is: $data\n"; foreach my $target (@canWrite) { $target->send($data) if ($target);; } }else{ last; } } # finished with the socket $sel->remove($obj); $obj->close; } } } }
I say this makes since because when the first connection comes in the second, third and foruth do not exist yet so the forked process has no way of knowing abou them, Same with the second, third, fourth and so-on.
How can I logically setup this code to keep an updated list of socket conenction on all forked children?
In reply to Re: Two-Part Socket Question.
by Elijah
in thread Two-Part Socket Question.
by Elijah
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |