in reply to Socket: Server shall send same $line to several clients
Thus you have all clients in @sockclients, and can send data to each one using:my $sockserv = new IO::Socket::INET( LocalAddr => '192.168.1.1', LocalPort => $port, Proto => 'tcp', Listen => 1, Reuse => 1, Timeout => 60); die "Can't create Server ($!)" unless $sockserv; $x = new IO::Select(); $x->add($sockserv); $clients = 0; $sockclient=(); while (1) { my @handles = $x->can_read(); # wait for data foreach $handle (@handles) { if ($handle == $sockserv) { $sockclient = $sockserv->accept() || warn "accept: $!" +; $clients++; if ($clients > 5) { print $sockclient "Sorry, we're full.\n"; $sockclient->close(); } else { $sockclients[$clients] = $sockclient; } $x->add($sockclients[$clients]); } $cl = is_member($handle, @sockclients); if ($cl > -1) { $n_read = sysread($sockclients[$cl], $buf, 1024); return 0 if (!n_read || !length $buf); parse_external_command($buf, $sockclients[$cl]); } } }
If you need forks tho, you'll need to find some other way to get an array of the sockets.foreach my $sock (@sockclients) { print $sock $data; }
C.
Disclaimer: Copied partly from working code, not tested as is!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Socket: Server shall send same $line to several clients
by Anonymous Monk on Feb 23, 2003 at 10:13 UTC | |
|
Re: Re: Socket: Server shall send same $line to several clients
by Anonymous Monk on Feb 24, 2003 at 11:43 UTC |