Thread IO::Select und Sockets (9 answers)
Opened by pq at 2003-11-29 15:07

pq
 2003-11-29 17:02
#38193 #38193
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
ich bin mal so frei:
Code: (dl )
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
#!/usr/bin/perl -w
use strict;
use IO::Socket;
use IO::Select;
my $hname = "localhost";
my $hport = $ARGV[0];

my $sock = new IO::Socket::INET->new(
 LocalPort => $hport,
 Listen => 10,
 Reuse => 1,
 Proto => 'tcp'
);
my $sel = new IO::Select->new();
$sel->add($sock);
$sel->add(*STDIN);

die "*Could not Connect" unless $sock;
while(1){
 while(my @ready = $sel->can_read) {
   foreach my $fh (@ready) {
     if ($fh eq $sock) {
       my $new = $sock->accept;
       $sel->add($new);
       print "Willkommen\n";
     }
     elsif($fh eq *STDIN) {
       my $buf = <STDIN>;
       print "Client\n";
       client($buf);
     }
     else{
       $sel->remove($fh);
       $fh->close;
     }
   }
 }
}
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread IO::Select und Sockets