Socket.IO的客户端关闭后,服务端不断收到connection事件

新手上路,请多包涵

服务端使用的是node.js和socket.io,客户端使用了Unity和BestHTTP。


// Server
io.on('connection', function(socket) {

    console.log('User[' + socket.id + '] connected.');

    socket.on('disconnect', () => {
        console.log('disconnect.');
        
    });

    // 
});
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BestHTTP;
using BestHTTP.SocketIO;

public class SocketIOClientTest : MonoBehaviour
{
    private SocketManager _manager = null;
    // Start is called before the first frame update
    void Start()
    {
        _manager = new SocketManager(new Uri("http://localhost:9314/socket.io/"));
        _manager.Socket.On("connect", (socket, packet, args) => { Debug.Log("1"); });
    }
}

两端的测试代码都很简单,UnityEditor中启动Play后,正常连接;

但问题来了:UnityEditor中Stop之后,服务端会继续收到connection事件,最诡异的是UnityEditor已经停止播放的情况下,Debug.Log还在不断输出,除非关闭UnityEditor这个进程;感觉有个背景线程没有终止。请教,这是使用方法上的问题还是Unity或者BestHTTP的bug吗?

服务端log:
clipboard.png

客户端log:

clipboard.png

阅读 3.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题