[cse491] nonblocking

C. Titus Brown ctb at msu.edu
Sat Sep 13 22:05:53 PDT 2008


On Sun, Sep 14, 2008 at 12:58:26AM -0400, Alex Nolley wrote:
-> Hey I'm having some trouble understanding how the echo server and webserver
-> can accept multiple concurrent connections using only the nonblocking
-> method. Right now my nb echo server code has a while loop that handles the
-> sock.accept() in a try/except statement. If a client connects, the
-> client_sock is set to nonblocking and then a nested while loop is entered
-> that handles the conversation with that client. It works well enough if one
-> client connects at a time but it doesn't handle multiple concurrent
-> connections. My questions is, if we can't use multithreading, how do we
-> accept new connections and handle existing connections at the same time?

That's a good question :).

Have you tried keeping a list of connections and monitoring all of them
for new things to read & write?  Unlike in the blocking case, there's
nothing preventing you from sequentially trying to read from multiple
sockets.

--titus
-- 
C. Titus Brown, ctb at msu.edu



More information about the cse491-fall-2008 mailing list