扭曲的多个同行

Twisted multiple peers

我目前正在 python 中使用 twisted,我正在尝试在多个对等点之间进行多播(每个对等点都可以发送和接收消息、发送确认等)。我的主图是这样的:

if __name__ == '__main__':
    serial_process_num, address = parse_args()

    if serial_process_num == '0':
        factory = PeerFactory('0', 'log')
        reactor.listenTCP(address[1], factory)
        reactor.listenTCP(address[1]+1, factory)

        print "Process 0 is listening @" + address[0] + " port " + str(address[1])
        print "Process 0 is listening @" + address[0] + " port " + str(address[1]+1)
    elif serial_process_num == '1':
        factory = PeerFactory('1', '')
        host, port = address
        print "Connecting to process 0 " + host + " port " + str(port)
        reactor.connectTCP(host, port, factory)
        print "Process 1 is listening @" + address[0] + " port " + str(address[1]+2)
        reactor.listenTCP(port+2, factory)
    else:
        factory = PeerFactory('2', '')
        host, port = address
        print "Connecting to process 0 " + host + " port " + str(port+1)
        reactor.connectTCP(host, port+1, factory)
        print "Connecting to process 1 " + host + " port " + str(port+2)
        reactor.connectTCP(host, port+2, factory)


    reactor.run()

我保持这个简单,因为我想了解我的错误,所以我只使用 3 peers.I 从 cmd 开始第一个 serial_process_num 0(ex py example.py 0), 那么 1 和 2.Am 我设置 listeners/connecttcp 正确吗?每当我在这 3 个之间发送消息时,我只收到每个对等方的一半。 (我使用 self.transport.write('example')

是否有另一种方法通过 twisted 中的 TCPconnect 进行多播?(我正在遵循 krondos 教程)以及如何使用 twisted 在多个对等点之间建立多个连接?

多播是一个datagram protocol,这意味着您没有像使用TCP 那样的字节流;换句话说,它是一种 UDP。所以不,你不能在 Twisted 或其他情况下使用 TCP。