If you can upgrade to or are using JDK 7 I suggest using Vert.x Vertx.io , use Sockjs on the client side. Vert.x has a complete sockjs server implementation, I ll try to suggest a way to implement this, for the rest please look at the Docs
The server implementation could be like this
Vertx vertx = Vertx.newVertx();
EventBus eventBus = vertx.eventBus()
HttpServer server = vertx.createHttpServer();
JsonArray permitted = new JsonArray();
permitted.add(new JsonObject());
SockJSServer sockJSServer = new DefaultSockJSServer(vertx, server);
sockJSServer.bridge(new JsonObject().putString("prefix", "/pusher"), permitted, permitted);
server.listen(<some port>);
On the client side register a handler like so on document load
function () {
if (!eb) {
eb = new vertx.EventBus("http://<your_host>:<your_port>/pusher");
eb.onopen = function() {
console.log("connected")
};
eb.onclose = function() {
console.log("Not connected");
eb = null;
};
}
}
You can then register a handler to any address - address here can be anything , assume it is "AwesomeNotifications"
function subscribe(address) {
if (eb) {
eb.registerHandler(address, function(msg, replyTo) {
console.log("Reply recieved")
});
}
}
Once you have this all set up , you can now push any data from the server to this address using the event bus we created earlier
eventBus.publish("AwesomeNotifications", new JsonObject(<some hashmap to serialize>))
Hope this helps