wsgi, ajax, and multiple requests

Adam Tauno Williams awilliam at whitemice.org
Wed Feb 9 14:52:41 CET 2011


On Wed, 2011-02-09 at 14:31 +0200, Frank Millman wrote: 
> I am dabbling with writing an ajax-style app. On occasion, I want to send 
> more than one message from the client to the server. It is important that 
> the server processes the messages in the same order that they are generated. 
> I have found that the Safari browser does not always send them in the 
> correct sequence.
> I found an article on the subject -
> http://www.sitepen.com/blog/2009/02/27/deterministic-clientserver-interaction/
> It explains that you can never guarantee that the messages will arrive in 
> the same order, with *any* browser.

Correct.

> Maybe I was lucky with the other ones. 
> It goes on to say that, if the order is important, you must include a header 
> with a sequential counter, and the server must check the sequence.

Yep.  This is similar to the If-Match headers used by HTTP (and
especially WebDAV).

> So the question is, how can I achieve this with wsgi? If I detect that I 
> have received a request out of sequence, I can queue the request, and send 
> an empty response. When I receive the correct request, I can process it, 
> call start_response(), and return the response body, but I cannot figure out 
> how to get back to process the queued request.

I'd simply notify the client that the request could not be processed and
have the client resend; this generally works much better than trying to
"hold" the request on the server [what if the next one you expect never
comes?  what if you hit a different server due to DNS round-robin /
clustering / etc...]  If order is *very* important the client should
perform each operation sequentially only sending the next-step when it
has confirmation the previous ones have completed.  This is really a
client-side issue IMO.




More information about the Python-list mailing list