One last thing about SocketServer

R

rbt

I've read more about sockets and now, I have a better understanding of
them. However, I still have a few SocketServer module questions:

When used with SocketServer how exactly does socket.setdefaulttimeout()
work? Does it timeout the initial connect request to the socket server
or does it timeout the session between the connecting client socket and
the client socket the server generated to handle the incoming request?

Also, since the *only* thing a 'socket server' does is to create 'client
sockets' to handle requests, how do I use socket object features on
these generated clients to manage and/or monitor them?

The SocketServer module is great, but it seems to hide too many details
of what it's up to!

Thanks,
rbt
 
S

Steve Holden

rbt said:
I've read more about sockets and now, I have a better understanding of
them. However, I still have a few SocketServer module questions:

When used with SocketServer how exactly does socket.setdefaulttimeout()
work? Does it timeout the initial connect request to the socket server
or does it timeout the session between the connecting client socket and
the client socket the server generated to handle the incoming request?
setdefaulttimeout() simply sets the default timeout for all sockets
created thereafter. This timeout applies to any socket operation, I
believe (though I am unsure about "accept()").
Also, since the *only* thing a 'socket server' does is to create 'client
sockets' to handle requests, how do I use socket object features on
these generated clients to manage and/or monitor them?
When the accept() call on a socket returns a tuple(socket, address): the
first element of the returned tuple is the socket you use to communicate
with that particular client (in other words, it represents the server
end of the connection that's just been accept()ed).

So you can read and write that socket to communicate with that client
over that specific connection. Of course, if you don't use either the
ThreadingMixIn or the ForkingMixIn then communication with one client
will effectively stop you form accept()ing any more connections, hence
the need for the mix-in classes.
The SocketServer module is great, but it seems to hide too many details
of what it's up to!
Well, of course, that is what abstractions are for! You should bear in
mind that SocketServer isn't necessarily the most efficient or effective
way to handle multiple clients concurrently, but it's very convenient
when you are just getting started.

Later you might want to consider an asyncore-based approach, or perhaps
using the Twisted package. Both of these solutions are a little more
robust for production code.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top