ImMathan
ImMathan

Reputation: 4971

Android Socket client node js server

I am creating an android client using socket not by Socket.io and node js is the server.
I need to know answers for this.

1.It is possible that i have asked?
2.Can socket.io can be implemented as an android client?
3.If socket.io not available, then show how to implement this by socket?
4.If possible then show how to implement?

Upvotes: 3

Views: 2231

Answers (2)

Omar Aflak
Omar Aflak

Reputation: 2962

This is a tutorial I made to make communicate your Android with a Node.js server:

(without any additional library)

https://causeyourestuck.io/2016/04/27/node-js-android-tcpip/

This is a foretaste of how it looks like at the end:

Client socket = new Client("192.168.0.8", 1234);
socket.setOnEventOccurred(new Client.OnEventOccurred() {
    @Override
    public void onMessage(String message) {
    }

    @Override
    public void onConnected(Socket socket) {
        socket.send("Hello World!");
        socket.disconnect();
    }

    @Override
    public void onDisconnected(Socket socket, String message) {
    }
});

socket.connect();

Upvotes: 1

M Omayr
M Omayr

Reputation: 1351

One of the best solutions is to use socket.io-java-client which is fully android supported.

EDIT: If you're using socket.io 1 or later then use nkzawa socket.io-client.java

Upvotes: 4

Related Questions