dqlhsm9820 2015-01-26 04:41
浏览 118

Javascript Websocket客户端无法正常工作

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.

  • 写回答

1条回答 默认 最新

  • duandou2763 2015-03-07 16:46
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?