1
This commit is contained in:
@@ -3,6 +3,7 @@ using Best.WebSockets;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
@@ -80,10 +81,10 @@ namespace Assets.MyGame.Scripts.Net
|
||||
WebSocketSendList.Bind(GameManager.Instance.user.id);
|
||||
break;
|
||||
case SocketType.room:
|
||||
|
||||
|
||||
break;
|
||||
case SocketType.game:
|
||||
WebSocketSendList.JoinRoom("11109", GameManager.Instance.user.id,1);
|
||||
|
||||
|
||||
break;
|
||||
case SocketType.chess:
|
||||
@@ -99,7 +100,11 @@ namespace Assets.MyGame.Scripts.Net
|
||||
{
|
||||
Debug.Log($"[WebSocket] {type} 连接关闭 Code:{code} Reason:{reason}");
|
||||
// 自动重连
|
||||
StartCoroutine(Reconnect(type));
|
||||
if (code!=WebSocketStatusCodes.NormalClosure)
|
||||
{
|
||||
StartCoroutine(Reconnect(type));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
ws.OnClosed += (web, code, message) =>
|
||||
@@ -145,7 +150,8 @@ namespace Assets.MyGame.Scripts.Net
|
||||
{
|
||||
if (sockets.TryGetValue(type, out var ws))
|
||||
{
|
||||
ws.Close();
|
||||
ws.Close(WebSocketStatusCodes.NormalClosure, "正常关闭"); // 或者 CloseStatusCode.Normal
|
||||
//ws.Close();
|
||||
sockets.Remove(type);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user