JavaScript Websocket only works on localhost -


can tell me how use javascript create wss connection remote ip address?

my websocket works on 127.0.0.1 , localhost

ws = new websocket("wss://127.0.0.1:13529"); ws.onopen = function() {   alert("连接成功");   ws.send('tom');   alert("给服务端发送一个字符串:tom");};   ws.onmessage = function(e) {   alert("收到服务端的消息:" + e.data); }; 

after change 127.0.0.1 ip address, connection cannot established.

i found post why did failed connect websocket?.

it says setting '0.0.0.0' can solve problem. however, changed codes following, cannot run.

enter image description here

the error message is:

uncaught syntaxerror: unexpected identifier 

i install ssl cert: install ssl cert

websockets not going standardized raw socket support.

or more raw socket portions needed directly communicate between 2 browsers without need of host server reform data.

but answer question, within google web apps (to discontinued 2018 per chrome press release) have web server running websockets using this code / web app (web server chrome offered chromebeat.com) allows other systems access web server. i've not examined code.

given bad news suggest using nodejs.

https://www.w3.org/tr/websockets/ current published.

following http procedures here introduce serious security problems in web browser context. example, consider host websocket server @ 1 path , open http redirector @ another. suddenly, script can given particular websocket url can tricked communicating (and potentially sharing secrets with) host on internet, if script checks url has right hostname.

https://w3c.github.io/websockets/ development

no 1 in web platform working group actively working on specification. latest version of websocket api use whatwg living standard.

https://html.spec.whatwg.org/multipage/web-sockets.html#network

to enable web applications maintain bidirectional communications server-side processes, specification introduces websocket interface.

this interface does not allow raw access underlying network. example, interface not used implement irc client without proxying messages through custom server.

the web server requires raw access sockets :(


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -