JAVA push from server to clients

I would like clients to immediately request each other through the server (= no polling interval).

Example: Server S, Clients A and B

Client A wants to request client B. Client A sends a request to server S, no problem. Then server S should be able to request client B, but how to do it without polling?

All node.js / APE technologies (for PHP) are designed for the Internet, however, I do not use a web server for this. Does Java have something close to push / framework technology that is not a web server?

I would prefer a solution that does not require each client to use its own reserved port (I do not want to ultimately use 1 WebService for each client)

Note: all clients are on the same machine.

+4
source share
3 answers

Several variants...

  • Simple socket communication. java.net.Socket, java.net.ServerSocket. Maximum flexibility, but requires knowledge of low-level TCP / IP APIs / concepts.

  • Good old RMI. Java based RPC layer on top of TCP / IP. It works well when the client and server are in Java and generally on the same subnet. A problem may occur when the client and / or server are natted.

  • Spring Remoting, it's actually pretty decent.

  • Bidirectional web services. that is, clients host their own WSes, which the Server calls when it needs to make a callback.

  • JMS, as mentioned.

  • Distributed data structures, check out http://www.hazelcast.com/

Lots of options to choose from, no web server needed.

+5
source

If you really do not want to use a web server, I would take a look at JMS . That being said, all the cool kids use web servers these days, because protocols are so ubiquitous.

+3
source

In your use case, a messaging protocol is required. We do not know the extent of your problem, but you already said that you want the server to exchange requests between clients, so I would go with the existing solution, and not using my own approach.

JMS is mentioned and certainly a viable Java based solution, the other is XMPP , which is a widely used real-time instant messaging protocol.

This is an open standard that supports both the server and the client in all major languages ​​and platforms. This will allow you to have standalone apps, web apps, and mobile apps that can communicate with each other. The only potential access for your use case is that it is text based. Since you did not say what requests you want to transfer back and forth, I don’t know if this will fit your bill or not.

You can use Smack for client-side development in Java and any OS server you want.

0
source

Source: https://habr.com/ru/post/1403758/


All Articles