I made this basic client to accommodate myself with asyncore.
import asyncore, socket
class TestClient(asyncore.dispatcher):
def __init__(self, host, port):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, port))
self.buffer = "madonna"
def handle_connect(self):
pass
def handle_close(self):
print "Close"
self.close()
def handle_read(self):
print self.recv(8192)
def writable(self):
print "Calling writable"
return (len(self.buffer) > 0)
def handle_write(self):
print "Write"
sent = self.send(self.buffer)
self.buffer = self.buffer[sent:]
client = TestClient("127.0.0.1", 7899)
asyncore.loop()
I think I am not doing something right. I can connect to the server but it doesn't send any data. Because the buffer
is not empty, shouldn't Writable be called to check the buffer and if is not empty call handle_write
?
Besides the __init__
method, nothing gets called.
You should re-indent your methods :)