简体   繁体   English

P2P通信不起作用

[英]P2P communication is not working Java

What I am trying to do is, send data from my PC(local IP) to another PC(private IP) in internet. 我想要做的是,将数据从我的PC(本地IP)发送到互联网上的另一台PC(私有IP)。 I wrote a java program to send/receive messages with stun resolver. 我写了一个java程序来发送/接收带有眩晕解析器的消息。

Program: 程序:

Resolve stun and get public IP and port
Send message with same socket(resolve stun) to another program.
Receiving with same socket(resolve stun) in different thread.

We are sending data to each other's public IP/port resolved by stun. 我们正在通过stun解析彼此的公共IP /端口的数据。 I'm not sure about other end but my network has Port restricted clone NAT . 我不确定其他目的,但我的网络有Port restricted clone NAT Am I doing any wrong?? 我做错了吗?

Note: NAT is tested. 注意: NAT已经过测试。 I communicated with a server and a local mobile device with stun resolve. 我通过昏迷的决心与服务器和本地移动设备进行了沟通。

Edit 编辑

I don't have any firewall. 我没有防火墙。 I also stopped ufw service. 我也停止了ufw服务。

System: 系统:

Ubuntu 14.04
Mac 10.10.3

Short summary: After discovering your STUN ip/port for your socket, you need to send a 1 byte "hole punching packet" to the remote endpoint's IP and port. 简短摘要:在发现套接字的STUN ip / port之后,需要向远程端点的IP和端口发送一个1字节的“打孔数据包”。 This will allow incoming traffic from that address. 这将允许来自该地址的传入流量。 The other side should do the same thing. 另一方应该做同样的事情。

Long answer: My previous write-up on P2P socket programming here. 答案很长:我以前在这里写了关于P2P套接字编程的文章。

You need to punch a hole in both side's NAT for the NATs to allow the incoming packets. 您需要在两侧的NAT中为NAT打一个洞以允许传入的数据包。 You should punch hole with low ttl value. 你应该用低ttl值打洞。 So that the packet you send for hole punching doesn't reach other side NAT. 因此,您发送的用于打孔的数据包不会到达其他端NAT。 If it does than all the packet after that from your ip to that NAT may be blocked. 如果它确实比你之后所有的数据包从你的IP到NAT可能被阻止。 Not all NATs are configured like this. 并非所有NAT都配置如下。 This could be a reason for you both not receiving anything. 这可能是你们两个都没有收到任何东西的原因。

There could be another reason. 可能还有另一个原因。 Your other NAT could be a symmetric NAT. 您的其他NAT可能是对称NAT。 In this case you will need a TURN server to establish connectivity. 在这种情况下,您将需要TURN服务器来建立连接。

Also you do not need to punch hole if other side's NAT is Full Cone. 如果其他方的NAT是Full Cone,您也不需要打孔。 So you really need to know the other side's NAT type to find your problem. 所以你真的需要知道对方的NAT类型来找到你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM