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.
You can check the socket. connected property: var socket = io. connect(); console.
socket-io. client is the code for the client-side implementation of socket.io. That code may be used either by a browser client or by a server process that is initiating a socket.io connection to some other server (thus playing the client-side role in a socket.io connection).
Socket.IO is a library that enables real-time, bidirectional and event-based communication between the browser and the server. It consists of: a Node. js server: Source | API. a Javascript client library for the browser (which can be also run from Node.
Manager manager = new Manager(new URI("http://socket.com"));
Socket socket = manager.socket("/my-namespace");
socket.connect();
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With