NAT Traversal / HolePunching TPC的Java实现
我一直在浏览和搜索路由器后面的两个客户端的点对点 TCP 连接的实现,但我得到的一切都是“变得更加困惑”!
我的情况“有点简单”,因为我已经知道双方的本地和公共 IP 地址。
因此,此时我不需要使用第三台服务器来发现这些信息。
客户端A:(本地IP =“192.168.0.1”,公共IP =“aaaa”)。
该客户端将侦听端口“pppp”上的连接
serverSocket = new ServerSocket("pppp");
serverSocket.setSoTimeout(timeOut);
socket = ClientA.serverSocket.accept();*
客户端 B:(LocalIP =“10.10.0.1”,PublicIP =“bbbb”)
该客户端将尝试连接到端口“pppp”上的“客户端 A”
SocketAddress sockaddr = new InetSocketAddress("a.a.a.a", "pppp");
socket.connect(sockaddr, timeOut);
当然它行不通,所以鉴于这些信息,如何继续?
I've been browsing and searching for implementation of a Peer-to-Peer TCP Connection with both clients behind routers, but everything I got was "get more confused"!
My case is "a little bit simplest", since I already KNOW the local and public IP addresses from both sides.
So, at this point I just DON'T NEED TO USE THIRD SERVER to discover those informations.
Client A: (LocalIP="192.168.0.1", PublicIP="a.a.a.a").
This client will be Listening to connection on port "pppp"
serverSocket = new ServerSocket("pppp");
serverSocket.setSoTimeout(timeOut);
socket = ClientA.serverSocket.accept();*
Client B: (LocalIP="10.10.0.1", PublicIP="b.b.b.b")
This client will will try to connect to "Client A" on port "pppp"
SocketAddress sockaddr = new InetSocketAddress("a.a.a.a", "pppp");
socket.connect(sockaddr, timeOut);
Of couse it will not work, so given those informations, how to proceed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论