在我之前的一个问题中,我得到了这个答案:
子类
twisted.conch.recvline.HistoricRecvLine
而不是twisted.protocols.basic.LineReceiver
。keystrokeReceived
是使用终端而不是TCP连接时可用的几个附加协议回调之一。 - Jean-Paul Calderone
但是如果有终端和TCP连接怎么办?当我继承HistoricRecvLine
时,我失去了TCP连接的功能?所以让我们从头开始吧。我的.py
文件是:
class WebCheckerCommandProtocol(basic.LineReceiver):
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 arguments"
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
stdio.StandardIO(SimpleServer())
reactor.listenTCP(1234, factory)
reactor.run()
如何启用命令历史记录?我如何结合你建议我实现我想要的一切?
显然我错过了什么!