After i have made my SOCKET.IO server for a multiple room chat application how do i create the android client using https://github.com/socketio/socket.io-client-java ? I have searched a lot and haven`t found up to date examples on the client side of socket.io for android , most of the tutorials and examples are for the server side with node.js.
How to setup an Android Socket.io client?
15.2k views Asked by Olteanu Radu At
2
There are 2 answers
0
On
it has an example chat app implemented in android link below:
https://github.com/nkzawa/socket.io-android-chat
any way, for using socket.io in android, i think best way is using it inside a service something like this:
public class ChatService extends Service {
public void connectSocket() {
try {
IO.Options options = new IO.Options();
socket = IO.socket("http://192.168.1.1:8080", options);
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
}
}).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
}
}).on("error", new Emitter.Listener() {
@Override
public void call(Object... args) {
}
});
socket.connect();
} catch (Exception ignored) {
}
}
@Override
public void onDestroy() {
socket.disconnect();
super.onDestroy();
}
}
public abstract class BaseActivity extends AppCompatActivity {
}