Question

I'm using RoboSpice + Spring Android for developing a chat application in Android. How to integrate socket.io connection in RoboSpice? so that i can maintain socket connections between activities.

Socket io code

              try {
        socket = new SocketIO("http://server.com");
    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
         }
            socket.connect(new IOCallback() {
            @Override
            public void onMessage(JSONObject json, IOAcknowledge ack) {
                try {
                    System.out.println("Server said:" + json.toString(2));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onMessage(String data, IOAcknowledge ack) {
                System.out.println("Server said: " + data);
            }

            @Override
            public void onError(SocketIOException socketIOException) {
                System.out.println("an Error occured");
                socketIOException.printStackTrace();
            }

            @Override
            public void onDisconnect() {
                System.out.println("Connection terminated.");
            }

            @Override
            public void onConnect() {
                System.out.println("Connection established");
            }

            @Override
            public void on(String event, IOAcknowledge ack, Object... args) {
                System.out.println("Server triggered event '" + event + "'");
                System.out.println("Message : '" + args[0] + "'");
            }
        });
Était-ce utile?

La solution

In RoboSpice, networking is managed at the Request level. Hence, your request should use the socket io lib.

Socket IO is not provided as a module of RoboSpice. I didn't even know it before seeing your question. What exactly would you expect from RoboSpice when using Socket IO ?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top