Created
September 15, 2017 07:56
-
-
Save perbu/315a3703996813a14e2633d92c95c49d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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