简体   繁体   English

公共网络服务器与NAT后的服务器之间的双向通信解决方案

[英]Solution for 2-way communcation between public network server and servers behind NATs

I have below scenario and would like to find a solution for it: 我有以下情况,并希望找到解决方案:

Private Server A is behind NAT, it has no fixed public IP address. 专用服务器A位于NAT之后,它没有固定的公用IP地址。

Public Server B has public IP. 公用服务器B具有公用IP。

Public Server B will need to send messages to private server A consequently upon business requirements. 因此,根据业务需求,公共服务器B将需要向私有服务器A发送消息。

I am wonder whether there is any Java solution for this kind of communication? 我想知道是否有用于此类通信的Java解决方案?

Since private server A has no fixed IP address, it will has to first has a way to tell public server B its IP/Port, etc, or start a connection like websocket first. 由于私有服务器A没有固定的IP地址,因此它首先必须具有一种方法来告知公共服务器B其IP /端口等,或者首先启动类似websocket的连接。 Then keep the connection long alive, then public server B can send data back to server A. 然后使连接保持活动状态,然后公共服务器B可以将数据发送回服务器A。

This scenario is similar but not exactly the same as UDP hole punching. 这种情况与UDP打孔相似但不完全相同。 Since I am new to Java, I am wondering whether there is any existing Java lib for such case? 由于我是Java新手,所以我想知道是否存在针对这种情况的现有Java库?

The restrictions are: 限制是:

  1. We are not allowed to configure the NAT network, which means port forwarding are not applicable. 我们不允许配置NAT网络,这意味着端口转发不适用。

  2. There will be many NATs. 将会有许多NAT。 Inside each NAT there will be a server(Or a cluster) communicating to the public server. 在每个NAT内,将有一个服务器(或群集)与公用服务器通信。 So websocket solution may not a best solution as it will keep the public server maintaining many connections in memory. 因此,websocket解决方案可能不是最佳解决方案,因为它将使公共服务器保持内存中的许多连接。

Thanks 谢谢

The NAT configuration basically forces you to make connections from server A, which is located behind a NAT, to server B. If you do not want to keep a connection open, then server A needs to poll periodically for information, then disconnect. NAT配置基本上会迫使您从位于NAT后面的服务器A到服务器B建立连接。如果您不想保持连接打开,则服务器A需要定期轮询以获取信息,然后断开连接。 This obviously introduces latency; 显然,这会导致延迟。 server A is disconnected for most of the period and only receives updates after it connects. 服务器A在大部分时间内都断开连接,并且仅在连接后才接收更新。

I would be surprised if you have so many servers that you cannot keep a socket connection open. 如果您有如此多的服务器而无法保持套接字连接打开,我会感到惊讶。

Java is a side issue. Java是附带问题。 Any kind of socket or websocket you would open in Java has direct analogues in other languages. 您将用Java打开的任何套接字或websocket都具有其他语言的直接类似物。

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

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