BaseHTTPRequestHandler: how to read/write until diconnected

Discussion in 'Python' started by Maksim Kasimov, Jul 13, 2006.

  1. 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
     
    Maksim Kasimov, Jul 13, 2006
    #1
    1. Advertising

  2. 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).
     
    notanotheridiot, Jul 13, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben
    Replies:
    2
    Views:
    422
    bromden
    Oct 19, 2003
  2. Christopher J. Bottaro

    getting POST vars from BaseHTTPRequestHandler

    Christopher J. Bottaro, Jun 26, 2006, in forum: Python
    Replies:
    1
    Views:
    2,895
  3. Replies:
    1
    Views:
    386
    aspineux
    Apr 6, 2007
  4. tzuchien
    Replies:
    3
    Views:
    1,308
    Gabriel Genellina
    Aug 23, 2007
  5. Replies:
    1
    Views:
    1,061
Loading...

Share This Page