/// <summary> /// 从注册的解码集合中获取packet的解码方法 /// </summary> /// <param name="id"></param> /// <param name="stream"></param> /// <returns></returns> public T decode(uint id, MemoryStream stream, ref Packet packet) { if (packetDecoders.ContainsKey(id)) { PacketDecodeHandler <T> decodeHandler = packetDecoders[id] as PacketDecodeHandler <T>; if (decodeHandler == null) { //Log.Logger.warn(Log.Module.Network, "DecodeHandler cast from " + packetDecoders[id] + " is null"); Debug.Log("**************************************************************************1"); return(default(T)); } T p = decodeHandler.Invoke(stream, ref packet); Debug.Log("**************************************************************************=" + packet.Opcode + "】【" + packet.Option); return(p); } //Log.Logger.warn(Log.Module.Network, "do not exist decoder with msg type:" + id + ", ignore encode"); Debug.Log("**************************************************************************2"); return(default(T)); }
private void ProcessConnect(SocketAsyncEventArgs connectEventArgs) { if (connectEventArgs.SocketError != SocketError.Success) { this.OnError($"socket connect error, address:{this._ip}:{this._port}, code:{connectEventArgs.SocketError}"); this.Close(); return; } this.session.connection.socket = this.socket; this.session.connection.localEndPoint = this.socket.LocalEndPoint; this.session.connection.remoteEndPoint = this.socket.RemoteEndPoint; this.session.connection.recvBufSize = this.recvBufSize; this.session.connection.packetEncodeHandler = this.packetEncodeHandler; this.session.connection.packetDecodeHandler = this.packetDecodeHandler; this.session.connection.StartReceive(); this.socket = null; NetEvent netEvent = NetEventMgr.instance.pool.Pop(); netEvent.type = NetEvent.Type.Establish; netEvent.session = this.session; NetEventMgr.instance.Push(netEvent); }