扭曲的多个同伴

时间:2015-11-02 16:36:48

标签: python tcp twisted multicast

我目前正在使用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个peer.I从cmd开始第一个带有serial_process_num 0(ex py example.py 0),然后是1和2.Am我正确设置了listeners / connecttcp?每当我在这3个人之间发送消息时,我只会在每个同伴中收到一半消息。 (我使用self.transport.write('示例')

是否存在通过TCPconnect进行多播的替代方式?(即时关注krondos教程)如何在多个对等方之间建立多个连接?

1 个答案:

答案 0 :(得分:1)

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