Skip to content

Instantly share code, notes, and snippets.

@perbu
Created September 15, 2017 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perbu/315a3703996813a14e2633d92c95c49d to your computer and use it in GitHub Desktop.
Save perbu/315a3703996813a14e2633d92c95c49d to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use IO::Socket;
use constant MAXWRITE => 2000; #biggest write we'll attempt
use strict;
use warnings;
$|++; # autoflush stdout
my ($host,$port) = @ARGV;
my $socket = new IO::Socket::INET (
PeerHost => $host,
PeerPort => $port || 5001,
Proto => 'tcp'
);
die "Connection error: $!\n" unless ($socket);
print "Connection established.\n";
my $recvbuffer;
foreach my $i (1 .. MAXWRITE) {
my $string = "x" x $i; # build string to write to stream.
print("$i: ");
$socket->send($string);
print("(sent) ");
$socket->recv($recvbuffer, MAXWRITE);
print(length($recvbuffer)," ", "(recieved) ");
print "(match) " if ($string eq $recvbuffer);
print "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment