简体   繁体   English

没有客户端脚本的Socket.IO ping

[英]Socket.IO ping without client-side script

I have an Android application and when somebody forces it to stop it doesn't fire the disconnect event on the server side. 我有一个Android应用程序,当有人强迫它停止运行时,不会在服务器端触发断开连接事件。

Since I can't force people to update their android app, I can't make a ping event handler on the client side. 由于无法强迫人们更新其android应用程序,因此无法在客户端上执行ping事件处理程序。 How could I check on the server side whether the client is active without client-side modification? 如何在不修改客户端的情况下在服务器端检查客户端是否处于活动状态?

You need to find out why the disconnect event doesn't fire. 您需要找出断开事件为什么不触发的原因。
Have you put the socket's disconnect event inside the connection callback? 您是否将套接字的断开连接事件放在 connection回调中?
Also pay attention to variable io and socket . 也要注意变量iosocket Maybe you put it wrong. 也许你说错了。

io.on('connection', function (socket) {
  console.log('user connected');

  socket.on('disconnect', function () {
    console.log('user disconnected');
  });
});

If the structure is already right, then I believe you should check the client's code. 如果结构已经正确,那么我相信您应该检查客户端的代码。

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

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