简体   繁体   English

WebSocket-如何保持连接?

[英]WebSocket - how to keep connection?

I have two clients connected through WebSocket server that is behind my influence field. 我有两个客户端通过WebSocket服务器连接,该服务器位于我的影响力领域后面。 After about 1,5 minutes both clientes get disconnected. 大约1.5分钟后,两个客户端都断开连接。 Reconnecting is not the best solution in my case, because it takes time and sometimes it occures that there should be send a message withing this time. 在我的情况下,重新连接不是最佳的解决方案,因为这需要时间,并且有时会在这段时间内发送一条消息。 Is this a kind of a server side configuration to maintain communication instantly? 这是一种服务器端配置,可以即时维护通信吗? Is there a way to keep connection established doing something on the client side? 有没有办法使连接建立在客户端上执行某些操作?

The Websocket protocol implements so called PING/PONG messages to keep Websockets alive, even behind proxies, firewalls and load-balancers. Websocket协议实现了所谓的PING / PONG消息,以使Websocket保持活动状态,甚至在代理,防火墙和负载平衡器之后也是如此。 The server sends a PING message to the client through the Websocket, which then replies with PONG. 服务器通过Websocket向客户端发送PING消息,然后通过PONG进行答复。 If the client does not reply, the server closes the connection. 如果客户端未回复,则服务器关闭连接。

Check Your server config probably a wrong config have this side effect. 检查您的服务器配置是否可能有错误的配置有此副作用。

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

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