Leser: 2
5 Einträge, 1 Seite |
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
use IO::Socket;
use IO::Select;
my $s = new IO::Socket::INET (
LocalPort => '5800',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
);
die "Could not create socket: $!\n" unless $s;
$read_set = new IO::Select();
$read_set->add($s);
while (1) {
my $rh_set = IO::Select->select($read_set, undef, undef, 0);
foreach $rh (@$rh_set) {
if ($rh == $s) {
$ns = $rh->accept();
$read_set->add($ns);
}
else {
$buf = <$rh>;
if($buf) {
print $buf;
}
else {
$read_set->remove($rh);
close($rh);
}
}
}
}
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
#!C:\perl\bin\perl
use IO::Select;
use IO::Socket;
my @data;
$lsn = new IO::Socket::INET(Listen => 1, LocalPort => 9900);
$sel = new IO::Select( $lsn );
while(@ready = $sel->can_read) {
foreach $fh (@ready) {
if($fh == $lsn) {
# Create a new socket
$new = $lsn->accept;
$sel->add($new);
$addr=$new->peerhost;
# push(@data,($addr,
print "New Connection from $addr!\n";
}
else {
$test=<$fh>;
if ($test) {
print $test;
} else {
$sel->remove($fh);
$fh->close;
}
}
}
}
5 Einträge, 1 Seite |