开发者

Twisted and command line history console application

So I did the following (This app is a client and a server at the same time):

class WebCheckerCommandProtocol(recvline.HistoricRecvLine):

    def connectionMade(self):
        self.sendLine("checker console. Type 'help' for help.")

    def lineReceived(self, line):
        ...

    def connectionLost(self, reason):
        # stop the reactor, only because this is meant to be run in Stdio.
        reactor.stop()

    def do_listservers(self):
        "Cmd to Query all available Servers - Takes no argu开发者_C百科ments"
        conn = httplib.HTTPConnection(ip+":"+port)
        conn.request(.....)
        response = conn.getresponse()
        print response.status, response.reason
        data = response.read()
    def do_sessions(self):
        conn = httplib.HTTPConnection(ip+":"+port)
        conn.request(.....)

    def do_logUser(self, name):
        conn = httplib.HTTPConnection(ip+":"+port)
        conn.request(.....)


class SimpleServer(LineReceiver):

    def connectionMade(self):
        print 'Connection from: ', self.transport.client

    def connectionLost(self, reason):
        print self.transport.client, 'Disconnected'

    def dataReceived(self, line):
        """Here the XML Parser"""
        print line

if __name__ == "__main__":
    factory = Factory()
    factory.protocol = SimpleServer

    runWithProtocol(WebCheckerCommandProtocol)
    reactor.listenTCP(1234, factory)
    reactor.run()

When I run it I see the command line, but nothing else works. I can write commands but they don't seem to work. I see nothing at the console.

What am I doing wrong?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜