WebSocket checker
Test a WebSocket endpoint: whether the handshake succeeds, how long it takes, and what the server sends first.
WebSocket 检测
检测一个 WebSocket 端点:握手是否成功、耗时多久,以及服务器发送的第一条消息。
What the checker shows
- Handshake: The status the server answers the upgrade with, and whether its accept key is valid.
- Time: How long the connection and upgrade took.
- First message: The start of the first message the server sends on its own, if any arrives within 5 seconds.
- Close: The close code and reason when the server ends the connection straight away.
When the handshake fails
- Behind nginx: Pass the upgrade on: proxy_http_version 1.1, proxy_set_header Upgrade $http_upgrade and proxy_set_header Connection "upgrade".
- Closed after a minute: Proxies close idle connections. Send a ping more often than the proxy's idle timeout.
- Redirect instead of 101: WebSocket clients do not follow redirects. Use the final address, often wss:// instead of ws://.
- Close code 1008 or 4xxx: The server refused the connection on purpose, usually for a missing token or a disallowed Origin.
Know when real-time features stop working
When a WebSocket endpoint fails, chat, live dashboards and notifications go quiet while the rest of the site loads fine. An OpenUptime WebSocket monitor makes the handshake on a schedule and alerts you when it fails.
Questions
What does the checker do?
It opens a WebSocket connection to the address, checks that the server answers the upgrade with 101 Switching Protocols and a valid accept key, then waits up to 5 seconds for a first message. It sends nothing and closes the connection afterwards.
Why do I get 200, 400 or 404 instead of 101?
The request reached a normal web handler instead of the WebSocket server. Usually a proxy or load balancer drops the Upgrade and Connection headers, the path is wrong, or the server only accepts WebSocket connections that carry a token or an Origin it expects.
The connection works but no message arrives. Is that a problem?
Not by itself. Many servers only answer after the client subscribes or sends a request. A server that pushes a greeting or a heartbeat on connect shows it here.
Can I check ws:// as well as wss://?
Both, on the default ports (80 and 443). An address without a scheme is opened as wss://. Only public addresses can be checked.
Can OpenUptime watch a WebSocket endpoint?
Yes. A WebSocket monitor makes the same handshake on a schedule. It can also send a message and require the answer to contain a keyword, so it fails when the server accepts connections but stops responding.
检测结果包含什么
- 握手: 服务器响应升级请求的状态码,以及它返回的 accept 密钥是否有效。
- 耗时: 建立连接和完成升级所用的时间。
- 第一条消息: 服务器主动发送的第一条消息的开头部分(如果 5 秒内收到)。
- 关闭: 服务器立即断开连接时的关闭代码和原因。
握手失败时
- 使用 nginx 时: 需要转发升级请求:proxy_http_version 1.1、proxy_set_header Upgrade $http_upgrade 和 proxy_set_header Connection "upgrade"。
- 一分钟后被断开: 代理会关闭空闲连接。发送 ping 的间隔要短于代理的空闲超时。
- 返回跳转而不是 101: WebSocket 客户端不会跟随跳转。使用最终地址,通常是 wss:// 而不是 ws://。
- 关闭代码 1008 或 4xxx: 服务器主动拒绝了连接,通常是因为缺少令牌或 Origin 不被允许。
实时功能失效时第一时间知道
WebSocket 端点出问题时,聊天、实时面板和通知都会悄无声息,而网站的其他部分照常加载。OpenUptime 的 WebSocket 监控会按计划进行握手,失败时提醒你。
常见问题
这个工具做了什么?
它向这个地址发起 WebSocket 连接,检查服务器是否以 101 Switching Protocols 和有效的 accept 密钥响应升级请求,然后最多等待 5 秒接收第一条消息。它不发送任何内容,结束后会关闭连接。
为什么返回的是 200、400 或 404,而不是 101?
请求到达的是普通的 Web 处理程序,而不是 WebSocket 服务。常见原因是代理或负载均衡丢掉了 Upgrade 和 Connection 头,路径不对,或者服务器只接受带有令牌或特定 Origin 的连接。
连接成功了但没有收到消息,有问题吗?
不一定。很多服务器只在客户端订阅或发出请求之后才回应。连接后会主动发送欢迎消息或心跳的服务器,消息会显示在这里。
能检测 ws:// 吗,还是只能 wss://?
都可以,使用默认端口(80 和 443)。没有写协议的地址按 wss:// 打开。只能检测公网地址。
OpenUptime 能持续监控 WebSocket 端点吗?
可以。WebSocket 监控会按计划进行同样的握手,还可以发送一条消息并要求回复包含某个关键词,这样当服务器接受连接却不再回应时,检测也会失败。