[Tutor] python and MS Access db's

alan.gauld@bt.com alan.gauld@bt.com
Sat, 23 Mar 2002 22:14:44 -0000


> > If the answer to both is no then consider a dedicated
> > client/server solution using raw sockets - it will perform
> ... it sounds like there are alternatives.  "raw socket"?  I haven't 
> heard of those.  The only sockets I am familiar with are network 
> sockets -- the sort that work like this
> 
> = socket listens at port 80 or whichever
> = request comes along
> = socket daemon spawns a new socket for the request and redirects the 
> request to the new socket
> = client and server do their business on new socket, 

Yes thats what i meant by a raw socket type approach. In opther words 
not using a pre canned protocol like http/CGI

You can use any port(non standard) for the listener. And the messages 
can be any string you define thus for a bespoke application you can 
define your own protocol using specific requests with specific 
parameters etc. This is usually much more efficient that trying to use 
http/GET or POST type requiests, especially since you can hold the 
connection open for as long as you need so don't need to keep 
posting the context.

> envisioning how programs that are not stateless 

THis is one of the biggest gains. Sending state with each request
(or reassembling it from cache) is a real performance hit. If you 
just think of it as a dialogue between two objects conducted 
using strings its pretty easy. Typically you use a fixed length 
first field to identify the message then the server application
uses an event loop type approach:

msg = rec_str[:3]  # assume 3 char msg ID
if msg == "CHK":  # check balance
    return checkBalance(msg[3:])  # knows how to unpack the params
elif msg == "ADD":  # add to balance
    return addSum(msg[3:])
elif msg == "SUB":
	...etc...
else: return "ERR:unknown message"

Some people would have you believe that passing message parameters 
is an enormously difficult task and call it marshalling coz it 
sounds good. But for simmple apps it doesn't need to be more 
complicated than an agreed set of string formatting conventions.

Of course you can use the struct module and send binary values 
but IMHO thats too complicated anda sign you've reached the stage 
where you need CORBA or something else more industrial strength...

Alan g.