my code on android is
document.addEventListener('deviceready', function(){
var wsserver = cordova.plugins.wsserver;
wsserver.start(8082, {
'onFailure' : function(addr, port, reason) {
alert("onFailure");
console.log('Stopped listening on %s:%d. Reason: %s', addr, port, reason);
},
// WebSocket Connection handlers
'onOpen' : function(conn) {
alert("onOpen");
console.log('A user connected from %s', conn.remoteAddr);
},
'onMessage' : function(conn, msg) {
alert(["onMessage",msg]);
console.log([conn, msg]);
},
'onClose' : function(conn, code, reason, wasClean) {
alert("onClose");
console.log('A user disconnected from %s', conn.remoteAddr);
},
// Other options
'origins' : [ 'file://',"http://","*"], // validates the 'Origin' HTTP Header.
'protocols' : [ ], // 'my-protocol-v1', 'my-protocol-v2' validates the 'Sec-WebSocket-Protocol' HTTP Header.
'tcpNoDelay' : true // disables Nagle's algorithm.
}, function onStart(addr, port) {
alert(["onStart",addr, port]);
console.log('Listening on %s:%d', addr, port);
}, function onDidNotStart(reason) {
alert("onDidNotStart");
console.log('Did not start. Reason: %s', reason);
});
}, false);
my client code run on windows10 x64
<!DOCTYPE html>
websocket
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````
the websocket server listen port is 8082
ip address is 192.168.1.100
I ping the phone's ip 192.168.1.100 is connect ok!
I use telnet 192.168.1.100 8082 is connect ok;
I use nodejs tcp client code tcp.js is connect ok!
var net=require("net");
var Client = net.createConnection({host:"192.168.1.100",port:8082}, function(){
console.log("connect ok");
});
android 4.3 is root
my client code run on windows10 x64
<!DOCTYPE html>
````````````````````````````````````````````````````````````````````````````````````````````````````````````````` the websocket server listen port is 8082 ip address is 192.168.1.100
I ping the phone's ip 192.168.1.100 is connect ok! I use telnet 192.168.1.100 8082 is connect ok; I use nodejs tcp client code tcp.js is connect ok!
var net=require("net"); var Client = net.createConnection({host:"192.168.1.100",port:8082}, function(){ console.log("connect ok"); });
Client.on('data', function(buf){ console.log("data:"+data.toString()); });
Client.on('end', function(){ console.log("end"); });
but i use the html+js page,I can not connect ,why?