修复客户端重连问题

This commit is contained in:
sin365 2024-06-21 17:17:32 +08:00
parent ed48aade15
commit 59ee584c2c
16 changed files with 356 additions and 275 deletions

Binary file not shown.

Binary file not shown.

View File

@ -49,6 +49,24 @@ namespace ServerCore.Manager
ClientUserCount = mDictTunnelID2Listeners.Count; ClientUserCount = mDictTunnelID2Listeners.Count;
} }
public void GetClientDebugInfo()
{
AppNoSugarNet.log.Debug($"------------ mDictTunnelID2Listeners {mDictTunnelID2Listeners.Count} ------------");
lock (mDictTunnelID2Listeners)
{
foreach (var item in mDictTunnelID2Listeners)
{
var cinfo = item.Value.GetDictIdx2LocalClientInfo();
AppNoSugarNet.log.Debug($"----- TunnelID {item.Key} ObjcurrSeed->{item.Value.currSeed} ClientList->{item.Value.ClientList.Count} Idx2LocalClient->{cinfo.Count} -----");
foreach (var c in cinfo)
{
AppNoSugarNet.log.Debug($"----- Idx {c.Key} bRemoteConnect->{c.Value.bRemoteConnect} msgQueue.Count->{c.Value.msgQueue.Count} -----");
}
}
}
}
/// <summary> /// <summary>
/// 初始化连接,先获取到配置 /// 初始化连接,先获取到配置
/// </summary> /// </summary>
@ -114,10 +132,12 @@ namespace ServerCore.Manager
for (int i = 0; i < keys.Length; i++) for (int i = 0; i < keys.Length; i++)
{ {
LocalListener _listener = mDictTunnelID2Listeners[keys[i]]; LocalListener _listener = mDictTunnelID2Listeners[keys[i]];
_listener.StopAll(); _listener.StopAllLocalClient();
_listener.Stop();
//_listener.Stop(); //_listener.Stop();
RemoveLocalListener(_listener); RemoveLocalListener(_listener);
} }
mDictTunnelID2Listeners.Clear();
} }
} }
#endregion #endregion
@ -266,7 +286,7 @@ namespace ServerCore.Manager
/// <param name="data"></param> /// <param name="data"></param>
public void OnClientTunnelDataCallBack(byte tunnelId,byte Idx, byte[] data) public void OnClientTunnelDataCallBack(byte tunnelId,byte Idx, byte[] data)
{ {
//AppNoSugarNet.log.Info($"OnClientTunnelDataCallBack {tunnelId},{Idx}"); //AppNoSugarNet.log.Info($"OnClientTunnelDataCallBack {tunnelId},{Idx} data.Length->{data.Length}");
int SlienLenght = 1000; int SlienLenght = 1000;
//判断数据量大时分包 //判断数据量大时分包

View File

@ -6,16 +6,22 @@ namespace NoSugarNet.ClientCore.Manager
{ {
public class AppLogin public class AppLogin
{ {
static string LastLoginGuid = "";
public AppLogin() public AppLogin()
{ {
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdLogin, RecvLoginMsg); NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdLogin, RecvLoginMsg);
} }
public void Login(string Account)
public void Login()
{ {
if(string.IsNullOrEmpty(LastLoginGuid))
LastLoginGuid = Guid.NewGuid().ToString();
AppNoSugarNet.user.userdata.Account = LastLoginGuid;
Protobuf_Login msg = new Protobuf_Login() Protobuf_Login msg = new Protobuf_Login()
{ {
LoginType = 0, LoginType = 0,
Account = Account, Account = AppNoSugarNet.user.userdata.Account,
}; };
AppNoSugarNet.networkHelper.SendToServer((int)CommandID.CmdLogin, ProtoBufHelper.Serizlize(msg)); AppNoSugarNet.networkHelper.SendToServer((int)CommandID.CmdLogin, ProtoBufHelper.Serizlize(msg));
} }

View File

@ -8,6 +8,9 @@ namespace NoSugarNet.ClientCore
public byte mTunnelID; public byte mTunnelID;
public long mReciveAllLenght; public long mReciveAllLenght;
public long mSendAllLenght; public long mSendAllLenght;
public long currSeed;
static long Seed;
public LocalListener(int numConnections, int receiveBufferSize, byte TunnelID) public LocalListener(int numConnections, int receiveBufferSize, byte TunnelID)
: base(numConnections, receiveBufferSize) : base(numConnections, receiveBufferSize)
{ {
@ -17,12 +20,14 @@ namespace NoSugarNet.ClientCore
OnNetLog += OnShowNetLog; OnNetLog += OnShowNetLog;
mTunnelID = TunnelID; mTunnelID = TunnelID;
currSeed = Seed++;
} }
private void ClientNumberChange(int num, AsyncUserToken token) private void ClientNumberChange(int num, AsyncUserToken token)
{ {
AppNoSugarNet.log.Info("Client数发生变化"); AppNoSugarNet.log.Info("Client数发生变化");
//增加连接数 //增加连接数stsc
if (num > 0) if (num > 0)
{ {
int Idx = AddDictSocket(token.Socket); int Idx = AddDictSocket(token.Socket);
@ -79,9 +84,16 @@ namespace NoSugarNet.ClientCore
public void CloseConnectByIdx(byte Idx) public void CloseConnectByIdx(byte Idx)
{ {
if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInf)) if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo))
{ {
_localClientInf._socket.Shutdown(SocketShutdown.Both); //把未发送消息队列回收了
while (_localClientInfo.msgQueue.Count > 0)
{
IdxWithMsg msg = _localClientInfo.msgQueue.Dequeue();
AppNoSugarNet.local._localMsgPool.Enqueue(msg);
}
_localClientInfo._socket.Shutdown(SocketShutdown.Both);
} }
} }
@ -118,6 +130,11 @@ namespace NoSugarNet.ClientCore
public Queue<IdxWithMsg> msgQueue = new Queue<IdxWithMsg>(); public Queue<IdxWithMsg> msgQueue = new Queue<IdxWithMsg>();
} }
public Dictionary<int, LocalClientInfo> GetDictIdx2LocalClientInfo()
{
return DictIdx2LocalClientInfo;
}
int GetNextIdx() int GetNextIdx()
{ {
if (FreeIdxs.Count > 0) if (FreeIdxs.Count > 0)
@ -129,6 +146,12 @@ namespace NoSugarNet.ClientCore
return mSeedIdx++; return mSeedIdx++;
} }
void ResetFree()
{
FreeIdxs.Clear();
mSeedIdx = 0;
}
/// <summary> /// <summary>
/// 追加Socket返回下标 /// 追加Socket返回下标
/// </summary> /// </summary>
@ -143,6 +166,7 @@ namespace NoSugarNet.ClientCore
int Idx = GetNextIdx(); int Idx = GetNextIdx();
DictSocketHandle2Idx[socket.Handle] = Idx; DictSocketHandle2Idx[socket.Handle] = Idx;
DictIdx2LocalClientInfo[Idx] = new LocalClientInfo() { _socket = socket,bRemoteConnect = false}; DictIdx2LocalClientInfo[Idx] = new LocalClientInfo() { _socket = socket,bRemoteConnect = false};
AppNoSugarNet.log.Debug($"AddDictSocket mTunnelID->{mTunnelID} Idx->{Idx} socket.Handle{socket.Handle}");
return Idx; return Idx;
} }
} }
@ -160,6 +184,7 @@ namespace NoSugarNet.ClientCore
if (DictIdx2LocalClientInfo.ContainsKey(Idx)) if (DictIdx2LocalClientInfo.ContainsKey(Idx))
DictIdx2LocalClientInfo.Remove(Idx); DictIdx2LocalClientInfo.Remove(Idx);
DictSocketHandle2Idx.Remove(socket.Handle); DictSocketHandle2Idx.Remove(socket.Handle);
AppNoSugarNet.log.Debug($"RemoveDictSocket mTunnelID->{mTunnelID} Idx->{Idx} socket.Handle{socket.Handle}");
} }
} }
@ -211,7 +236,7 @@ namespace NoSugarNet.ClientCore
_localClientInfo.bRemoteConnect = bConnected; _localClientInfo.bRemoteConnect = bConnected;
} }
public void StopAll() public void StopAllLocalClient()
{ {
lock (DictIdx2LocalClientInfo) lock (DictIdx2LocalClientInfo)
{ {
@ -221,6 +246,14 @@ namespace NoSugarNet.ClientCore
CloseConnectByIdx((byte)Idxs[i]); CloseConnectByIdx((byte)Idxs[i]);
} }
DictIdx2LocalClientInfo.Clear(); DictIdx2LocalClientInfo.Clear();
DictSocketHandle2Idx.Clear();
ResetFree();
//清理事件
OnClientNumberChange -= ClientNumberChange;
OnReceive -= ReceiveData;
OnDisconnected -= OnDisconnect;
OnNetLog -= OnShowNetLog;
} }
} }

View File

@ -1,290 +1,296 @@
using HaoYueNet.ClientNetwork.OtherMode; //using HaoYueNet.ClientNetwork.OtherMode;
using HaoYueNet.ServerNetwork; //using HaoYueNet.ServerNetwork;
using System.Net.Sockets; //using System.Net.Sockets;
namespace NoSugarNet.ClientCore //namespace NoSugarNet.ClientCore
{ //{
public class LocalListener_Source : NetworkHelperCore_ListenerMode // public class LocalListener_Source : NetworkHelperCore_ListenerMode
{ // {
public byte mTunnelID; // public byte mTunnelID;
public long mReciveAllLenght; // public long mReciveAllLenght;
public long mSendAllLenght; // public long mSendAllLenght;
public LocalListener_Source(int numConnections, int receiveBufferSize, byte TunnelID) // public LocalListener_Source(int numConnections, int receiveBufferSize, byte TunnelID)
: base() // : base()
{ // {
OnConnected += ClientNumberChange; // OnConnected += ClientNumberChange;
OnReceive += ReceiveData; // OnReceive += ReceiveData;
OnDisconnected += OnDisconnectClient; // OnDisconnected += OnDisconnectClient;
OnNetLog += OnShowNetLog; // OnNetLog += OnShowNetLog;
mTunnelID = TunnelID; // mTunnelID = TunnelID;
} // }
private void ClientNumberChange(Socket socket) // private void ClientNumberChange(Socket socket)
{ // {
AppNoSugarNet.log.Info("Client数发生变化"); // AppNoSugarNet.log.Info("Client数发生变化");
//增加连接数 // //增加连接数
int Idx = AddDictSocket(socket); // int Idx = AddDictSocket(socket);
if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInf)) // if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInf))
{ // {
AppNoSugarNet.local.OnClientLocalConnect(mTunnelID, (byte)Idx); // AppNoSugarNet.local.OnClientLocalConnect(mTunnelID, (byte)Idx);
} // }
} // }
/// <summary> // /// <summary>
/// 通过下标发送 // /// 通过下标发送
/// </summary> // /// </summary>
/// <param name="Idx"></param> // /// <param name="Idx"></param>
/// <param name="data"></param> // /// <param name="data"></param>
public void SendSocketByIdx(int Idx, byte[] data) // public void SendSocketByIdx(int Idx, byte[] data)
{ // {
if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo)) // if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo))
{ // {
mSendAllLenght += data.Length; // mSendAllLenght += data.Length;
SendToClient(_localClientInfo._socket, data); // SendToClient(_localClientInfo._socket, data);
} // }
//TODO连接前缓存数据 // //TODO连接前缓存数据
} // }
/// <summary> // /// <summary>
/// 接受包回调 // /// 接受包回调
/// </summary> // /// </summary>
/// <param name="CMDID">协议ID</param> // /// <param name="CMDID">协议ID</param>
/// <param name="ERRCODE">错误编号</param> // /// <param name="ERRCODE">错误编号</param>
/// <param name="data">业务数据</param> // /// <param name="data">业务数据</param>
private void ReceiveData(Socket sk, byte[] data) // private void ReceiveData(Socket sk, byte[] data)
{ // {
DataCallBack(sk, data); // DataCallBack(sk, data);
} // }
public void DataCallBack(Socket sk, byte[] data) // public void DataCallBack(Socket sk, byte[] data)
{ // {
//AppNoSugarNet.log.Info("收到消息 数据长度=>" + data.Length); // //AppNoSugarNet.log.Info("收到消息 数据长度=>" + data.Length);
//记录接受长度 // //记录接受长度
mReciveAllLenght += data.Length; // mReciveAllLenght += data.Length;
if (!GetSocketIdxBySocket(sk, out int Idx)) // if (!GetSocketIdxBySocket(sk, out int Idx))
return; // return;
try // try
{ // {
if (GetMsgQueueByIdx(sk.Handle, out Queue<byte[]> _queue)) // if (GetMsgQueueByIdx(sk.Handle, out Queue<byte[]> _queue))
{ // {
lock (_queue) // lock (_queue)
{ // {
_queue.Enqueue(data); // _queue.Enqueue(data);
while (_queue.Count > 0) // while (_queue.Count > 0)
{ // {
AppNoSugarNet.local.OnClientTunnelDataCallBack(mTunnelID, (byte)Idx, _queue.Dequeue()); // AppNoSugarNet.local.OnClientTunnelDataCallBack(mTunnelID, (byte)Idx, _queue.Dequeue());
} // }
} // }
} // }
////抛出网络数据 // ////抛出网络数据
//AppNoSugarNet.local.OnClientTunnelDataCallBack(mTunnelID, (byte)Idx, data); // //AppNoSugarNet.local.OnClientTunnelDataCallBack(mTunnelID, (byte)Idx, data);
} // }
catch (Exception ex) // catch (Exception ex)
{ // {
AppNoSugarNet.log.Info("逻辑处理错误:" + ex.ToString()); // AppNoSugarNet.log.Info("逻辑处理错误:" + ex.ToString());
} // }
} // }
public void CloseConnectByIdx(byte Idx) // public void CloseConnectByIdx(byte Idx)
{ // {
if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInf)) // if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInf))
{ // {
_localClientInf._socket.Shutdown(SocketShutdown.Both); // _localClientInf._socket.Shutdown(SocketShutdown.Both);
} // }
} // }
/// <summary> // /// <summary>
/// 断开连接 // /// 断开连接
/// </summary> // /// </summary>
/// <param name="sk"></param> // /// <param name="sk"></param>
public void OnDisconnectClient(Socket sk) // public void OnDisconnectClient(Socket sk)
{ // {
AppNoSugarNet.log.Info("断开连接"); // AppNoSugarNet.log.Info("断开连接");
if (!GetSocketIdxBySocket(sk, out int Idx)) // if (!GetSocketIdxBySocket(sk, out int Idx))
return; // return;
AppNoSugarNet.local.OnClientLocalDisconnect(mTunnelID, (byte)Idx); // AppNoSugarNet.local.OnClientLocalDisconnect(mTunnelID, (byte)Idx);
RemoveDictSocket(sk); // RemoveDictSocket(sk);
} // }
public void OnShowNetLog(string msg) // public void OnShowNetLog(string msg)
{ // {
AppNoSugarNet.log.Info(msg); // AppNoSugarNet.log.Info(msg);
} // }
#region // #region 一个轻量级无用户连接管理
Dictionary<nint, int> DictSocketHandle2Idx = new Dictionary<nint, int>(); // Dictionary<nint, int> DictSocketHandle2Idx = new Dictionary<nint, int>();
Dictionary<nint, Queue<byte[]>> DictSocketHandle2Msg = new Dictionary<nint, Queue<byte[]>>(); // Dictionary<nint, Queue<byte[]>> DictSocketHandle2Msg = new Dictionary<nint, Queue<byte[]>>();
Dictionary<int, LocalClientInfo> DictIdx2LocalClientInfo = new Dictionary<int, LocalClientInfo>(); // Dictionary<int, LocalClientInfo> DictIdx2LocalClientInfo = new Dictionary<int, LocalClientInfo>();
int mSeedIdx = 0; // int mSeedIdx = 0;
List<int> FreeIdxs = new List<int>(); // List<int> FreeIdxs = new List<int>();
public class LocalClientInfo // public class LocalClientInfo
{ // {
public Socket _socket; // public Socket _socket;
public bool bRemoteConnect; // public bool bRemoteConnect;
public bool bLocalConnect => _socket.Connected; // public bool bLocalConnect => _socket.Connected;
public Queue<IdxWithMsg> msgQueue = new Queue<IdxWithMsg>(); // public Queue<IdxWithMsg> msgQueue = new Queue<IdxWithMsg>();
} // }
int GetNextIdx() // int GetNextIdx()
{ // {
if (FreeIdxs.Count > 0) // if (FreeIdxs.Count > 0)
{ // {
int Idx = FreeIdxs[0]; // int Idx = FreeIdxs[0];
FreeIdxs.RemoveAt(0); // FreeIdxs.RemoveAt(0);
return Idx; // return Idx;
} // }
return mSeedIdx++; // return mSeedIdx++;
} // }
/// <summary> // /// <summary>
/// 追加Socket返回下标 // /// 追加Socket返回下标
/// </summary> // /// </summary>
/// <param name="socket"></param> // /// <param name="socket"></param>
/// <returns></returns> // /// <returns></returns>
public int AddDictSocket(Socket socket) // public int AddDictSocket(Socket socket)
{ // {
if (socket == null) // if (socket == null)
return -1; // return -1;
lock (DictSocketHandle2Idx)
{
int Idx = GetNextIdx();
DictSocketHandle2Idx[socket.Handle] = Idx;
DictIdx2LocalClientInfo[Idx] = new LocalClientInfo() { _socket = socket,bRemoteConnect = false};
DictSocketHandle2Msg[socket.Handle] = new Queue<byte[]>();
return Idx;
}
}
public void RemoveDictSocket(Socket socket) // lock (DictSocketHandle2Idx)
{ // {
if (socket == null) // int Idx = GetNextIdx();
return; // DictSocketHandle2Idx[socket.Handle] = Idx;
lock (DictSocketHandle2Idx) // DictIdx2LocalClientInfo[Idx] = new LocalClientInfo() { _socket = socket,bRemoteConnect = false};
{ // DictSocketHandle2Msg[socket.Handle] = new Queue<byte[]>();
if (!DictSocketHandle2Idx.ContainsKey(socket.Handle)) // AppNoSugarNet.log.Debug($"AddDictSocket mTunnelID->{mTunnelID} Idx->{Idx} socket.Handle{socket.Handle}");
return; // return Idx;
int Idx = DictSocketHandle2Idx[socket.Handle]; // }
FreeIdxs.Add(Idx); // }
if (DictIdx2LocalClientInfo.ContainsKey(Idx))
DictIdx2LocalClientInfo.Remove(Idx);
if (DictSocketHandle2Msg.ContainsKey(socket.Handle)) // public void RemoveDictSocket(Socket socket)
DictSocketHandle2Msg.Remove(socket.Handle); // {
// if (socket == null)
// return;
// lock (DictSocketHandle2Idx)
// {
// if (!DictSocketHandle2Idx.ContainsKey(socket.Handle))
// return;
// int Idx = DictSocketHandle2Idx[socket.Handle];
// FreeIdxs.Add(Idx);
// if (DictIdx2LocalClientInfo.ContainsKey(Idx))
// DictIdx2LocalClientInfo.Remove(Idx);
DictSocketHandle2Idx.Remove(socket.Handle); // if (DictSocketHandle2Msg.ContainsKey(socket.Handle))
} // DictSocketHandle2Msg.Remove(socket.Handle);
}
bool GetSocketByIdx(int Idx, out LocalClientInfo _localClientInfo) // DictSocketHandle2Idx.Remove(socket.Handle);
{
if (!DictIdx2LocalClientInfo.ContainsKey(Idx))
{
_localClientInfo = null;
return false;
}
_localClientInfo = DictIdx2LocalClientInfo[Idx]; // AppNoSugarNet.log.Debug($"RemoveDictSocket mTunnelID->{mTunnelID} Idx->{Idx} socket.Handle{socket.Handle}");
return true; // }
} // }
bool GetMsgQueueByIdx(nint handle, out Queue<byte[]> _queue) // bool GetSocketByIdx(int Idx, out LocalClientInfo _localClientInfo)
{ // {
if (!DictSocketHandle2Msg.ContainsKey(handle)) // if (!DictIdx2LocalClientInfo.ContainsKey(Idx))
{ // {
_queue = null; // _localClientInfo = null;
return false; // return false;
} // }
_queue = DictSocketHandle2Msg[handle]; // _localClientInfo = DictIdx2LocalClientInfo[Idx];
return true; // return true;
} // }
public bool GetSocketIdxBySocket(Socket _socket, out int Idx) // bool GetMsgQueueByIdx(nint handle, out Queue<byte[]> _queue)
{ // {
if (_socket == null) // if (!DictSocketHandle2Msg.ContainsKey(handle))
{ // {
Idx = -1; // _queue = null;
return false; // return false;
} // }
if (!DictSocketHandle2Idx.ContainsKey(_socket.Handle)) // _queue = DictSocketHandle2Msg[handle];
{ // return true;
Idx = -1; // }
return false;
}
Idx = DictSocketHandle2Idx[_socket.Handle]; // public bool GetSocketIdxBySocket(Socket _socket, out int Idx)
return true; // {
} // if (_socket == null)
// {
// Idx = -1;
// return false;
// }
public bool CheckRemoteConnect(int Idx) // if (!DictSocketHandle2Idx.ContainsKey(_socket.Handle))
{ // {
if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo)) // Idx = -1;
return false; // return false;
return _localClientInfo.bRemoteConnect; // }
}
public void SetRemoteConnectd(int Idx,bool bConnected) // Idx = DictSocketHandle2Idx[_socket.Handle];
{ // return true;
if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo)) // }
return;
if (bConnected)
AppNoSugarNet.log.Info("远端本地连接已连接!!!!");
else
AppNoSugarNet.log.Info("远端本地连接已断开连接!!!!");
_localClientInfo.bRemoteConnect = bConnected;
}
public void StopAll() // public bool CheckRemoteConnect(int Idx)
{ // {
lock (DictIdx2LocalClientInfo) // if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo))
{ // return false;
int[] Idxs = DictIdx2LocalClientInfo.Keys.ToArray(); // return _localClientInfo.bRemoteConnect;
for (int i = 0; i < Idxs.Length; i++) // }
{
CloseConnectByIdx((byte)Idxs[i]);
}
DictIdx2LocalClientInfo.Clear();
}
}
#endregion // public void SetRemoteConnectd(int Idx,bool bConnected)
// {
// if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo))
// return;
// if (bConnected)
// AppNoSugarNet.log.Info("远端本地连接已连接!!!!");
// else
// AppNoSugarNet.log.Info("远端本地连接已断开连接!!!!");
// _localClientInfo.bRemoteConnect = bConnected;
// }
// public void StopAll()
// {
// lock (DictIdx2LocalClientInfo)
// {
// int[] Idxs = DictIdx2LocalClientInfo.Keys.ToArray();
// for (int i = 0; i < Idxs.Length; i++)
// {
// CloseConnectByIdx((byte)Idxs[i]);
// }
// DictIdx2LocalClientInfo.Clear();
// FreeIdxs.Clear();
// mSeedIdx = 0;
// }
// }
// #endregion
#region // #region 缓存
public void EnqueueIdxWithMsg(byte Idx, byte[] data) // public void EnqueueIdxWithMsg(byte Idx, byte[] data)
{ // {
if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo)) // if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo))
return; // return;
IdxWithMsg Msg = AppNoSugarNet.local._localMsgPool.Dequeue(); // IdxWithMsg Msg = AppNoSugarNet.local._localMsgPool.Dequeue();
Msg.Idx = Idx; // Msg.Idx = Idx;
Msg.data = data; // Msg.data = data;
_localClientInfo.msgQueue.Enqueue(Msg); // _localClientInfo.msgQueue.Enqueue(Msg);
} // }
public bool GetDictMsgQueue(byte Idx,out List<IdxWithMsg> MsgList) // public bool GetDictMsgQueue(byte Idx,out List<IdxWithMsg> MsgList)
{ // {
if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo) || _localClientInfo.msgQueue.Count < 1) // if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo) || _localClientInfo.msgQueue.Count < 1)
{ // {
MsgList = null; // MsgList = null;
return false; // return false;
} // }
MsgList = new List<IdxWithMsg>(); // MsgList = new List<IdxWithMsg>();
lock (_localClientInfo.msgQueue) // lock (_localClientInfo.msgQueue)
{ // {
while (_localClientInfo.msgQueue.Count > 0) // while (_localClientInfo.msgQueue.Count > 0)
{ // {
IdxWithMsg msg = _localClientInfo.msgQueue.Dequeue(); // IdxWithMsg msg = _localClientInfo.msgQueue.Dequeue();
MsgList.Add(msg); // MsgList.Add(msg);
} // }
return true; // return true;
} // }
} // }
#endregion // #endregion
} // }
} //}

View File

@ -49,7 +49,7 @@ namespace NoSugarNet.ClientCore.Manager
//如果之前已登录,则重新登录 //如果之前已登录,则重新登录
if (userdata.IsLoggedIn) if (userdata.IsLoggedIn)
{ {
AppNoSugarNet.login.Login(userdata.Account); AppNoSugarNet.login.Login();
} }
} }
} }

View File

@ -33,7 +33,7 @@ namespace NoSugarNet.ClientCore.Network
/// <summary> /// <summary>
/// 是否自动重连 /// 是否自动重连
/// </summary> /// </summary>
public bool bAutoReConnect = false; public bool bAutoReConnect = true;
/// <summary> /// <summary>
/// 重连尝试时间 /// 重连尝试时间
/// </summary> /// </summary>
@ -44,12 +44,21 @@ namespace NoSugarNet.ClientCore.Network
NetworkDeBugLog($"NetworkConnected:{IsConnect}"); NetworkDeBugLog($"NetworkConnected:{IsConnect}");
if (IsConnect) if (IsConnect)
{ {
AppNoSugarNet.login.Login(Guid.NewGuid().ToString()); //从未登录过
if (!AppNoSugarNet.user.IsLoggedIn)
{
//首次登录
AppNoSugarNet.login.Login();
}
} }
else else
{ {
//连接失败 //连接失败
NetworkDeBugLog("连接失败!"); NetworkDeBugLog("连接失败!");
//停止所有
AppNoSugarNet.local.StopAll();
//自动重连开关 //自动重连开关
if (bAutoReConnect) if (bAutoReConnect)
ReConnect(); ReConnect();

View File

@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
--> -->
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<History>True|2024-01-23T08:25:49.0876201Z;</History> <History>True|2024-04-23T09:15:55.5521754Z;True|2024-01-23T16:25:49.0876201+08:00;</History>
<LastFailureDetails /> <LastFailureDetails />
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
--> -->
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<History>True|2024-01-25T09:08:35.3176032Z;</History> <History>True|2024-04-23T09:13:21.9642037Z;True|2024-04-23T17:02:04.8137007+08:00;True|2024-01-25T17:08:35.3176032+08:00;</History>
<LastFailureDetails /> <LastFailureDetails />
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<_LastSelectedProfileId>D:\NoSugarNet\Sample\NoSugarNet.ClientCli\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId> <_LastSelectedProfileId>F:\Sin365\NoSugarNet\Sample\NoSugarNet.ClientCli\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -27,6 +27,12 @@ namespace NoSugarNet.ClientCli
case "con": case "con":
AppNoSugarNet.Connect(Config.ServerIP, Config.ServerPort); AppNoSugarNet.Connect(Config.ServerIP, Config.ServerPort);
break; break;
case "tlist":
AppNoSugarNet.local.GetClientCount(out int ClientUserCount, out int TunnelCount);
Console.WriteLine($"GetClientCount->{ClientUserCount} TunnelCount->{TunnelCount}");
AppNoSugarNet.local.GetClientDebugInfo();
break;
case "stop": case "stop":
AppNoSugarNet.Close(); AppNoSugarNet.Close();
break; break;

View File

@ -6,12 +6,13 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PropertyGroup> <PropertyGroup>
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>Any CPU</Platform> <Platform>Any CPU</Platform>
<PublishDir>bin\Release\net8.0\publish\linux-x64\</PublishDir> <PublishDir>bin\Release\net8.0\publish\win-x64\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol> <PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId> <_TargetId>Folder</_TargetId>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained> <SelfContained>false</SelfContained>
<PublishSingleFile>false</PublishSingleFile> <PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
--> -->
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<History>True|2024-04-14T14:24:49.2846754Z;True|2024-01-23T16:35:06.3918472+08:00;True|2024-01-23T16:34:52.0595483+08:00;True|2024-01-23T16:27:36.4850749+08:00;True|2024-01-23T16:27:04.0721589+08:00;</History> <History>True|2024-06-18T04:59:35.6257454Z;True|2024-06-18T10:27:07.8233386+08:00;True|2024-06-17T15:05:24.3158316+08:00;True|2024-05-20T18:14:09.8394409+08:00;True|2024-05-20T18:13:33.8442145+08:00;True|2024-05-20T18:01:49.3220793+08:00;True|2024-05-20T18:01:28.3681468+08:00;True|2024-04-14T22:24:49.2846754+08:00;True|2024-01-23T16:35:06.3918472+08:00;True|2024-01-23T16:34:52.0595483+08:00;True|2024-01-23T16:27:36.4850749+08:00;True|2024-01-23T16:27:04.0721589+08:00;</History>
<LastFailureDetails /> <LastFailureDetails />
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
--> -->
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<History>True|2024-04-15T07:24:50.3598281Z;True|2024-04-15T15:24:34.0374231+08:00;True|2024-01-25T17:09:07.9161603+08:00;True|2024-01-23T18:28:01.1220581+08:00;True|2024-01-23T16:36:21.1141328+08:00;</History> <History>True|2024-06-18T03:37:53.3986849Z;True|2024-06-18T11:21:56.8035265+08:00;True|2024-06-18T11:21:19.5434721+08:00;True|2024-06-18T11:21:01.1589956+08:00;True|2024-06-18T11:13:38.3624463+08:00;True|2024-06-18T11:10:28.0508856+08:00;True|2024-06-18T10:39:23.0033920+08:00;True|2024-06-18T10:28:08.9658896+08:00;True|2024-06-17T14:46:33.2307641+08:00;True|2024-05-20T17:56:34.6581491+08:00;True|2024-04-23T17:02:36.4793408+08:00;True|2024-04-15T15:24:50.3598281+08:00;True|2024-04-15T15:24:34.0374231+08:00;True|2024-01-25T17:09:07.9161603+08:00;True|2024-01-23T18:28:01.1220581+08:00;True|2024-01-23T16:36:21.1141328+08:00;</History>
<LastFailureDetails /> <LastFailureDetails />
</PropertyGroup> </PropertyGroup>
</Project> </Project>