On DroidScript Create HTML APP
<html>
<head>
<script src="file:///android_asset/app.js"></script>
<script src="
https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script>
function OnStart() {
app.ShowPopup( "NODEJS + DROIDScript Rocks!" );
}
</script>
</head>
<body>
<script type="text/javascript">
var socket = io('http://192.168.1.100:3000');
document.documentElement.style.position = "absolute";
document.documentElement.style.top = 0 + "px";
document.documentElement.style.left = 0 + "px";
document.documentElement.style.right = 0 + "px";
document.documentElement.style.bottom = 0 + "px";
document.documentElement.style.margin = 0 + "px " + 0 + "px " + 0 + "px " + 0 + "px";
document.documentElement.style.padding = 0 + "px " + 0 + "px " + 0 + "px " + 0 + "px";
document.documentElement.style.border = 0 + "px solid transparent";
document.body.style.position = "absolute";
document.body.style.top = 0 + "px";
document.body.style.left = 0 + "px";
document.body.style.right = 0 + "px";
document.body.style.bottom = 0 + "px";
document.body.style.margin = 0 + "px " + 0 + "px " + 0 + "px " + 0 + "px";
document.body.style.padding = 0 + "px " + 0 + "px " + 0 + "px " + 0 + "px";
document.body.style.border = 0 + "px solid transparent";
document.body.style.backgroundColor="grey";
document.body.onload = function() { app.Start(); };
var ul = document.createElement('ul');
ul.style.position = "absolute";
ul.style.top = 0 + "px";
ul.style.left = 0 + "px";
ul.style.right = 0 + "px";
ul.style.bottom = 40 + "px";
ul.style.margin = 0 + "px " + 0 + "px " + 0 + "px " + 0 + "px";
ul.style.padding = 0 + "px " + 0 + "px " + 0 + "px " + 0 + "px";
ul.style.borderBottom = 1 + "px solid black";
ul.style.backgroundColor="white";
ul.style.listStyleType = "none";
ul.style.overflowY = "scroll";
ul.id = "messages";
document.body.appendChild(ul);
var input = document.createElement('input');
input.setAttribute("type", "text");
input.style.position = "absolute";
input.style.height = 40 + "px";
input.style.left = 0 + "px";
input.style.width = document.body.clientWidth - 60 + "px";
input.style.bottom = 0 + "px";
input.style.margin = 0 + "px " + 0 + "px " + 0 + "px " + 0 + "px";
input.style.padding = 0 + "px " + 0 + "px " + 0 + "px " + 0 + "px";
input.style.border = 0 + "px solid transparent";
input.addEventListener('keypress', function (e) {
var key = e.which || e.keyCode;
if (key === 13) {
socket.emit('message', input.value);
input.value = '';
}
});
document.body.appendChild(input);
var button = document.createElement('button');
button.style.position = "absolute";
button.style.height = 40 + "px";
button.style.right = 0 + "px";
button.style.width = 60 + "px";
button.style.bottom = 0 + "px";
button.innerText = "SEND";
button.addEventListener('click', function() {
socket.emit('message', input.value);
input.value = '';
});
document.body.appendChild(button);
var num = 0;
var li = [];
document.head.innerHTML += "<style> #messages li:nth-child(odd) { background: #eee; } </style>";
socket.on('message', function(data){
li[num] = document.createElement('li');
li[num].style.padding = 5 + "px " + 10 + "px " + 0 + "px " + 0 + "px";
li[num].innerText = data;
ul.appendChild(li[num]);
num++;
});
window.addEventListener('resize', function() {
input.style.width = document.body.clientWidth - 60 + "px";
}, false);
</script>
</body>
</html>
CREATE FOLDER Name "NodeServer"
SAVE THE SCRIPT BELOW INTO THE FOLDER AS server.js
console.log('listening on *:3000');
io.on('connection', function(socket){
console.log("User Online ("+socket.request.connection.remoteAddress+")\n");
socket.on('message', function(data){
if (data == '') { return false; }
io.emit('message', data);
});
socket.on('disconnect', function(socket){
console.log("User OffLine ("+socket.request.connection.remoteAddress+")\n");
});
});
open node console, cd into NodeServer
npm init
nodejs server.js TO START SERVER
make sure u using npm command "node package manager"