1
2
3
4
5
6
7
8
my $master6 = IO::Socket::INET6->new(
Domain => AF_INET6,
LocalPort => 2000,
Listen => 5,
Proto => 'tcp',
MultiHomed => 1,
ReuseAddr => 1
);
1
2
3
4
5
6
7
my $master4 = IO::Socket::INET->new(
LocalPort => 2000,
Listen => 5,
Proto => 'tcp',
MultiHomed => 1,
ReuseAddr => 1
);
1
2
3
4
5
6
7
8
9
10
Aktive Internetverbindungen (Server und stehende Verbindungen)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 942/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1201/cupsd
tcp 0 0 192.168.0.191:50536 209.85.149.106:80 TIME_WAIT -
tcp 0 0 192.168.0.191:59723 209.85.149.99:80 TIME_WAIT -
tcp 0 0 192.168.0.191:50534 209.85.149.106:80 TIME_WAIT -
tcp6 0 0 :::2000 :::* LISTEN 1862/perl
tcp6 0 0 :::22 :::* LISTEN 942/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1201/cupsd
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
#!/usr/bin/perl use 5.010; use strict; use warnings; use IO::Socket::INET6; my $pid = fork; die "error: cannot fork!\n" unless defined $pid; # edit my $server = IO::Socket::INET6->new( LocalAddr => $pid ? '127.0.0.1' : '::1', LocalPort => 20_000, Listen => 5, Proto => 'tcp', ReuseAddr => 1, ) or die "error creating socket: $@\n"; while (my $client = $server->accept) { chomp(my $request = <$client>); if ($request =~ /^quit|exit|bye/) { print $client "exiting\n"; close $client; exit; # es wird nur der beendet, mit dem verbunden wurde. nicht beide } print $client (scalar reverse $request), "\n"; close $client; }
1 2 3 4 5 6 7
my $server = IO::Socket::INET6->new( LocalAddr => '::', # <-- LocalPort => 20_000, Listen => 5, Proto => 'tcp', ReuseAddr => 1, ) or die "error creating socket: $@\n";
1
2
3
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:20000 0.0.0.0:* LISTEN 10827/perl
tcp6 0 0 ::1:20000 :::* LISTEN 10828/perl
tcp6 0 0 :::20000 :::* LISTEN 10947/perl
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
#!/usr/bin/perl use 5.010; use strict; use warnings; use IO::Socket::INET6; while () { print "> "; my $command = <STDIN>; my $addr = $command =~ s/^4// ? '127.0.0.1' : '::1'; my $socket = IO::Socket::INET6->new( PeerAddr => $addr, PeerPort => 20_000, Proto => 'tcp', ) or die "error creating socket: $@\n"; print $socket $command; print scalar <$socket>; close $socket; last if $command =~ /^quit|exit|bye/; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ perl server.pl &
$ perl client.pl
> foobar
raboof
> 4foobar
raboof
> exit
exiting
$ perl client.pl
> test
error creating socket: IO::Socket::INET6: connect: Verbindungsaufbau abgelehnt
$ perl client.pl
> 4test
tset
> 4exit
exiting
[1]+ Fertig perl server.pl
setsockopt( $master6, IPPROTO_IPV6, IPV6_V6ONLY, 1 );
setsockopt( $master6, IPPROTO_IPV6, 26, 1 );
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
#!/usr/bin/env perl
use strict;
use warnings;
use Socket qw(:all);
use IO::Socket;
use IO::Socket::INET;
my $sock;
my $tcpnodelay;
print "\nUsing built-in method\n";
my $proto = getprotobyname ('tcp');
socket ($sock, PF_INET, SOCK_STREAM, $proto) or die "Socket: $! ($^E)";
$tcpnodelay = getsockopt ($sock, IPPROTO_TCP, TCP_NODELAY);
$tcpnodelay = unpack 'I', $tcpnodelay;
print "Before: tcpnodelay=$tcpnodelay\n";
setsockopt $sock, IPPROTO_TCP, TCP_NODELAY, 1 or die "setsockopt: $! ($^E)";
$tcpnodelay = getsockopt ($sock, IPPROTO_TCP, TCP_NODELAY);
$tcpnodelay = unpack 'I', $tcpnodelay;
print "After: tcpnodelay=$tcpnodelay\n";
print "\nUsing OO method\n";
$sock = IO::Socket::INET->new(Type => SOCK_STREAM, Proto =>'tcp') or
die "new IO::Socket::INET: $! ($^E)";
$tcpnodelay = $sock->sockopt(TCP_NODELAY);
print "Before: tcpnodelay=$tcpnodelay\n";
$sock->sockopt(TCP_NODELAY, 1) or die "\$sock->sockopt NODELAY, 1: $! ($^E)";
$tcpnodelay = $sock->sockopt(TCP_NODELAY);
print "After: tcpnodelay=$tcpnodelay\n";
print "\n\n";
__END__
1
2
3
4
5
6
7
Using built-in method
Before: tcpnodelay=0
After: tcpnodelay=1
Using OO method
Before: tcpnodelay=0
$sock->sockopt NODELAY, 1: Keine Berechtigung (Keine Berechtigung) at ./Server3.pl line 30.
1
2
3
4
5
6
7
8
9
[sudo] password for enzo:
Using built-in method
Before: tcpnodelay=0
After: tcpnodelay=1
Using OO method
Before: tcpnodelay=0
After: tcpnodelay=-1