private void InitRegister() { // 解释器 m_Netter.AddParser((int)Msg.G2C.CMD.AuthRsp, Msg.G2C.AuthRsp.Parser); m_Netter.AddParser((int)Msg.G2C.CMD.SmessageRsp, Msg.G2C.SMESSAGERsp.Parser); // 业务处理 m_Netter.AddReceiveDelegate((int)Msg.G2C.CMD.AuthRsp, ReceiverAuth); m_Netter.AddReceiveDelegate((int)Msg.G2C.CMD.SmessageRsp, ReceiverMessage); }
private void AcceptClient(IAsyncResult ar) { Socket socket = m_Socket.EndAccept(ar); ClientNetter clientNetter = new ClientNetter(socket); clientNetter.Id = (uint)(s_ClientAutoId++); Dictionary <int, MessageParser> .Enumerator parserEnumator = m_ReceiveParserDic.GetEnumerator(); while (parserEnumator.MoveNext()) { clientNetter.AddParser(parserEnumator.Current.Key, parserEnumator.Current.Value); } Dictionary <int, ServerMessageReceiveDelegate> .Enumerator delegateEnumator = m_ReceiveDelegateDic.GetEnumerator(); while (delegateEnumator.MoveNext()) { MessageReceiveDelegate callback = (message) => { ClientEndReceive(clientNetter.Id, message); }; clientNetter.AddReceiveDelegate(delegateEnumator.Current.Key, callback); } m_ClientDict.Add(clientNetter.Id, clientNetter); m_ClientList.Add(clientNetter); clientNetter.BeginReceive(); }