File: server-generator.pl

package info (click to toggle)
libredis-fast-perl 0.34%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 492 kB
  • sloc: perl: 2,630; makefile: 7
file content (29 lines) | stat: -rwxr-xr-x 525 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

use strict;
use warnings;
use IO::Socket::INET;

$| = 1;
my $sock = IO::Socket::INET->new(
    Listen    => 5,
    LocalAddr => 'localhost',
    LocalPort => 1234,
    Proto     => 'tcp',
    ReuseAddr => 1,
);

die $! unless $sock;
die $! unless $sock->listen();

while (my $client = $sock->accept()) {
    my $line = <$client>;
    chomp $line;

    my ($cnt, $len) = split(',', $line);
    next unless $cnt || $len;

    for (my $i = 1; $i <= $cnt; ++$i) {
        print $client '.' x $len, "\n";
    }
}