【问题标题】:Twisted multiple peers扭曲多个对等点
【发布时间】:2015-11-02 16:36:48
【问题描述】:

我目前正在使用 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 个对等点。我从 cmd(例如 py example.py 0)开始用 serial_process_num 0 开始第一个,然后是 1 和 2.Am我正确设置了侦听器/connecttcp?每当我在这 3 个之间发送消息时,我在每个对等方中只收到一半。 (我使用 self.transport.write('example')

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

【问题讨论】:

标签: python tcp twisted multicast


【解决方案1】:

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

【讨论】:

  • 嗯,它不是真正的多播,但我想让每个对等点相互通信(通过它们之间的连接)。但我似乎无法正确设置他们的连接。
猜你喜欢
  • 2011-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多