How to contact Node.js server from Android client

I am working on a small project where I need to communicate with the node.js server (it has rest services) from the android client ... I referred to this link Combining java and nodejs for an Android application ... is there any way I can Communicate instead of web sockets.

+8
android
source share
4 answers

Check out http://www.mkyong.com/webservices/jax-rs/restfull-java-client-with-java-net-url/ , it includes a simple server example, but I think the client code should be for you useful.

There is also this SO question, which should have more useful information for you.

+10
source share

it has been a long time with OP posts, but for those who can see it, this is a tutorial that I did to communicate your Android with the Node.js server:

(without additional library)

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

This is a foretaste of what 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(); 
+6
source share

If you are creating WebApp, Socket.io is useful .

+2
source share

I used the Gottox API on Android to connect to Node.js + Socket.IO without any problems.

I also tried android-websockets before, but had some problems ( see this question ) that are probably already resolved. Give it a try.

+2
source share

All Articles