Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. # client.pl
  2.  
  3. use strict;
  4. use warnings;
  5. use utf8;
  6. use JSON;
  7. use IO::Socket;
  8. use constant BUFSIZE => 1024;
  9. use Data::Dumper;
  10. my $JSONObject = JSON::XS->new->ascii->pretty->allow_nonref();
  11.  
  12. # for debug
  13. binmode STDOUT, ":utf8";
  14. my $host = shift or die "Usage: client.pl host\n";
  15. my $json_file = shift;
  16. my $port = '10280';
  17. my $buffer;
  18. my $json;
  19.  
  20.  
  21. {
  22. local $/; #Enable 'slurp' mode
  23. open my $fh, "<", $json_file;
  24. $json = <$fh>;
  25. close $fh;
  26. }
  27.  
  28.  
  29. my $socket = new IO::Socket(
  30. Domain => PF_INET,
  31. PeerAddr => $host,
  32. PeerPort => $port,
  33. Proto => getprotobyname('tcp'),
  34. Timeout => 60,
  35. ) or die $@;
  36.  
  37.  
  38. print Dumper($json);
  39. syswrite($socket, $json, BUFSIZE);
  40. shutdown($socket, 2);
  41. close($socket);
  42.  
  43. __END__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement