Problems Returning an HTTP 200 Ok Message
GDavidson7 at gmail.com
Thu Jul 10 23:10:46 CEST 2008
On Jul 10, 12:38 pm, samwyse <samw... at gmail.com> wrote:
> On Jul 10, 1:50 pm, Guy Davidson <GDavids... at gmail.com> wrote:
> > Hi Folks,
> > I'm having some issues with an small socket based server I'm writing,
> > and I was hoping I could get some help.
> > My code (attached below) us supposed to read an HTTP Post message
> > coming from a power meter, parse it, and return a proper HTTP 200 Ok
> > message. The problem is that the socket fails to send the entire
> > message as one message, creating a fragmented message which the power
> > meter then fails to read and accept.
> > Is there any way to force the socket to send the entire message at
> > once? Am I doing anything wrong? Is there an easier way to implement
> > this functionality?
> By 'message', do you mean a single IP datagram? In general, the
> answer is no. Each call to 'connection.send()' will (in general, see
> the next paragraph) transmit as much data as will fit into a single IP
> datagram, given the current MTU for the transmission circuit. The
> fact that you're calling it in a loop indicates that the data being
> sent may be larger than will fit into a datagram.
> Or, by 'message', do you mean a single TCP segment? Again, the answer
> is no. Your network stack will try to make the TCP segments the right
> size to fit within a single IP datagram, leading to the same result as
> From your description, I get the feeling that your power meter has a
> broken network stack, and you're trying to program around it. You
> need to repair the meter.
Here's the weird thing. I know it should be able to be done.
Let me try and explain in some more depth what I'm trying to do:
The meter sends HTTP Post messages, and expects, as a reply, an HTTP
I try to send the following message, using the socket.send() command:
'HTTP/1.1 200 OK\r\nDate: Thu, 10 July 2008 14:07:50 GMT\r\nServer:
Apache/2.2.8 (Fedora)\r\nX-Powered-By: PHP/5.2.4\r\nContent-Length: 4\r
\nConnection: close\r\nContent-Type: text/html; charset=UTF-8\r\n\r
However, when I snoop on the packets in wireshark, here's what I see:
HTTP/1.1 200 Ok:
HTTP/1.1 200 OK
Date: Wed, 09 July 2008 14:55:50 GMT
Server: Apache/2.2.8 (Fedora)
Continuation or non-HTTP traffic:
Content-Type: text/html; charset=UTF-8
It splits into two packages, which the meter can't read, and the
communication breaks down there.
More information about the Python-list