client derived from async_chat
Patrick Useldinger
pu at nodomain.lu
Mon Aug 18 16:34:06 EDT 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):
timeOut=self.gettimeout()
self.settimeout(None)
SingleServer.connect(self,*args)
self.settimeout(timeOut)
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.
-Patrick
--
Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64')
Visit my Homepage at http://www.homepages.lu/pu/
More information about the Python-list
mailing list