简体   繁体   English

Java Script Web Socket客户端无法正常工作

[英]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. 我正在开发php网页,我想使用Web套接字。我开发了一个javascript Web套接字客户端。然后我使用Java开发了一个Websocket。本地Web套接字客户端运行良好。但是在托管时,它无法正常工作。运行良好。当网页在本地运行时,我使用托管的Java Web socket运行良好。 this is my javacript web socket client 这是我的javacript Web套接字客户端

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. 当托管php web页面时,为什么它不起作用。在那种情况下,我不会收到任何错误消息。我的Web套接字连接请求不会转到Java Web套接字。 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. 尽管您的本地PHP文件连接没有问题,但这是由于主机网络上的网络防火墙问题,不会影响在同一网络上运行的PHP文件。 Most web hosts will not support websockets at this point due to their environments not being designed for them yet. 由于目前尚未为他们设计环境,因此大多数Web主机目前不支持WebSocket。 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. 最好的选择是找到一个专门允许websocket的主机,然后询问它们允许的套接字号,或者设置自己的虚拟机或专用计算机来运行Java应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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