我有以下代码(聊天服务器的例子的几乎精确副本中列出here:扭曲忽略来自MUD客户端的数据?
进口twisted.scripts.twistd 从twisted.protocols导入从twisted.internet进口协议,从扭曲反应器 基本 。申请进口服务,互联网
class MyChat(basic.LineReceiver):
def connectionMade(self):
print "Got new client!"
self.factory.clients.append(self)
def connectionLost(self, reason):
print "Lost a client!"
self.factory.clients.remove(self)
def lineReceived(self, line):
print "received", repr(line)
for c in self.factory.clients:
c.message(line)
def message(self, message):
self.transport.write(message + '\n')
factory = protocol.ServerFactory()
factory.protocol = MyChat
factory.clients = []
if __name__ == "__main__":
print "Building reactor...."
reactor.listenTCP(50000, factory)
print "Running ractor...."
reactor.run()
else:
application = service.Application("chatserver")
internet.TCPServer(50000, factory).setServiceParent(application)
服务器无错误运行,如果我通过Telnet连接到它,我可以发送数据和服务器打印到控制台,继到所有客户端(如预期)。但是,如果我通过不同的工具(MUD客户端)连接到它,它永远不会获取数据。我已经确保客户端正在发送数据(用Wireshark跟踪数据包,他们正在通过线路),但服务器要么永远不会收到它,要么因为某种原因选择忽略它。
我试过这个有两个MUD客户端gmud和JMC。如果它很重要,我正在运行Windows 7 x64。
有没有人知道为什么会发生这种情况?
谢谢,
麦克
编辑:
由于由Maiku Mori提供的提示,我尝试添加这是在Twisted API Docs,dataReceived指定另一种方法。一旦添加完成,MUD客户端可以很好地工作,但Telnet现在正在将每个字符都发送给自己的一组数据,而不是等待用户按Enter。
这里是新代码的文档片断:
def dataReceived(self, data):
print "Dreceived", repr(data)
for c in self.factory.clients:
c.message(data)
# def lineReceived(self, line):
# print "received", repr(line)
# for c in self.factory.clients:
# c.message(line)
有没有人经历了这一点,如果是的话,你怎么围绕它得到什么?理想情况下,我希望Telnet 和 MUD客户端可以使用此应用程序。
再次感谢。
啊,我以为你检查wireshark和MUD客户端使用暂停或别的东西作为分隔符。那么这是一个干净的解决方案:D – 2009-12-14 01:33:53
基本上,您不能对客户端是否发送\ n,\ r,\ n \ r或\ r \ n做任何假设。就我个人而言,我不会尝试弯曲LineReceiver来处理Telnet(尤其是不是MUD流量),因为它基本上不是基于行的协议,特别是当您考虑IAC序列,ANSI颜色等时。 – Kylotan 2009-12-14 10:15:45
那么您会建议使用什么Twisted组件? – 2009-12-14 14:09:14