[Tutor] Using Select

Sean 'Shaleh' Perry shalehperry@attbi.com
Tue, 26 Mar 2002 09:10:55 -0800 (PST)


> 
> I currently have the code written to read the data from
> the connection and display it back to the user.  What I
> need a bit of help with is allowing multiple connections
> to do so at the same time.  Currently I plan on using
> select to allow the multiple connections.  I have a vague
> idea of how to go about using select but I am looking for
> a bit more info.  Does anyone know of a good walkthrough
> for select that they could point me to?  Also is there a
> better way to allow for the multiple connections in a
> situation like this (fork, threads)?
> 
> I have a fairly good programming background having worked
> with C for quite awhile, but I haven't done very much socket
> or network related programming and any information that you
> could point me to on either topic (python focused preferably)
> would be greatly appreciated.
> 

While it is written in C, W. Richard Stevens "UNIX Network Programming" books
are one of the corner stones of the field.

There are advantages and disadvantages to any approach.  I think forking a
python server sounds like a bad idea.  If you use select you need to keep a
distinct record in memory for each connection and have a way to reference these
records with the socket that responded (a list or a dictionary probably). 
Threading is a nice approach as it gives you some of the clarity of a fork
design without the fork.  But you also have to deal with threading (-:

Since you are new to this, my recommendation would be to use a select loop and
make that work.  Then try to implement the threading method.  Since you will
already understand all of the things needed to support multiple connections you
will be able to focus on threading idiosynchracies when you get there.  It also
makes sense to start easy and work up.