简体   繁体   中英

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.

Public Server B has public IP.

Public Server B will need to send messages to private server A consequently upon business requirements.

I am wonder whether there is any Java solution for this kind of communication?

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. Then keep the connection long alive, then public server B can send data back to server A.

This scenario is similar but not exactly the same as UDP hole punching. Since I am new to Java, I am wondering whether there is any existing Java lib for such case?

The restrictions are:

  1. We are not allowed to configure the NAT network, which means port forwarding are not applicable.

  2. There will be many NATs. Inside each NAT there will be a server(Or a cluster) communicating to the public server. So websocket solution may not a best solution as it will keep the public server maintaining many connections in memory.

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. This obviously introduces latency; server A is disconnected for most of the period and only receives updates after it connects.

I would be surprised if you have so many servers that you cannot keep a socket connection open.

Java is a side issue. Any kind of socket or websocket you would open in Java has direct analogues in other languages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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