Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best java server implementation for socket.io

Tags:

java

socket.io

I wanted to use socket.io to push data from server to browser but the project is java tomcat one, and there are many implementation in Github for the server implementation of socket.io. Most of them say they are deprecated or better ones are available.Can anyone suggest me a good implementation.

And I see lot of demo and sample code about broadcasting with socket.io. My requirement is to push different messages to different clients. Could someone point me to some good demo or tutorial dealing with such stuff?

Thanks

like image 589
Jiby Jose Avatar asked Mar 22 '13 11:03

Jiby Jose


People also ask

Can I use Socket.IO with Java?

IO-client Java. This is the Socket.IO Client Library for Java, which is simply ported from the JavaScript client.

Does Socket.IO need a server?

Socket.io, and WebSockets in general, require an http server for the initial upgrade handshake. So even if you don't supply Socket.io with an http server it will create one for you.

Which is better Socket.IO or WS?

Socket.IO is way more than just a layer above WebSockets, it has different semantics (marks messages with name), and does failovers to different protocols, as well has heartbeating mechanism. More to that attaches ID's to clients on server side, and more. So it is not just a wrapper, it is full-featured library.


3 Answers

As author, I suggest to try my SocketIO server implementation on Java:

https://github.com/mrniko/netty-socketio

Stable and production ready lib.

like image 134
Nikita Koksharov Avatar answered Oct 09 '22 09:10

Nikita Koksharov


We are using in production this one: Socket.IO-Java. We have customize it by our requirements. But in the main case it works good enough.

My colleague shared customized version in github. We are using Jetty 8, there are can be some problem with another servlet containers. Also, we consider using WebSocket only implementation, when XP will not supported by Microsoft.

like image 41
Taky Avatar answered Oct 09 '22 09:10

Taky


You can try this one: https://github.com/codeminders/socket.io-server-java

This implementation is loosely based on old Socket.IO-Java library mentioned in other answers.

It supports Socket.IO 1.0+ clients. The websocket transport is implemented with Jetty 9 but there is no dependency on Jetty for core part of the library. It should not be very difficult to implement websocket transport with Tomcat if needed.

I tried to keep the API similar to Node.JS Socket.IO server API. So, to send a message to specific socket all you need is to call socket.emit()

Here is a small code fragment to be called in your SocketIO servlet:

on(new ConnectionListener() {
        public void onConnect(Socket socket)
        {
            try
            {
                socket.emit("welcome", "Welcome to Socket.IO Chat!");
            }
            catch (SocketIOException e)
            {
                socket.disconnect(true);
            }
       }
}); 
like image 3
Alexander Sova Avatar answered Oct 09 '22 10:10

Alexander Sova