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? Thank you.

When you send a message over a socket, you have no control over how many pieces the message gets chopped up into. For instance, if you send the message 'hello world', that could get sent in 1 piece, 2 pieces, 3 pieces, etc., and the pieces could all be different lengths. Therefore, the sender and the receiver of the message have to agree on a signal for the end of the message--that way the receiver knows when it can stop trying to read from the socket.

Some protocols use end-of-file as the signal that the receiver should stop trying to read from the socket. The eof signal is sent when the other side closes the socket. In your case, amazon is doing a retry, so amazon doesn't close the socket, which means your while loop doesn't end after it reads the entirety of the message.

I don't think you can use the closing brace as a signal to tell you when you should stop trying to read from the socket, because closing braces can exist within a JSON formatted message as well. Maybe look for a line that consists of just a closing brace? Alternatively, you have to figure out what characters amazon sends between the end of the message and the retry, and look for those characters in your while loop so you can break out of it.

I looked around a little bit, and the retry feature is something people have been requesting, but nothing indicates that amazon has implemented retry yet or how to configure it. Your results indicate that amazon has indeed implemented that feature.

Also, note that when you use the line input operator, <>, you are not telling perl to read whatever data is available in the socket--instead you are telling perl to block and keep trying to read until perl reads in a newline. After reading a newline, the parts of the message that have been read up to that point are returned and the body of the while loop executes.


In reply to Re: problems accepting HTTP packets from Amazon by 7stud
in thread problems accepting HTTP packets from Amazon by coontie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.