简体   繁体   中英

Java Script Web Socket client is not working

I'm developing php webpage And I want to use web socket.I developed a javascript web socket client.And I developed a websocket using java.Locally web socket client is working well.But when hosted, it is not working.My wen Socket is working well.When web page run locally,I use hosted java web socket and It is working well. this is my javacript web socket client

var INIT_WS = "ws://184.72.171.96:9059/";

function openwebsocket(uname){

                if(webSocket !== undefined && webSocket.readyState !== WebSocket.CLOSED){
                   writeResponse("WebSocket is already opened.");
                    return;
                }
                webSocket = new WebSocket(INIT_WS + "Sl2World/slworldendpoint/"+uname);

                webSocket.onopen = function(event){
                    if(event.data === undefined)
                        return; 
                    writeResponse(event.data);
                };

                webSocket.onmessage = function(event){

                    writeResponse(event.data);                    
                }; 
                webSocket.onclose = function(event){
                    writeResponse("Connection closed");
                }; 
           }

When php web page hosted,Why it is not working.In that case I can't get any error message.I thing web socket connection request is not going to java web socket. thank you.

This would appear to be a security configuration issue on the host. While your local PHP file connects without a problem this will be because of a network firewall issue on your hosts network which would not affect a PHP file running on the same network. Most web hosts will not support websockets at this point due to their environments not being designed for them yet. Your best bet would be to find a host which specifically allows websockets and then ask them what socket numbers are allowed, or set up your own virtual or dedicated machine to run your java application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM