in reply to problems accepting HTTP packets from Amazon
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problems accepting HTTP packets from Amazon
by coontie (Sexton) on Jun 22, 2011 at 21:57 UTC |