First off thank you guys. I have gotten soemthing from each of your replys.

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.

#!/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; } } } }
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.

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?


www.perlskripts.com

In reply to Re: Two-Part Socket Question. by Elijah
in thread Two-Part Socket Question. by Elijah

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.