SockJS 作为 websocket 连接,但没有通过 [英] SockJS connected as websocket, but nothing going through

查看:39
本文介绍了SockJS 作为 websocket 连接,但没有通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在特定访问网络上使用 SockJS 时遇到问题.它认为这与 SockJS 根据网络状态选择最佳传输协议(websocket、长轮询...)的方式有关.

I came accross a problem while using SockJS on a specific access network. It think it is related to the way SockJS chooses the best transport protocol (websocket, long polling, ...) according to the state of the network.

使用网络浏览器,我的 SockJS 客户端通过 websocket 传输协议连接到我的节点 SockJS 服务器.我什至在节点上看到了on connection"事件.但是,当我发送数据时,没有任何东西通过它.详尽地说,它在其他一些接入网络中运行良好.

Using a web browser, my SockJS client is connected with the websocket transport protocol to my node SockJS server. I even see the "on connection" event on node. However, when I send data, nothing passes through it. To be exhaustive, it works perfectly well from some other access networks.

根据网站http://websocketstest.com/的结果,这个接入网的状态是有点特殊:对于 WebSockets(端口 80),它坚持:

According to the results of the website http://websocketstest.com/ the state of this access network is a bit special: for WebSockets (Port 80), it is stucked to:

Connected       Yes✔
Data Receive    Yes✔

为了确保 websocket 运行良好,它还应该有一个由测试服务器每秒钟更新一次的服务器时间"行.由于情况并非如此,我很确定我有一个透明的 HTTP 代理,它会中断 websocket 连接.

To be sure websocket works well, it should also have a "Server time" line updated every seconds by the test server. Since it is not the case, I am pretty sure I have a transparent HTTP proxy which breaks the websocket connection.

然而,SockJS 没有发现这一点,也没有切换到回退协议.我认为它是为此而设计的.

However, SockJS does not discover that, and it does not switch to a fallback protocol. I thought it was designed to do so.

我是否误解了 SockJS 的传输协商功能?

Am I mistaken about the transport negotiation capabilities of SockJS?

Socket.IO 在这种情况下还是对于这种具有透明 HTTP 代理的访问网络更健壮?

Is Socket.IO more robust in this kind of scenario or for this kind of access networks with transparent HTTP proxies?

我知道我可以将 SockJS 与 SSL 结合使用,但我认为这是一种后备方案,而不是真正的解决方案.

I know I could use SockJS with SSL, but I think it is rather a fallback, not really a solution.

推荐答案

我认为您误解了 SockJS 的传输协商功能.SockJS 是一个 websocket 模拟.SockJS 的行为类似于 websockets.事实上,如果 websockets 由客户端支持,它们将被使用.但当然,有些浏览器不支持 websockets,这正是 SockJS 所关心的.回退机制用于找到客户端支持的传输,而不是网络支持的传输.

I think you are mistaken about the transport negotiation capabilities of SockJS. SockJS is a websocket emulation. SockJS behaves like websockets. Indeed, if websockets are supported by the client they will be use. But of course, some browsers don't support websockets, which is what SockJS takes care of. The fallback mechanism is used to find a transport that is supported by the client, not a transport which is supported by the network.

事实上,SockJS 遍历传输直到找到一个成功的连接,这有点误导它正在尝试做什么.它不会处理网络中断 websockets 的情况,这种方式看起来好像 websocket 已连接,或者任何其他传输似乎已连接(通过读取连接状态)但数据无法通过.

The fact that SockJS iterates through transports until it finds a successful connection is sort of misleading about what it is trying to do. It doesn't take care of situations where networks break websockets in a way that appears as if the websocket is connected, or any other transport that appears connected (by reading the connection status) but data doesn't make it through.

您有责任确保数据通过网络传输,并且如果这是您的意图,您也保持连接.这些东西超出了 websockets 的范围,因此也不在 SockJS 的范围内.

You are responsible for ensuring that data makes it through the network and that you also remain connected if this is what you intend. These things are outside the scope of websockets, and therefore the scope of SockJS.

这篇关于SockJS 作为 websocket 连接,但没有通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆