pyp2p 库 - 如何使用 pyp2p 库进行点对点通信

发布于 2025-01-10 19:54:13 字数 851 浏览 7 评论 0原文

谁能告诉我如何使用 pyp2p 库进行点对点通信。或者是否有其他方法可以连接到位于 2 个不同 NAT 后面的 2 台不同计算机

Alice Node

from pyp2p.net import *
import time

#Setup Alice's p2p node.
alice = Net(passive_bind="192.168.0.45", passive_port=44444, interface="eth0:2", node_type="passive", debug=1)
alice.start()
alice.bootstrap()
alice.advertise()

#Event loop.
while 1:
    for con in alice:
        for reply in con:
            print(reply)

    time.sleep(1)

我必须在 Passive_bind、passive_port 和接口下输入什么,才能在位于 2 个不同 NAT 后面的两个节点之间建立连接

Bob Node

from pyp2p.net import *

#Setup Bob's p2p node.
bob = Net(passive_bind="192.168.0.44", passive_port=44445, interface="eth0:1", node_type="passive", debug=1)
bob.start()
bob.bootstrap()
bob.advertise()

#Event loop.
while 1:
    for con in bob:
        con.send_line("test")

    time.sleep(1)

Can anyone please tell me how to use the pyp2p library for peer to peer communication. Or is there any other way to connect to 2 different computers which are behind 2 different NATs

Alice Node

from pyp2p.net import *
import time

#Setup Alice's p2p node.
alice = Net(passive_bind="192.168.0.45", passive_port=44444, interface="eth0:2", node_type="passive", debug=1)
alice.start()
alice.bootstrap()
alice.advertise()

#Event loop.
while 1:
    for con in alice:
        for reply in con:
            print(reply)

    time.sleep(1)

What must I enter under passive_bind, passive_port and interface to establish connection between the two nodes which are behind 2 different NATs

Bob Node

from pyp2p.net import *

#Setup Bob's p2p node.
bob = Net(passive_bind="192.168.0.44", passive_port=44445, interface="eth0:1", node_type="passive", debug=1)
bob.start()
bob.bootstrap()
bob.advertise()

#Event loop.
while 1:
    for con in bob:
        con.send_line("test")

    time.sleep(1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文