webSocket_websocket连接_websocket与socket区别(4)

电脑杂谈  发布时间:2017-02-19 06:00:10  来源:网络整理

utils.objectExtend(that._options, options);这一句比较可疑是转移属性的,

that._applyInfo(info, rtt, protocols_whitelist);比较可疑,看一下

SockJS.prototype._applyInfo = function(info, rtt, protocols_whitelist) {
    var that = this;
    that._options.info = info;
    that._options.rtt = rtt;
    that._options.rto = utils.countRTO(rtt);
    that._options.info.null_origin = !_document.domain;
    var probed = utils.probeProtocols();
    that._protocols = utils.detectProtocols(probed, protocols_whitelist, info);
};

rto设置找到了!that._options.rto = utils.countRTO(rtt);

utils.countRTO = function (rtt) {
    var rto;
    if (rtt > 100) {
        rto = 3 * rtt; // rto > 300msec
    } else {
        rto = rtt + 200; // 200msec < rto <= 300msec
    }
    return rto;
}

好了,只用设置rtt既可以设置rto了。。。就这样,连接超时的问题算是解决了。websocket连接

二、但是还没完,就算websocket连接超时导致协议切换为xhr_streaming,也不会导致后台报错的情况出现,下面解决这个问题:

报错处的代码:在AbstractHttpSockJsSession类中:

private void initRequest(ServerHttpRequest request, ServerHttpResponse response,
            SockJsFrameFormat frameFormat) {

        Assert.notNull(request, "Request must not be null");
        Assert.notNull(response, "Response must not be null");
        Assert.notNull(frameFormat, "SockJsFrameFormat must not be null");

        this.response = response;
        this.frameFormat = frameFormat;
        this.asyncRequestControl = request.getAsyncRequestControl(response);
    }

最后一句报错咯,看代码:

public ServerHttpAsyncRequestControl getAsyncRequestControl(ServerHttpResponse response) {
        if (this.asyncRequestControl == null) {
            Assert.isInstanceOf(ServletServerHttpResponse.class, response);
            ServletServerHttpResponse servletServerResponse = (ServletServerHttpResponse) response;
            this.asyncRequestControl = new ServletServerHttpAsyncRequestControl(this, servletServerResponse);//这一句报错了
        }
        return this.asyncRequestControl;
    }


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/ruanjian/article-33265-4.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...