简体   繁体   English

浏览器关闭 WebSocket 连接,错误 1006 在我在 OpenVPN 后面时建立后一秒

[英]Browser closes WebSocket connection with error 1006 one second after it is established when I'm behind OpenVPN

I have small HTTP + WebSocket server hosted on Amazon VPS.我有小型 HTTP + WebSocket 服务器托管在 Amazon VPS 上。 Index.html has JS code to connect WebSocket server and exchange data with it. Index.html有JS代码连接WebSocket服务器并与之交换数据。 When I connect my server directly using public IP or domain name - everything works fine.当我使用公共 IP 或域名直接连接我的服务器时 - 一切正常。

However I don't want this server to be public, so I configured OpenVPN to connect to this server privately.但是我不希望这台服务器公开,所以我将 OpenVPN 配置为私下连接到这台服务器。

Sometimes everything works as expected over OpenVPN and when I enter local (inside VPN) servers IP address in my browser (Chrome or Opera) it succesfully loads index.html, connects my WebSocket server and succesfully exchanges data via WebSocket connection. Sometimes everything works as expected over OpenVPN and when I enter local (inside VPN) servers IP address in my browser (Chrome or Opera) it succesfully loads index.html, connects my WebSocket server and succesfully exchanges data via WebSocket connection. But sometimes (or some days) 1 second after Websocket connection is established it is closed by browser with error code 1006 and without any description.但有时(或某些天)在 Websocket 连接建立后 1 秒,它会被浏览器关闭,错误代码为 1006,并且没有任何描述。 My script tries to reconnect WebSocket 1 second after this, but result is the same all the time.我的脚本尝试在此之后 1 秒重新连接 WebSocket,但结果始终相同。

I can't figure out why sometimes everything is working and sometimes I can't use WebSocket over OpenVPN for several hours.我不明白为什么有时一切正常,有时我无法在 OpenVPN 上使用 WebSocket 几个小时。

Can somebody describe why error 1006 occures when using WebSocket over OpenVPN and how to eliminate it by coding or reconfiguring Chrome, Opera or OpenVPN?有人可以描述为什么在 OpenVPN 上使用 WebSocket 时会出现错误 1006,以及如何通过编码或重新配置 Chrome、Opera 或 OpenVPN 来消除它?

I discovered that problem only occurs when any side of WS connection sends large message.我发现只有当 WS 连接的任何一侧发送大消息时才会出现该问题。

I guess that if there is some middleware like VPN, firewall or proxy between browser and WebSocket server, then large WS message can exceed some internal packet size or limit of that middleware and it will interrupt the connection between browser and server during message transfer.我猜如果浏览器和 WebSocket 服务器之间有一些中间件,如 VPN、防火墙或代理,那么大的 WS 消息可能会超过该中间件的某些内部数据包大小或限制,它会在消息传输过程中中断浏览器和服务器之间的连接。 This unexpected disconnect results to error 1006 in your browser.这种意外断开会导致浏览器出现错误 1006。

If your clients experience unexpected disconnects with error 1006, try to minimize WebSocket message sizes of your API.如果您的客户端遇到错误 1006 的意外断开连接,请尝试最小化 API 的 WebSocket 消息大小。 If you need to send large data amounts then don't send it in one chunk.如果您需要发送大量数据,请不要将其一大块发送。 You better slice it and send multiple short messages.您最好将其切片并发送多条短信。

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

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