如何让 TCP 服务器在路由器 (NAT) 后面工作而不需要任何重定向配置 [英] How do I make a TCP server work behind a router (NAT) without any redirection configuration needed

查看:24
本文介绍了如何让 TCP 服务器在路由器 (NAT) 后面工作而不需要任何重定向配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景如下.我有两台机器 A 和 B:A:客户端(在 NAT 后面)B: 服务器(在 NAT 后面)

The scenario is the following. I have two machines A and B: A: Client (behind NAT) B: Server (behind NAT)

我希望 B 能够侦听任何给定端口,以便 A 可以通过该特定 TCP 端口向 B 发送数据包并接收任何响应.如果两台机器都不在 NAT 后面,那么这是一个非常直接的过程.但是,我如何使其工作,以便即使 B 在路由器后面也能工作,而无需他更改路由器配置,启用某些端口转发等...

I want B to be able to listen on any given port, so that A can send packets to B through that specific TCP port and receive any response. If both machines are not behind a NAT it is pretty straight foward process. However how do I make it work so that it works even when B is behind a router, without him having to go change the router configuration enable some port forwarding etc...

例如,在用户无需进行任何配置的情况下,像 Torrent 客户端这样的点对点程序如何工作?

For example, how do peer-to-peer programs like torrent clients work without the user having anything to configure?

推荐答案

代理服务器的替代方案是匹配服务器.不是代理所有流量,Match maker 只是协商直到对等方可以相互交谈.这涉及找到对等方的外部公共 IP 并与每个人交谈,以便防火墙/路由器知道对等方希望进行通信.

An alternative to a proxy server is a match-making server. Instead of proxying all of the traffic, the match maker just negotiates until the peers can talk to each other. This involves finding the external public IPs of the peers and talking to each one so that the firewall/router knows that the peers wish to communicate.

这称为打洞,通常必须由媒人完成,而不是比同龄人本身.不过,一旦破了洞,媒人就可以告诉同伴彼此的情况,他们可以直接交流.

This is called hole punching and it often has to be done by the match maker rather than the peers themselves. Once the hole are punched though, the match maker can tell the peers about each other and they can communicate directly.

这篇关于如何让 TCP 服务器在路由器 (NAT) 后面工作而不需要任何重定向配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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