服务端使用的是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:
客户端log: