I'm using Amazon SNS to send/receive HTTP notifications. Sending works ok but for receiving, I need a simple socket server that would accept inbound HTTP messages.
I created this (quick & dirty)
# Turn on autoflushing
$| = 1;
my $port = 54321;
my $server = IO::Socket->new(
Domain => PF_INET,
Proto => 'tcp',
LocalPort => $port,
Listen => SOMAXCONN,
Reuse => 1,
die "Bind failed: $!\n" unless $server;
my $new_sock = $server->accept();
print $_ . "\n";
However, what happens is that I get ALL of the data incoming EXCEPT that very last byte. The last byte is a squiggly } and I don't get it until much later. It's really strange. And then Amazon attempts to resend the message again. So, it ends up getting all screwed up.
I have a feeling accepting raw TCP packets is not the right way, that I'm missing something inherent to HTTP.
What am I doing wrong, can you please help?