JAVA push from server to clients

2019-01-14 09:49发布

I would like to have the clients query each other through the server without delay ( = no polling interval ).

Example: Server S, clients A and B

Client A wants to request Client B. Client A will make a request to the server S, no problem there. Then Server S needs to be able to request Client B but how to do that without polling?

All the node.js/APE (for PHP) technos are designed for the web, however I don't use a web server for that. Does Java has something close to a push technology/framework that is not web?

I would really prefer a solution that doesn't require each client to use their own reserved port (I don't want to end up with 1 WebService per client for example)

Note: all the clients are on the same machine.

3条回答
Summer. ? 凉城
2楼-- · 2019-01-14 10:23

If you really don't want to use a web server then I would check out JMS. That being said, all the cool kids are using web servers these days since the protocols are so ubiquitous.

查看更多
贼婆χ
3楼-- · 2019-01-14 10:40

Your use case requires a messaging protocol. We don't really know the scope of your problem but you already said you want a server to exchange requests between clients, so I would go with an existing solution rather than a roll your own approach.

JMS has been mentioned and is certainly a viable Java based solution, another would be XMPP which is a real time communication protocol commonly used for instant messaging.

It is an open standard that has both server and client support in every major language and platform. This would allow you to have standalone apps, web based ones and apps for mobile devices all being able to communicate with each other. The only potential gotcha for your use case is that it is text based. Since you haven't said what requests you want to pass 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.

查看更多
看我几分像从前
4楼-- · 2019-01-14 10:46

A couple of options...

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

  • The good old RMI. Java based RPC layer on top of TCP/IP. Works good when client and server are both in Java and generally in same subnet. May give problems when client and/or server are natted.

  • Spring Remoting, it's actually pretty decent.

  • Bi-Directional Web Services. i.e. clients host their own WSes which the Server calls when it needs to do a callback.

  • JMS as someone already mentioned.

  • Distributed Data Structures, Check out http://www.hazelcast.com/

Lots of options to chose from, no need for webserver.

查看更多
登录 后发表回答