vscode的remote-ssh无法连接,服务端日志[ExtensionHostConnection] The client has reconnected

关闭服务端

⚡ 01/24|19:34:39 > 20220119T105255 > ps aux | grep vscode
root     16092  0.0  0.0   9564  1324 ?        S    1月19   0:00 sh /root/.vscode-server/bin/0ba0ca52957102ca3527cf479571617f0de6ed50/server.sh --host=127.0.0.1 --enable-remote-auto-shutdown --port=0
root     16100  0.0  0.0 951808 60660 ?        Sl   1月19   3:53 /root/.vscode-server/bin/0ba0ca52957102ca3527cf479571617f0de6ed50/node /root/.vscode-server/bin/0ba0ca52957102ca3527cf479571617f0de6ed50/out/vs/server/main.js --host=127.0.0.1 --enable-remote-auto-shutdown --port=0
root     49733  0.0  0.0 112828  1000 pts/25   S+   19:34   0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn vscode
 ⚡ 01/24|19:34:46 > 20220119T105255 > kill -9 16092 16100

重新连接

然后重新用vscode连接即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 React Native 中使用 WebSocket,可以使用内置的 `WebSocket` API。要实现心跳检测和重新连接机制,可以编写自定义的 WebSocket 类。 下面是一个简单的实现,可以用作参考: ```javascript class MyWebSocket { constructor(url) { this.ws = new WebSocket(url); this.heartBeatTimer = null; this.reconnectTimer = null; this.isClosed = false; this.ws.onopen = () => { this.heartBeat(); }; this.ws.onmessage = (event) => { // 处理收到的消息 }; this.ws.onerror = (error) => { console.log(`WebSocket error: ${error}`); this.reconnect(); }; this.ws.onclose = () => { console.log(`WebSocket closed`); this.isClosed = true; this.reconnect(); }; } send(data) { if (!this.isClosed) { this.ws.send(data); } } heartBeat() { this.send('heart beat'); this.heartBeatTimer = setTimeout(() => { this.heartBeat(); }, 10000); // 10秒检测一次心跳 } reconnect() { if (this.isClosed) { return; } if (this.reconnectTimer) { clearTimeout(this.reconnectTimer); } this.reconnectTimer = setTimeout(() => { console.log(`WebSocket reconnecting...`); this.ws = new WebSocket(this.ws.url); this.ws.onopen = () => { console.log(`WebSocket reconnected`); clearTimeout(this.reconnectTimer); this.isClosed = false; this.heartBeat(); }; this.ws.onmessage = (event) => { // 处理收到的消息 }; this.ws.onerror = (error) => { console.log(`WebSocket error: ${error}`); this.reconnect(); }; this.ws.onclose = () => { console.log(`WebSocket closed`); this.isClosed = true; this.reconnect(); }; }, 3000); // 3秒后尝试重新连接 } close() { this.isClosed = true; clearTimeout(this.heartBeatTimer); clearTimeout(this.reconnectTimer); this.ws.close(); } } ``` 这个自定义的 WebSocket 类具有心跳检测和重新连接机制。在初始化时,会创建一个 WebSocket 连接,并设置 `onopen`、`onmessage`、`onerror` 和 `onclose` 事件的回调函数。当连接打开时,会开始心跳检测;当连接关闭时,会尝试重新连接。在发送消息时,会检查连接是否已关闭,如果未关闭,则发送消息。关闭连接时,会清除定时器并关闭 WebSocket 连接。 使用这个自定义的 WebSocket 类时,只需实例化它,并调用其 `send` 方法发送消息: ```javascript const ws = new MyWebSocket('ws://localhost:8080'); ws.send('hello'); ``` 也可以在需要时关闭连接: ```javascript ws.close(); ``` 这样就可以在 React Native 中使用 WebSocket,并实现心跳检测和重新连接机制了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值