Server side push with java

2020-03-08 06:14发布

is it any simpler way then cometd as long-polling framework for java? Because what I need - is client specifies some parameters and sends them to server. Server process them and starts contonuously pushing messages back to client (looks like Thread-per-Service?). Client receivs messages and displays them. Client has possibility to stop listening and actually stop server's service to send messages. Maybe I'm too lazy, but cometd's examle was not that short and transparent as I wanted it to be.

Not HTML5 based.

3条回答
forever°为你锁心
2楼-- · 2020-03-08 06:49

With SSE ( server sent events ) you can do exactly what you explained you want to do, but unfortunately it's HTML5 technology .
If your interested you can check html5rocks for further information.

查看更多
3楼-- · 2020-03-08 07:07

Well if you are too lazy for cometd or reverse AJAX you can deploy a web service endpoint to your client (preferably restful and not SOAP) and have your server send back messages to your web service (acting as a client).

It is simple to implement this.

In your clien't initial request to the server, along with the other parameter, you can also send the port (or URL) that your endpoint is listening for notification.

Then you just have to define the notification events and implement the rest of the logic.

查看更多
闹够了就滚
4楼-- · 2020-03-08 07:14

These guys Atmosphere Asynchronous WebSocket/Comet Framework really made nice job at simplifying the server push process with fallbacks mechanism when browser and/or server parts does not support websockets

查看更多
登录 后发表回答