Leser: 3
4 Einträge, 1 Seite |
FoolAck+2008-08-17 14:39:31--Allerdings kann sich ja immer nur ein Client auf den Server-Socket verbinden.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
use strict; use warnings; use IO::Socket; use IO::Select; my $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => shift || 1234, Listen => 5, Timeout => 3 * 60, Reuse => 1, ); die "server\n$!\n" if not defined $server; my $selector = IO::Select->new($server); my $data; my $curr; while (1) { for my $sock ($selector->can_read()) { if ($sock == $server) { my $client = $server->accept(); $selector->add($client); $data = "New client (ip: ".$client->peerhost().") joined\n"; $curr = 0; } else { $data = <$sock>; $curr = $sock; } for my $sock ($selector->can_write()) { next if (($sock == $server) || ($sock == $curr)); print $sock $data; } } }
4 Einträge, 1 Seite |