gimite / web-socket-js

HTML5 Web Socket implementation powered by Flash
BSD 3-Clause "New" or "Revised" License
2.73k stars 489 forks source link

Error during WebSocket handshake: Unexpected response code: 200 #179

Closed huangche007 closed 6 years ago

huangche007 commented 6 years ago

My code as follows: `var ws = new WebSocket("ws://dev.ectrend.com:80"); ws.onopen = function() {

    };
    ws.onmessage = function(e) {
        // Receives a message.
        var respObj = JSON.parse(e.data);
        console.log(respObj);
        initTipsInfo(respObj);
    };
    /**
     * 根据返回的通知提示信息,初始化对应的dom元素
     * @param respObj
     */
    function initTipsInfo(respObj){
        if(parseInt(respObj.msg_cnt) === 0){
            $("#m-info-count").hide();
        }else {
            $("#m-info-count").show();
            $("#m-info-count").html(respObj.msg_cnt);
        }
        if(parseInt(respObj.logistics_msg_cnt) === 0){
            $("#wuliu-count").hide();
        }else {
            $("#wuliu-count").show();
            $("#wuliu-count").html(respObj.logistics_msg_cnt);
        }

        if(parseInt(respObj.sys_msg_cnt) === 0){
            $("#sys_count").hide();
            $("#mine-tip-count").hide();
        }else{
            $("#sys_count").show();
            $("#mine-tip-count").show();
            $("#sys_count").html(respObj.sys_msg_cnt);
            $("#mine-tip-count").html(respObj.sys_msg_cnt);
        }
    };
    ws.onclose = function() {
        ws.close();
    };
    ws.onerror = function (evt) {
        console.log("连接出错了!");
    };`

there is an error:WebSocket connection to 'ws://dev.ectrend.com/' failed: Error during WebSocket handshake: Unexpected response code: 200 tips:when i change the connection port to 81,var ws = new WebSocket("ws://dev.ectrend.com:81"); everything is right

gimite commented 6 years ago

Looks like you are running the web socket server on port 81 instead of 80? I believe the server shouldn't return 200 for web socket handshake if it supports web socket.

huangche007 commented 6 years ago

@gimite Yeah,this problem has resolved