becvert/cordova-plugin-websocket-server

I run the code on a android phone,but no effect?

huge818 opened this issue · 3 comments

android 4.3 is root

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

<title>websocket</title>
<script> var socket = new WebSocket('ws://localhost:8082');
		// 打开Socket 
		socket.onopen = function(event) { 
			console.log(event); 
			socket.send('I am the client and I\'m listening!'); 

			socket.onmessage = function(event) { 
				console.log('Client received a message',event); 
			}; 

			socket.onclose = function(event) { 
				console.log('Client notified socket has closed',event); 
			}; 
		};


	</script>
</body>

`````````````````````````````````````````````````````````````````````````````````````````````````````````````````
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?

var socket = new WebSocket('ws://192.168.1.100:8082'); maybe?

Was this issue solved ?

no update on this?
closing for now