5

I can connect to socket.io web service no problem using this library https://github.com/nkzawa/socket.io-client.java . I cannot quite figure out how to connect to a specific namespace though. I have looked through the test code and think I might need to create a Manager class.

Any help would be appreciated. Thank you very much.

patrick_corrigan
  • 809
  • 11
  • 24

2 Answers2

22
Manager manager = new Manager(new URI("http://socket.com"));
Socket socket = manager.socket("/my-namespace");
socket.connect();
patrick_corrigan
  • 809
  • 11
  • 24
1

The above answer is not working for me.

Actually this code works, please use latest version of socket.io client version : https://github.com/socketio/socket.io-client-java

Add this in your build.graddle :

compile ('io.socket:socket.io-client:1.0.0') {
    // excluding org.json which is provided by Android
    exclude group: 'org.json', module: 'json'
}

Then you can connect to your namespace with this snippet :

Socket socket;
try {
        socket = IO.socket(socket_host + "/your_namespace");
    } catch (URISyntaxException e) {
        Log.d("ERROR :", e.toString());
    }
socket.connect();

Check this github issue where there are more explanation : https://github.com/nkzawa/socket.io-android-chat/issues/8

Raj
  • 197
  • 1
  • 2
  • 11