public void initialize(int capacity) { MaxConnectedClientLimit = capacity; socketListener = new SocketListener(capacity, (int)TCPCmdPacketSize.RECV_MAX_SIZE); socketListener.SocketClosed += SocketClosed; socketListener.SocketConnected += SocketConnected; socketListener.SocketReceived += SocketReceived; socketListener.SocketSended += SocketSended; _tcpClientPool = TCPClientPool.getInstance(); _tcpClientPool.initialize(100); _tcpLogClientPool = TCPClientPool.getLogInstance(); _tcpLogClientPool.initialize(100); tcpInPacketPool = new TCPInPacketPool(capacity); /*tcpOutPacketPool = new TCPOutPacketPool(capacity);*/ TCPOutPacketPool.getInstance().initialize(capacity); tcpOutPacketPool = TCPOutPacketPool.getInstance(); dictInPackets = new Dictionary <TMSKSocket, TCPInPacket>(capacity); tcpSessions = new Dictionary <TMSKSocket, TCPSession>(); TCPCmdDispatcher.getInstance().initialize(); #if UseTimer taskExecutor = new ScheduleExecutor(0); #else taskExecutor = new ScheduleExecutor(1); #endif taskExecutor.start(); }
/// <summary> /// 透传到DBServer处理 /// </summary> /// <param name="socket"></param> /// <param name="nID"></param> /// <param name="data"></param> /// <param name="count"></param> /// <returns></returns> public TCPProcessCmdResults transmission(TMSKSocket socket, int nID, byte[] data, int count) { string cmdData = null; try { cmdData = new UTF8Encoding().GetString(data, 0, count); } catch (Exception) //解析错误 { LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket))); return(TCPProcessCmdResults.RESULT_FAILED); } // GameClient client = GameManager.ClientMgr.FindClient(socket); // if (null == client) // { // LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket))); // return TCPProcessCmdResults.RESULT_FAILED; // } try { byte[] bytesData = Global.SendAndRecvData(TCPClientPool.getInstance(), TCPOutPacketPool.getInstance(), data, count, nID); if (null == bytesData) { LogManager.WriteLog(LogTypes.Error, string.Format("与DBServer通讯失败, CMD={0}", (TCPGameServerCmds)nID)); return(TCPProcessCmdResults.RESULT_FAILED); } Int32 length = BitConverter.ToInt32(bytesData, 0); Int16 cmd = BitConverter.ToInt16(bytesData, 4); TCPOutPacket tcpOutPacket = TCPOutPacketPool.getInstance().Pop(); tcpOutPacket.PacketCmdID = (Int16)cmd; tcpOutPacket.FinalWriteData(bytesData, 6, length - 2); //client.sendCmd(tcpOutPacket); TCPManager.getInstance().MySocketListener.SendData(socket, tcpOutPacket); return(TCPProcessCmdResults.RESULT_OK); } catch (Exception ex) { // 格式化异常错误信息 DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(socket), false); } return(TCPProcessCmdResults.RESULT_FAILED); }
public void initialize(int capacity) { this.MaxConnectedClientLimit = capacity; this.socketListener = new SocketListener(capacity, 6144); this.socketListener.SocketClosed += this.SocketClosed; this.socketListener.SocketConnected += this.SocketConnected; this.socketListener.SocketReceived += this.SocketReceived; this.socketListener.SocketSended += this.SocketSended; this._tcpClientPool = TCPClientPool.getInstance(); this._tcpClientPool.initialize(100); this._tcpLogClientPool = TCPClientPool.getLogInstance(); this._tcpLogClientPool.initialize(100); this.tcpInPacketPool = new TCPInPacketPool(capacity); TCPOutPacketPool.getInstance().initialize(capacity); this.tcpOutPacketPool = TCPOutPacketPool.getInstance(); this.dictInPackets = new Dictionary <TMSKSocket, TCPInPacket>(capacity); this.tcpSessions = new Dictionary <TMSKSocket, TCPSession>(); TCPCmdDispatcher.getInstance().initialize(); this.taskExecutor = new ScheduleExecutor(0); this.taskExecutor.start(); }