private void tcpSession_DataReceived(object sender, DataEventArgs e) { AsyncTcpSession session = sender as AsyncTcpSession; byte[] tmpBuffer = e.Data; var buffer = new CGD.buffer(e.Data, 0, e.Length); int bufferLength = (int)buffer.extract_uint(); ushort bufferType = (ushort)buffer.extract_byte(); switch (bufferType) { case 1: pingStopwatch.Start(); session.Send(NcsTemplateBuffer.HeartbeatBuffer1); break; case 2: ping = (int)pingStopwatch.ElapsedMilliseconds; pingStopwatch.Reset(); break; } }