更换网络库
This commit is contained in:
parent
a8be0154ec
commit
fdf7c058ca
@ -20,12 +20,12 @@ namespace ClientCore.Network
|
||||
public NetworkHelper(ServerType serverType,long UID = -1)
|
||||
{
|
||||
//指定接收服务器数据事件
|
||||
OnDataCallBack += GetDataCallBack;
|
||||
OnReceiveData += GetDataCallBack;
|
||||
//断开连接
|
||||
OnClose += OnConnectClose;
|
||||
//网络库调试信息输出事件,用于打印连接断开,收发事件
|
||||
OnLogOut += NetworkDeBugLog;
|
||||
OnConnected += NetworkConnected;
|
||||
OnLogOut += NetworkDeBugLog;
|
||||
mServerType = serverType;
|
||||
mUID = UID;
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,24 +1,25 @@
|
||||
using AxibugProtobuf;
|
||||
using HaoYueNet.ServerNetwork;
|
||||
using HaoYueNet.ServerNetwork;
|
||||
using ServerCore.Common.Enum;
|
||||
using ServerCore.Event;
|
||||
using ServerCore.Manager;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace ServerCore.NetWork
|
||||
{
|
||||
public class IOCPNetWork : SocketManager
|
||||
public class IOCPNetWork : TcpSaeaServer
|
||||
{
|
||||
ServerType mServerType;
|
||||
public IOCPNetWork(int numConnections, int receiveBufferSize, ServerType serverType)
|
||||
: base(numConnections, receiveBufferSize)
|
||||
{
|
||||
mServerType = serverType;
|
||||
ClientNumberChange += IOCPNetWork_ClientNumberChange;
|
||||
OnClientNumberChange += ClientNumberChange;
|
||||
OnReceive += ReceiveData;
|
||||
OnDisconnected += OnDisconnect;
|
||||
OnNetLog += OnShowNetLog;
|
||||
}
|
||||
|
||||
private void IOCPNetWork_ClientNumberChange(int num, AsyncUserToken token)
|
||||
void ClientNumberChange(int num, AsyncUserToken token)
|
||||
{
|
||||
Console.WriteLine("Client数发生变化");
|
||||
}
|
||||
@ -29,7 +30,7 @@ namespace ServerCore.NetWork
|
||||
/// <param name="CMDID">协议ID</param>
|
||||
/// <param name="ERRCODE">错误编号</param>
|
||||
/// <param name="data">业务数据</param>
|
||||
public override void DataCallBack(AsyncUserToken token, int CMDID, byte[] data)
|
||||
void ReceiveData(AsyncUserToken token, int CMDID, byte[] data)
|
||||
{
|
||||
//DataCallBackToOld(token.Socket, CMDID, data);
|
||||
ServerManager.g_Log.Debug("收到消息 CMDID =>" + CMDID + " 数据长度=>" + data.Length);
|
||||
@ -37,30 +38,22 @@ namespace ServerCore.NetWork
|
||||
NetMsg.Instance.PostNetMsgEvent(CMDID, token.Socket, data);
|
||||
}
|
||||
|
||||
//public void DataCallBackToOld(Socket sk, int CMDID, byte[] data)
|
||||
//{
|
||||
// ServerManager.g_Log.Debug("收到消息 CMDID =>" + CMDID + " 数据长度=>" + data.Length);
|
||||
// try
|
||||
// {
|
||||
// //抛出网络数据
|
||||
// NetMsg.Instance.PostNetMsgEvent(CMDID, sk, data);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine("逻辑处理错误:" + ex.ToString());
|
||||
// }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 断开连接
|
||||
/// </summary>
|
||||
/// <param name="sk"></param>
|
||||
public override void OnClose(AsyncUserToken token)
|
||||
void OnDisconnect(AsyncUserToken token)
|
||||
{
|
||||
ServerManager.g_Log.Debug($"断开连接,ServerType->{mServerType} | {((IPEndPoint)token.Socket.LocalEndPoint).Address}");
|
||||
//ServerManager.g_ClientMgr.SetClientOfflineForSocket(token.Socket);
|
||||
//TODO 要删除不同的
|
||||
//要删除不同的
|
||||
EventSystem.Instance.PostEvent(EEvent.OnSocketDisconnect, mServerType, token.Socket);
|
||||
}
|
||||
|
||||
|
||||
void OnShowNetLog(string msg)
|
||||
{
|
||||
ServerManager.g_Log.Debug(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user