BaseHTTPServer and keep-alive (evil hack problem)

D

David

This is called "evil hack problem" because my problems are due to me
trying to do an evil hack. Please don't judge me, just believe that
there are reasons for what I'm trying to do :)

I've got a problem with BaseHTTPServer. I am trying to keep a
connection alive so that I can send data down it. At the moment, I
have subclassed BaseHTTPRequestHandler like this:


def do_POST(self):
body =
self.rfile.read(int(self.headers.getheader("content-length")))

# handle the message.
pm.handle_message(body, self.client_address[0],
self.wfile)
debug("sending keep-alive header")
self.send_header("Connection", "keep-alive")


The handle_message method puts the wfile into a global map. When the
server wants to send more data, it just writes to the wfile. This
occurs in a separate thread.
So the do_POST method swiftly returns. I send the "keep-alive" header
because it seems to set connection_closed to 0 in the
BaseHTTPRequestHandler code, rather than because the client needs to
hear it.

However, when I try and write data to the wfile, I get:


Exception in thread Thread-3:Traceback (most recent call last):
File "/usr/lib/python2.3/threading.py", line 442, in __bootstrap
self.run()
File "/usr/lib/python2.3/threading.py", line 422, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/dhughj/blogfish/src/PeerManager.py", line 267, in
_passive_send
wfile.write(message)
File "/usr/lib/python2.3/socket.py", line 254, in write
self.flush()
File "/usr/lib/python2.3/socket.py", line 241, in flush
self._sock.sendall(buffer)
AttributeError: 'NoneType' object has no attribute 'sendall'


Can anyone help me to keep the connection alive at both ends, or
explain why at the moment the server is closing the conenection?

Thanks a lot.

David
 
C

Christos TZOTZIOY Georgiou

On 26 Jul 2004 06:35:37 -0700, rumours say that (e-mail address removed)
(David) might have written:

<snip>

ICBW, but I think BaseHTTPServer is HTTP/1.0 compatible, not HTTP/1.1
--so at the end of every request, the socket is closed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top