public void Receive() { byte[] receiveBuffer = new byte[_TcpClient.ReceiveBufferSize]; while (true) { int receiveLength = _TcpClient.GetStream().Read(receiveBuffer, 0, receiveBuffer.Length); if (receiveLength > 0) { Console.Write("接收:"); for (int i = 0; i < receiveLength; i++) { Console.Write("{0},", receiveBuffer[i]); } Console.WriteLine(); var resp = new BaseResp(receiveBuffer); if (!string.IsNullOrWhiteSpace(resp.Text)) { var lines = resp.Text.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { Console.WriteLine(line); } } } } }
public void BaseResp_Test() { byte[] arg = new byte[] { 1, 0, 1, 194, 0, 0, 0, 1, 40, 81, 112, 2, 27, 11, 49, 32, 15, 27, 77, 27, 14, 73, 79, 58, 35, 53, 88, 71, 120, 76, 108, 70, 120, 84, 36, 35, 40, 27, 15, 58, 32, 32, 32, 13, 32, 32, 32, 32, 32, 57, 27, 14, 84, 66, 27, 15, 50, 52, 27, 14, 72, 85, 27, 15, 32 ,27,98,13,30,27,98,3}; var r = new BaseResp(arg); var except = "上海地区天气预报: \r 9月24日 "; Assert.AreEqual(except, r.Text); }