Leser: 3
2 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
use strict;
use warnings;
use IO::Socket::INET;
my $socket = IO::Socket::INET->new(
LocalHost => '127.0.0.1',
LocalPort => 43618,
Type => SOCK_STREAM,
Listen => 10,
Reuse => 1,
) or die "server: can't open socket over port 43618";
warn "server initialized\n";
while ( 1 ) {
while (my $client = $socket->accept) {
my $request = <$client>;
chomp($request);
next unless $request;
warn "client pid: $request\n";
# close() um zu testen wie der Client darauf reagiert
close($client);
}
}
close($socket);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use strict;
use warnings;
use IO::Socket::INET;
my $socket = IO::Socket::INET->new(
PeerAddr => '127.0.0.1',
PeerPort => 43618,
Proto => 'tcp',
Type => SOCK_STREAM,
) or die "client: can't connect to 127.0.0.1:43618";
warn "client connected to server\n";
while ( 1 ) {
warn "send pid to server\n";
eval { print $socket "$$\n" };
last if $@;
sleep 1;
}
warn "lost connection\n";
close($socket);
1
2
3
4
5
#> perl client.pl
client connected to server
send pid to server
send pid to server
send pid to server
$SIG{PIPE}='IGNORE';
2 Einträge, 1 Seite |