使用套接字在nat后面连接一个IP [英] Connect an ip behind nat using sockets

查看:74
本文介绍了使用套接字在nat后面连接一个IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一部电话,它与电话A连接到wifi,地址为动态IP ex:192.168.0.34,并通过port 7567,的服务器套接字监听,如果我有另一种语言,我可以使用任何编程语言以哪种方式连接到该套接字电话B连接到公共IP说10.0.0.56的电话,而我的wifi路由器IP说ex 55.56.89.76?

Consider a phone which is connected to wifi with phones A, address as Dynamic Ip ex:192.168.0.34 and its listening over a server socket at port 7567, In what way can i connect to that socket using any programming language if i have another phone B to connect that which is on public ip say 10.0.0.56 and i have the wifi router ip say ex 55.56.89.76 ?

推荐答案

如果不使用端口转发,则无法直接连接到NAT后面的客户端.但是有一种叫做打孔的技术可以通过NAT打开端口.

It is not possible to connect directly to a client behind a NAT if you don't use port forwarding. But there is a technique called hole punching to open a port thrue a NAT.

来自维基百科:

打孔是一种计算机网络技术,用于在限制性防火墙后的独立组织中的两方之间建立通信.这两个客户端都用于在线游戏,P2P和VoIP等应用程序,它们与不受限制的第三方服务器建立连接,该第三方服务器可以为其找到外部和内部地址信息.由于每个客户端都向服务器发起了请求,因此服务器知道为该会话分配的IP地址和端口号,并且它们彼此共享.具有有效的端口号会使防火墙接受来自每一侧的传入数据包. ICMP打孔,UDP打孔和TCP打孔分别使用Internet控制消息,用户数据报和传输控制协议.使用TCP恶意打孔,可以将压缩的SYN数据包发送到公共ACK路径中.许多软件可以做到这一点.

Hole punching is a computer networking technique for establishing communications between two parties in separate organizations who are both behind restrictive firewalls. Used for applications such as online gaming, P2P and VoIP, both clients establish a connection with an unrestricted third-party server that uncovers external and internal address information for them. Since each client initiated the request to the server, the server knows their IP addresses and port numbers assigned for that session, which it shares one to the other. Having valid port numbers causes the firewalls to accept the incoming packets from each side. ICMP hole punching, UDP hole punching and TCP hole punching respectively use Internet Control Message, User Datagram and Transmission Control Protocols. Using TCP nefarious hole punching, it's possible to send compressed SYN packets through into a common ACK path. Numerous software does this.

另请参阅与本主题相关的问题.

See also the questions related to this topic.

这篇关于使用套接字在nat后面连接一个IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆