asyncore: handle_accept() question?

Erik Max Francis max at alcyone.com
Wed Aug 27 18:53:10 EDT 2003


Chris wrote:

>                 self.set_reuse_addr() # needed?

This is definitely not needed in the connection; it's only useful in the
server.  (I doubt this is your problem.)

> My basic problem is that I don't know any other way to 'hand off' the
> incoming connection - if there is a better way to do this please let
> me know. conn.fileno() appears to work, and I don't understand why
> this error comes up.
>
> Any ideas?

It looks like you're trying to do too much in your connection class
constructor.  In the way you're using it, after accept is called, the
connection socket is already open and ready.  You need not create or
initialize it; the fact that you're doing so is invariably what's
causing your error, although I'll admit I haven't tried to actually
reproduce it.  In fact, after accept, initializing a connection is
simpler than simple.  All you need to do is pass the socket into the
asyncore.dispatcher/asynchat.async_chat constructor:

	class Connection(asyncore.dispatcher):
	    def __init__(self, host, port, sock):
	        asyncore.dispatcher.__init__(self, sock)
	        # all done, your connection is ready to go

As it stands, you're creating new sockets and attempting to connect to
the connection address of the _accepted_ socket (where there isn't a
server listening), so it looks like you're getting a partially
initialized socket which would explain your problem.

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ Life is a gamble so I should / Live life more carefully
\__/  TLC




More information about the Python-list mailing list