/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/tests/netcat.pl
Perl | 35 lines | 28 code | 7 blank | 0 comment | 4 complexity | 910ccdccce0cba79e88b0ec63d8197f1 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
- use strict;
- use warnings;
-
- use Socket;
-
- binmode(STDIN);
- $| = 1;
- binmode(STDOUT);
-
- if (@ARGV != 2) {
- die "Usage: netcat.pl HOST PORT\n";
- }
-
- my $host = shift;
- my $port = shift;
-
- my $address = inet_aton($host) or die;
- my $address_and_port = sockaddr_in($port, $address);
- my $protocol = getprotobyname('tcp');
- socket(SOCKET, PF_INET, SOCK_STREAM, $protocol) or die;
-
- my $old = select(SOCKET);
- $| = 1;
- select($old);
- binmode(SOCKET);
-
- connect(SOCKET, $address_and_port) or die;
- while (<STDIN>) {
- print SOCKET $_;
- }
- while (<SOCKET>) {
- print;
- }
- close(SOCKET);
- exit 0;