testd.pl (828B)
1 #!/usr/bin/perl 2 use strict; 3 use warnings; 4 $| = 1; 5 6 use IO::Socket::UNIX; 7 use JSON::XS; 8 9 my $socket_path = "testd.socket"; 10 11 $SIG{TERM} = sub { unlink $socket_path; exit 0 }; 12 $SIG{INT} = sub { unlink $socket_path; exit 0 }; 13 14 my $server = IO::Socket::UNIX->new( 15 Type => SOCK_STREAM(), 16 Local => $socket_path, 17 Listen => 1, 18 ) or die "$socket_path: couldn't create socket: $!\n"; 19 20 while (my $client = $server->accept()) { 21 $client->read(my $data, 4096); 22 my $notify = decode_json($data); 23 24 my $num_devices = @{ $notify->{devices} }; 25 next if ($num_devices == 0); 26 27 print "testd: message type '$notify->{msg_type}'\n"; 28 # print "testd: payload is '" . Dumper($notify->{payload}) . "'\n"; 29 30 for (@{ $notify->{devices} }) { 31 #print Dumper($_); 32 my ($os, $push_token) = @$_; 33 print "testd: sending to '$push_token' os '$os'\n"; 34 } 35 }