Thanks for every ones help.
I got it working here's the working code.
I had to remove from the original code the line with
print <$cl>;
I also had to alter each line to have a leading [ and a trailing ], it's now working.
Working code:
#!/usr/bin/perl
use strict;
use IO::Socket::SSL; #qw(debug3);
use JSON::SL;
use Data::Dumper;
print "JSON Stream parser test\r\n";
my $p = JSON::SL->new;
#Look for everything past the first JSON pointer
$p->set_jsonpointer(["/^"]);
# simple client
my $cl = IO::Socket::SSL->new(
PeerAddr => 'example.com',
PeerService => 'https',
PeerPort => 443,
Proto => 'tcp',
Reuse => 1
);
die "no connection" unless $cl -> connected();
print $cl "GET /stream/report?token=IMNOTAREALTOKEN HTTP/1.0\r\n\r
+\n";
#print <$cl>;
#local $/ = \5; #read only 5 bytes at a time
while (my $line = <$cl>) {
chomp($line); #Remove new line characters
$line = "[$line],\n"; # Add leading [ and trailing ], so i
+t will parse correctly
if ($line =~ m/{"\w{14}/) {
print "Received:\n$line";
$p->feed($line); #parse what you can fetch anything that co
+mpleted the parse and matches the JSON Pointer
while (my $obj = $p->fetch) {
print Dumper($obj);
print "$obj->{Value}{flowStartSeconds}: $obj->{Value}{
+senderCallsign}\n";
}
}
}
close $cl;
|