5

So we want a Play! application which can communicate with a SocketIO (javascript) client.

What I've tried so far:

Using a Play! build in WebSocket and send an exactly same string as the node.js server did. The result is simply not working. I can see in the chrome frame tab the returning message, but while the message from the nodejs server triggers the onEvent handler, the java implementation never does that.

Using/porting the socket.io.play project. The result was the same as the Play! websocket version, the server gets the message, responds, but the message doesn't trigger the javascript eventhandler.

The third java implementation is the netty-socketio. I haven't tried it yet, but the main concept is problematic when I need to start it on another port instead of using the server port and the build in routing.

Java and scala versions are both welcomed, I can use both.

So my questions:

  • Is there any working Play (>=2.3.0) application with SocketIO (>=v1.0)?
  • What could be a problem in the build-in WebSocket implementation of the Play! ? How can I use it for the SocketIO protocol?
  • Can I take a netty based webapp inside my Play! application without using a new routing mechanism or new ports?
  • Is there ANY reference implementation with a more typed or formal language then javascript?

Play Java controller return type example:

public class WebSocketWithCallBack extends WebSocket<String> {
    private static List<Out<String>> globalOutList = new ArrayList<>();
    @Override
    public void onReady(In<String> in, final Out<String> out) {
        //Adding the output to the room
        globalOutList.add(out);
        System.out.println("adding output, " + globalOutList.size());
        // For each event received on the socket,
        in.onMessage(new F.Callback<String>() {
            public void invoke(String event) {
                //send event to all outputs
                System.out.println("recieved message: ");
                System.out.println(event);
                for(Out<String> outlocal : globalOutList) {
                    outlocal.write("42[\"chat message\",\"asd\"]");
                }
            }
        });
        // When the socket is closed.
        in.onClose(new F.Callback0() {
            public void invoke() {
                //removing the output when closed
                globalOutList.remove(out);
                System.out.println("removing output, " + globalOutList.size());
            }
        });
    }
}
stsatlantis
  • 555
  • 9
  • 26
tg44
  • 810
  • 1
  • 8
  • 21

0 Answers0