dtc66318 2016-11-11 13:56
浏览 381

建立P2P TCP / UDP连接(NAT遍历)

Is there any way to establish true P2P communication through TCP or UDP without an intermediary server? I understand that this is quite doable if the two computers have only public IP addresses but if they are behind any sort of NAT router or on a private network it starts to get tricky.. in fact the more I look into it the more it seems plain not possible. I have discovered STUN, TURN and ICE protocols and hole-punching but as far as I understand they all require some sort of server to at least establish the connection. I am amazed something seemingly so simple seems so hard to do, am I missing something? Ideally I am looking for solutions using Golang any help or examples in C++ would also be useful, thanks.

  • 写回答

1条回答 默认 最新

  • dongyun234854 2016-11-15 23:45
    关注

    This is not strictly a Go question — it's a general networking question.

    The reason this is so difficult is that the Internet was never designed to support NAT, NAT just happened and broke a lot of functionality. The clean solution to your problem is to switch to IPv6, where there is no NAT, but that might not be possible

    If your NAT box supports NAT-PMP or uPNP, you could use that. The simplest way would be to create a cgo binding to libminiupnpc, or you could go fishing for a native Go library.

    If your NAT doesn't support either of these protocols, then you're probably out of luck, as hole punching is a fragile and difficult technique that you will probably find difficult to implement.

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘