Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Websocket本地ip和公共ip_Javascript - Fatal编程技术网

Javascript Websocket本地ip和公共ip

Javascript Websocket本地ip和公共ip,javascript,Javascript,我有一个webview android应用程序,可以通过重定向连接到本地websocket和公共websocket ip上的服务器,而无需ip提供商 为了工作,我在我的html webview应用程序中有2个js文件和2个html文件。像这样: var ipValue; var connection; ipValue = "ws://192.168.1.40:81/"; connection = new WebSocket(ipValue); console.log(&q

我有一个webview android应用程序,可以通过重定向连接到本地websocket和公共websocket ip上的服务器,而无需ip提供商

为了工作,我在我的html webview应用程序中有2个js文件和2个html文件。像这样:

var ipValue;
var connection;
ipValue = "ws://192.168.1.40:81/";
connection = new WebSocket(ipValue);

 console.log("IP value changed to:"+ipValue);
    connection.onopen = function () {
    connection.send('Websocket funcionando!' + new Date());


    //connection.send('ping');
    //await ws.send('2')
    //ws.send("Hello, Ardunio");
};
connection.onerror = function (error) {
    console.log('WebSocket Error ', error);
};
connection.onmessage = function (e) {
    console.log('Server: ', e.data);

};

for the public 
var ipValue;
var connection;
ipValue = "ws://xxxxxx.ddns.net:81/";
connection = new WebSocket(ipValue);
//console.log(text)
    console.log("IP value changed to:"+ipValue);
    connection.onopen = function () {
    connection.send('Websocket funcionando!' + new Date());
    //connection.send('ping');
    //await ws.send('2')
    //ws.send("Hello, Ardunio");
};
connection.onerror = function (error) {
    console.log('WebSocket Error ', error);
};

如何在同一个js文件中自动从本地ip切换到公共ip。或者将2个js文件合并为一个