asyncore: handle_accept() question?

Chris chrisahlers at yahoo.com
Wed Aug 27 21:17:52 EDT 2003


Everything works fine now. Your message made perfect sense.

Thank you,
Chris

Erik Max Francis <max at alcyone.com> wrote in message news:<3F4D3656.9119ECC1 at alcyone.com>...
> 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.




More information about the Python-list mailing list