代码之家  ›  专栏  ›  技术社区  ›  Mike Trpcic

是否忽略从MUD客户端发送的数据?

  •  2
  • Mike Trpcic  · 技术社区  · 15 年前

    here :

    导入twisted.scripts.twistd 从twisted.com导入基本协议 来自twisted.internet导入协议,reactor

    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跟踪数据包,并且数据包正在穿越网络),但服务器要么从未接收到数据包,要么出于某种原因选择忽略数据包。

    gmud ,及 JMC . 如果这很重要,我正在运行Windows7x64。

    有人知道为什么会这样吗?

    谢谢

    迈克

    Maiku Mori ,我尝试添加在 Twisted API Docs

    以下是新代码的剪贴:

        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

    再次感谢。

    2 回复  |  直到 8 年前
        1
  •  3
  •   Mike Trpcic    15 年前

    如果有人偶然发现这个问题有类似的问题,我将把我的发现作为公认的答案,这样人们就不必像我那样去寻找了。

    Hello, World
    

    您的申请将通过以下方式接收:

    Hello, World\r
    

    导入twisted.scripts.twistd 从twisted.com导入基本协议 从twisted.application导入服务,internet

    class MyChat(basic.LineReceiver):
        def __init__(self):
            self.delimiter = "\n"
    
        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)
    

    谢谢你的帮助。

        2
  •  1
  •   Maiku Mori    15 年前

    收到的电话

    编辑:

    LineReceiver . 你可以和我一起玩 dataReceived 收到的电话 .