client derived from async_chat

Patrick Useldinger pu at
Mon Aug 18 22:34:06 CEST 2003

Heiko Wundram wrote:

> Remember: connecting is also a non-blocking operation, if the socket is
> set to non-blocking mode.

I should have read some more about sockets before trying to use 
async_chat; I thought I would get by 'just adding a few methods'. Shame 
on me ;-)

Anyway, what happened is that 'create_socket()' and 'connect()' were 
called to quickly one after the other; as async_chat (asnycore, 
actually) sets the socket on creation to non-blocking, my connect failed.

I solved the problem by adding a method 'connect()' in my derived class 
which looks like this:

     def connect(self,*args):

This did the trick for my chat client.

> I dunno why async_chat doesn't work with this on Windows (on *nix, this
> is exactly what it does), but I guess it has something to do with
> decoding the error codes, as a *nix-socket would return EWOULDBLOCK in
> this case, for which it checks, I am certain of that.

I think it works as designed, but it was not designed to open sockets 
for clients, only for servers. I could have opened the socket outside 
the method, probably, but I really wanted the class to handle all of the 
network stuff.

Anyway, it works fine now.

Thanks for your explanation.


Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64')
Visit my Homepage at

More information about the Python-list mailing list