简体   繁体   中英

Java - receiving notifications using TCP Sockets

Is there a good way to create receiving notification to Client using TCP Socket (without Pushes)?

It's accepted to send a request and receive an answer from server. But if I need to receive some messages from server in any time without sending any request (only in the beginning for connecting)? Like in messengers.

I think it's not ok to send a request to the server every 5 secs (for example) to get an answer.

The correct way to do that is to listen to websocket channels. I personally used WebSocket Rails-Android because our server is written on rails, but you can easily find a library that fits your need.

In the library above you can also find a simple and clear explanation of how the listening thing works.

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