from reading the asyncore
documentation, it seems handle_connect()
should be called after you successfully connect to a listening socket, i.e after the TCP handshake is done. But in practice, it seems asyncore
does not run handle_connect()
unless it receives or send a packet on the socket.
As an example:
I have server socket binded and listening on a certain port. The socket will accept any incoming connection, print what it receives, and send "thank you" back.
I then start an asyncore.dispatcher
based client, who connects to the server socket when created. The client has a method handle_connect()
which sends a "hello" packet to the server. It also has a method read that prints the packet received. (in this case it should print "thank you")
When this client is run, the connection is created, the TCP handshake is successful, and the server is able to accept the connection, but nothing else happens. handle_connect()
is never called.
The only way to make asyncore run handle_connect()
is if the server start by sending a packet, or if i send a packet to the server in the __init()__
function. then handle_connect()
works and everything works fine.
Is this how things are supposed to work? and if so, why? or is this just a bug that no corrected since asyncore
was written?
Is there any other way to work around this?
Not a workaround for
sock.connect
but can be used to catchsocket.error
exception: