Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # client.pl
- use strict;
- use warnings;
- use utf8;
- use JSON;
- use IO::Socket;
- use constant BUFSIZE => 1024;
- use Data::Dumper;
- my $JSONObject = JSON::XS->new->ascii->pretty->allow_nonref();
- # for debug
- binmode STDOUT, ":utf8";
- my $host = shift or die "Usage: client.pl host\n";
- my $json_file = shift;
- my $port = '10280';
- my $buffer;
- my $json;
- {
- local $/; #Enable 'slurp' mode
- open my $fh, "<", $json_file;
- $json = <$fh>;
- close $fh;
- }
- my $socket = new IO::Socket(
- Domain => PF_INET,
- PeerAddr => $host,
- PeerPort => $port,
- Proto => getprotobyname('tcp'),
- Timeout => 60,
- ) or die $@;
- print Dumper($json);
- syswrite($socket, $json, BUFSIZE);
- shutdown($socket, 2);
- close($socket);
- __END__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement