/// <summary> /// 当关闭时 /// </summary> /// <param name="obj">socket对象</param> private void OnSocketClosed(object obj) { lock (heartBeatState) { heartBeatState.Reset(); } receiveState.Reset(); if (OnClosed != null) { OnClosed.Invoke(this, lastException); } }
/// <summary> /// 当接收到消息 /// </summary> /// <param name="obj">消息内容</param> private void OnSocketMessage(object obj) { var data = (byte[])obj; Exception ex; var packet = receiveState.Input(data, out ex); if (ex != null) { OnSocketError(ex); Disconnect(); return; } if (packet == null) { return; } lock (heartBeatState) { heartBeatState.Reset(); } if (OnMessage != null) { OnMessage.Invoke(this, packet); } }