문제

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 :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top