2015-11-02 42 views
2

我目前正在使用python進行扭曲工作,我試圖在許多對等體之間進行多播(他們每個人都可以發送和接收消息,發送消息等)。我主要如下所示:Twisted multiple peers

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 IM開始從CMD(如PY example.py第一個與serial_process_num 0 0),那麼1和2.Am我正確設置了listeners/connecttcp?每當我在這三個人之間發送消息時,我在每個同伴中只收到一半消息。 (我使用self.transport.write(「示例」)

是否有通過在TCPconnect扭曲多播的替代方法?(IM以下krondos教程)和我怎樣才能使多個對等體之間的多個連接用扭曲?

+1

你可以從https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/broadcast/server.py得到一個想法Twisted + Autobahn WebSocket + broadcast received message給所有連接的同行。 –

+0

謝謝我想通了 – user1823812

回答

1

多播是一個datagram protocol,這意味着你沒有像使用TCP一樣的方式創建字節流;換句話說,它是一種UDP。所以不,你不能使用TCP,在Twisted或其他

+0

那麼,它不是一個真正的組播,然後我想讓每個對等體(通過它們之間的連接)相互通信。但我似乎無法正確建立他們的連接。 – user1823812