473,396 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

BaseHTTPRequestHandler: how to read/write until diconnected


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
Jul 13 '06 #1
1 4113

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).

Jul 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ben | last post by:
Hi all, I have written a web server that listens for requests: class MyHandler(BaseHTTPRequestHandler): def do_GET(self): if (self.path)=='/': data=makeList() else:
2
by: Andy Leszczynski | last post by:
Does BaseHTTPServer.BaseHTTPRequestHandler support HTTP protocol chunking? Thanks, Andy
21
by: Jason Heyes | last post by:
I want to allow objects of my class to be read from an input stream. I am having trouble with the implementation. Here are the different approaches I have tried: // Version 1.0 - Default...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
14
by: spike | last post by:
Im trying to write a program that should read through a binary file searching for the character sequence "\name\" Then it should read the characters following the "\name\" sequence until a NULL...
4
by: oncelovecoffee | last post by:
str_Array() 'strings I need save it to file and next time i can read from file. --------------------------------------------------------...
1
by: Christopher J. Bottaro | last post by:
Hi, I can't for the life of me figure out how to get the post vars when using basehttpserver. Here's my code: <code> class MyHandler(BaseHTTPRequestHandler): def do_POST(self):
8
by: paraidy | last post by:
Hi all, as from object i need to read all byte from a file example c: \myphoto.jpg and recreate the file with another name to another directory c:\photo\recreatedphoto.jpg can someone write a...
1
by: gcmartijn | last post by:
H! I was wondering how I can do something like this. file.html --------- <b>hello world</b> <special pythoncodetag> print 'hello world' #or display str(time.localtime())
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.