/*public void send(byte framID, byte wayID) * { * byte[] data = new byte[4] { 0, 2, framID, wayID }; * send(data); * * }*/ //帧更新执行 public void Update() { lock (netStatusList) { //检查连接状态变动状态 if (netStatusList.Count > 0) { if (statusCallback != null) { //状态通知 statusCallback(netStatusList.First.Value); netStatusList.RemoveFirst(); } } } if (connected()) { try { //有数据要接收 while (tcpClient.Client.Available >= 2) //仍然有数据可以处理 { //NetLog.warin(this, "收到数据"); if (msgLen == 0) { tcpClient.Client.Receive(headBuffer); msgLen = ByteUtil.Byte2Int(headBuffer); //NetLog.warin(this, "receive data head length: " + this.msgLen); bodyBuffer = new byte[msgLen]; } else { if (tcpClient.Client.Available >= msgLen) //数据完整 { tcpClient.Client.Receive(bodyBuffer); //NetLog.warin(this, "Receive bodyBuffer success"); var netData = new NetData(bodyBuffer); AppNet.main.receiveNetMsg(netData); bodyBuffer = null; msgLen = 0; } else { break; //数据不完整-退出 下次update再处理 } } } } catch (Exception ex) { NetLog.error(this, "-Update() Socket接收数据出错," + ex); close(); } } else { if (netStatus.Equals(NetParams.LINK_OK)) { close(); } } }