Node.js web server on Android with jxcore
Pre-requisite:
- Android device with adb/usb access (rooted phone)rooted phone allow full privileges to change perms and other, though it may be possible to execute as non-root, i have not explored this.
Procedure:
1. Download jxcore for Android from http://jxcore.com/downloads/ to your desktopchoose jxcore binary according to your platform of choice
2. push the jx binary from desktop to your phone using adb
eg., adb push <location to jx on your desktop> /data/local/jx
3. from the adb shell provide necessary execute permission for jx executable.
4. write a node.js webserver code either on your desktop and push it to the device OR
write code on the device directly with your favorite editor like nano or even cat
cat > mywebsrv.js
var http = require("http");
http.createServer(function(req, res) {
res.write(" Hello from Android server");
res.end();
}).listen(9090);
console.log(" web server listening on port 9090 on device ");
web server listening on port 9090 on device
root@host:/data/sdcard # ./jx websrv.js
./jx websrv.js
web server listening on port 9090 on device
6. Assuming that your device wifi is connected to your network router, same as your laptop so they are reachable on the network. To find your device IPAddr, either get it from router's admin console
OR using ifconfig from the device, sometimes the default ifconfig shall not print details, so get a busybox (www.busybox.net) for android and use its ifconfig.
Now you can open your browser to reach the device's IP/port:9090 to see message "Hello from Android server"
No comments:
Post a Comment