PageRenderTime 898ms CodeModel.GetById 883ms RepoModel.GetById 0ms 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
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. use strict;
  2. use warnings;
  3. use Socket;
  4. binmode(STDIN);
  5. $| = 1;
  6. binmode(STDOUT);
  7. if (@ARGV != 2) {
  8. die "Usage: netcat.pl HOST PORT\n";
  9. }
  10. my $host = shift;
  11. my $port = shift;
  12. my $address = inet_aton($host) or die;
  13. my $address_and_port = sockaddr_in($port, $address);
  14. my $protocol = getprotobyname('tcp');
  15. socket(SOCKET, PF_INET, SOCK_STREAM, $protocol) or die;
  16. my $old = select(SOCKET);
  17. $| = 1;
  18. select($old);
  19. binmode(SOCKET);
  20. connect(SOCKET, $address_and_port) or die;
  21. while (<STDIN>) {
  22. print SOCKET $_;
  23. }
  24. while (<SOCKET>) {
  25. print;
  26. }
  27. close(SOCKET);
  28. exit 0;