Android, iOS and desktop browser clients are currently polling a PHP-backend (utilizing PostgreSQL database on CentOS Linux) every few seconds.
I would like to replace the polling by using standalone Jetty Websocket Server to notify clients, that new data is available for pickup at the backend.
So in the custom WebSocketListener
I authenticate connected clients and store them in a ConcurrentHashMap<String,Session>
:
public class MyListener implements WebSocketListener
{
private Session mSession;
@Override
public void onWebSocketConnect(Session session) {
mSession = session;
}
@Override
public void onWebSocketText(String message) {
if (mSession != null && mSession.isOpen()) {
// 1. validate client id and password
// 2. store client id and session into Map
}
}
My question: How to notify the connected (via websockets) clients?
I.e. in the PHP-scripts I would like to run a lightweight program java -jar MyNotify.jar client-1234
to tell the Jetty standalone server:
Hey, there is new data available for the
client-1234
at the database!Please send it a short message over websockets by calling
MyMap.get("client-1234").getRemote().sendString("hey", null);