/// <summary> /// 网络频道 /// </summary> /// <param name="socket">网络套接字</param> /// <param name="packer">拆包打包器</param> /// <param name="name">频道名字</param> public NetworkChannel(ISocket socket, IPacker packer, string name) { Guard.Requires <ArgumentNullException>(socket != null); Guard.Requires <ArgumentNullException>(packer != null); Guard.NotEmptyOrNull(name, "name"); Name = name; this.socket = socket; this.packer = packer; receiveState = new ReceiveState(packer); heartBeatState = new HeartBeatState(0); lastException = null; heartBeatState.OnMissHeartBeat += (count) => { if (OnMissHeartBeat != null) { OnMissHeartBeat.Invoke(this, count); } }; socket.On(SocketEvents.Connect, OnSocketConnect); socket.On(SocketEvents.Error, OnSocketError); socket.On(SocketEvents.Closed, OnSocketClosed); socket.On(SocketEvents.Message, OnSocketMessage); socket.On(SocketEvents.Disconnect, OnSocketDisconnect); socket.On(SocketEvents.Sent, OnSocketSent); }