PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 35ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/tests/netcat.pl

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
Perl | 35 lines | 28 code | 7 blank | 0 comment | 4 complexity | 910ccdccce0cba79e88b0ec63d8197f1 MD5 | raw file
 1use strict;
 2use warnings;
 3
 4use Socket;
 5
 6binmode(STDIN);
 7$| = 1;
 8binmode(STDOUT);
 9
10if (@ARGV != 2) {
11  die "Usage: netcat.pl HOST PORT\n";
12}
13
14my $host = shift;
15my $port = shift;
16
17my $address = inet_aton($host) or die;
18my $address_and_port = sockaddr_in($port, $address);
19my $protocol = getprotobyname('tcp');
20socket(SOCKET, PF_INET, SOCK_STREAM, $protocol) or die;
21
22my $old = select(SOCKET);
23$| = 1;
24select($old);
25binmode(SOCKET);
26
27connect(SOCKET, $address_and_port) or die;
28while (<STDIN>) {
29  print SOCKET $_;
30}
31while (<SOCKET>) {
32  print;
33}
34close(SOCKET);
35exit 0;