Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > BaseHTTPRequestHandler: how to read/write until diconnected

Reply
Thread Tools

BaseHTTPRequestHandler: how to read/write until diconnected

 
 
Maksim Kasimov
Guest
Posts: n/a
 
      07-13-2006

Hi,

I'm trying to write an server-application, using BaseHTTPServer/BaseHTTPRequestHandler.

When application is running, some client-application can post data to the server, and BaseHTTPRequestHandler reads all headers and posted raw data from "rfile", sends back response, than client/server session, than session closed - that works just fine.

how to check whether some data posted again by the client in the session, and send response again in one session (and do such iterations util client stops to post data) ?




something like this:

class ServerChannel( BaseHTTPServer.BaseHTTPRequestHandler ):

def do_POST(self):

while needReadMessage:
...
msg_count += 1
log.info( "message number %d arrived" % msg_count )
raw_post_data = self.rfile.read( contentLength )
...
self.wfile.write( respContent )


many thanks for help.


--
Maksim Kasimov
 
Reply With Quote
 
 
 
 
notanotheridiot
Guest
Posts: n/a
 
      07-13-2006

Maksim Kasimov wrote:
> I'm trying to write an server-application, using BaseHTTPServer/BaseHTTPRequestHandler.
>
> When application is running, some client-application can post data to the server, and BaseHTTPRequestHandler reads all headers and posted raw data from "rfile", sends back response, than client/server session, than session closed - that works just fine.
>
> how to check whether some data posted again by the client in the session, and send response again in one session (and do such iterations util client stops to post data) ?
>


BaseHTTPServer is precisely that, a HTTP server. what you are
describing is not (I'm pretty sure) not HTTP.
HTTP/1.1 can do something similar and is supported by BaseHTTPServer:
with HTTP/1.1 the stream is not closed between requests. This relies on
a Content-Length field being present in all communications from the
server to the client. To enable HTTP/1.1 you have to set the
protocol_version attribute of your BaseHTTPRequestHandler derived class
to "HTTP/1.1" .

A little while back I wrote a small guide to HTTP in the context of
BaseHTTPServer: http://crunchy.python-hosting.com/wiki/HttpServer

If (as I think) you want to send multiple, inter-dependent messages
each way under the aegis of one HTTP request, you should probably look
at sublassing TCPServer (you can, and probably should, still use
mimetools.Message to parse headers though).

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
after IDN test, web locked until restart - ff(dp) beta 1.6b Splibbilla Firefox 1 10-06-2005 09:55 AM
Wi-Fi network unavailable until router restarted Petr Tomasek Wireless Networking 1 08-08-2005 08:34 PM
wait until Brad Smallridge VHDL 2 03-26-2005 01:34 PM
No Connection Until WLAN Utility is Run undaunted1 Wireless Networking 2 02-05-2005 07:38 PM



Advertisments