简体   繁体   中英

How to share socket connection sessions in java servers

If you are familiar with XMPP servers , then you must know openfire. im planning to write a JSON version of the openfire (imo xml is outdated and json is alot faster,and openfire is slower than its mate, Tigase, but they both have issues), but the only part that i'm stuck at is, when clustering (for example using HazzelCast) and a contact sends a message to an instance of server, but the target is on another instance, then i either need to have the connection shared or i should use a sort of memory based queue to send the packet to the target.

I tried to read the openfire source but it was too complicated , so i decided to share my question here:

How can serveral clustered servers use a single TCP connetion to send packet?

I'm going to use netty for a network framework.

A TCP connection it's an abstraction of two pairs of IP_ADDR + PORT, one belonging to the server and the other to the client (more precisely, it's the pair of channels associated with the endpoint). Given this premise, you cannot have a TCP connection shared amongst servers having different ip addresses.

In Java 9 SO_REUSEPORT will be supported and you will be able to have multiple server sockets sharing the same pair IP_ADDR + PORT. As far as I know Netty already does that for you.

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