51

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

Taky
  • 5,284
  • 1
  • 20
  • 29
Jiby Jose
  • 3,745
  • 4
  • 24
  • 32
  • As far as just looking for a java implementation of socket-io there are many,but their support for many containers is not good.SO the choice i took was to go with atmosphere,It gives you the option to use socket io as the lirary or theirs and some others and it does support most of the containers out there.It seems to be an actively developed project and i would recommend it to anyone in the same situation of doing comet in java – Jiby Jose Apr 14 '13 at 16:35
  • possible duplicate of [how to implement Socket.io on Tomcat 7](http://stackoverflow.com/questions/12299194/how-to-implement-socket-io-on-tomcat-7) – Steve Chambers May 08 '14 at 12:17

3 Answers3

54

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

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

Stable and production ready lib.

Nikita Koksharov
  • 10,283
  • 1
  • 62
  • 71
  • 1
    Netty-socketio creates its own server or I can use it inside a Tomcat application, for example? – Daniel T. Sobrosa Oct 28 '15 at 19:14
  • 1
    @NikitaKoksharov Hi, is there any formal documentation for netty-socketio that I could use as a reference while building my software around it? – Sajib Acharya Apr 14 '16 at 15:18
  • 1
    Nikita thanks for the lib, took few minutes to get everything working for me, i wish more people know how to design stuff like you... – vach Aug 01 '16 at 08:22
  • Have you used the Atmosphere Framework. How does it compare? – Alexander Suraphel Apr 19 '17 at 08:35
  • @NikitaKoksharov Can I use the netty-socketio framework EndPoint based implementation. – sprabhakaran May 13 '19 at 03:55
  • @SajibAcharya you can check out this demo https://github.com/mrniko/netty-socketio-demo –  May 31 '20 at 03:13
  • After a POC I am thinking to use it in our product with tomcat 8. But the GitHub repo last commit was on 29 September 2020. Is the repo still active and maintained – Amogh Nov 25 '20 at 07:33
  • @NikitaKoksharov it's really interesting implementation, but I can't found supporting v3 and v4 socket.io clients. Is it possible to add support v4? – Oleg Kovalyk Oct 20 '22 at 14:35
6

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.

Taky
  • 5,284
  • 1
  • 20
  • 29
  • Hey thanks for the answer i did check many of these java backends.But most of them were specific to some container like the one you pointed out was for jetty.SO i took the choice to go with atmosphere – Jiby Jose Apr 14 '13 at 16:36
  • 2
    Link is dead. Could you share your customized version somewhere? (github maybe) The project's documentation says it's abandoned and your changes might be what it was missing :) – naugtur Apr 19 '13 at 10:56
  • 2
    @naugtur I have added link to repo – Taky Apr 19 '13 at 12:08
3

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);
            }
       }
});