private void DealSqlResp(EventHReceiveArgs e) { try { int Type = BitConverter.ToInt32(e.DataPack, 4); string s = System.Text.Encoding.UTF8.GetString(e.DataPack, 8, e.DataPack.Length - 8); Debug.Log(s); switch (Type) { case TcpCmdID.SYS_DOWN_USER_INFO: //Debug.Log("DealSqlResp-SYS_DOWN_USER_INFO"); DealDownUserInfo(s); break; case TcpCmdID.GAS_DOWN_CUSTOMER_Last_AtTime: //Debug.Log("DealSqlResp-GAS_DOWN_CUSTOMER_Last_AtTime"); /* <NewDataSet> <Table> <Column1>2015-07-29T17:54:46.56+08:00</Column1> </Table> </NewDataSet> */ XmlDocument xml = new XmlDocument(); xml.LoadXml(s); XmlNode node = xml.SelectSingleNode(@"/NewDataSet/Table/Column1"); if (node != null) { MaxCustomerAtTimeSvr = Convert.ToDateTime(node.InnerText); SendDownCustomerInfo(); } break; case TcpCmdID.GAS_DOWN_CUSTOMER_INFO: Debug.Log("DealSqlResp-GAS_DOWN_CUSTOMER_INFO"); DealDownCustomerInfo(s); break; default: Debug.Log("DealSqlResp-" + Type); //if (OnRecvSqlResp != null) OnRecvSqlResp(this, e1); break; } } catch (Exception ex) { Debug.Log(String.Format("接收失败!\t{0},{1}", "其他数据", ex.Message)); } }
private void HReceiveCallback2(IAsyncResult ar) { try { StateObject state = (StateObject)ar.AsyncState; NetworkStream netStream = state.NetStream; int bytesRead = 0; bytesRead += netStream.EndRead(ar); for (int i = 0; i < 50; i++) { if (bytesRead < state.Buffer.Length) { bytesRead += state.NetStream.Read(state.Buffer, bytesRead, state.Buffer.Length - bytesRead); } else break; } if (bytesRead == state.Buffer.Length) { //接收到数据给出消息 //Debug.Log("接收到数据给出消息"); EventHReceiveArgs e = new EventHReceiveArgs(); e.DataPack = state.Buffer; if(OnHReceive!=null) { OnHReceive(this, e); } needACK = false; //继续接收 HReceive(); } else { throw new Exception("数据包体字节数不足!"); } } catch (IOException ex) //故障检查点 200 { Debug.Log("HTcpClient.HReceiveCallback2().200"); //WriteErrorLog(ex, "HTcpClient.HReceiveCallback2().200"); DisConnect(); } catch (Exception ex) //故障检查点 500 { Debug.Log("HTcpClient.HReceiveCallback2().500"); } }
private void HTcpEPClient_OnHReceive(object sender, EventHReceiveArgs e) { try { int CmdID = BitConverter.ToInt32(e.DataPack, 0); long ticks = 0; int result = 0; string sql = ""; switch (CmdID) { case TcpCmdID.SQL_EXE_RESP: DealSqlResp(e); break; case TcpCmdID.SYS_ACK: //Debug.Log("SYS_ACK"); //StatusEvent("收到心跳包检测!", ""); break; case TcpCmdID.SYS_DATETIME_SYNC_RESP: Debug.Log("SYS_DATETIME_SYNC_RESP"); //DealSyncDatetimeResp(e); break; case TcpCmdID.GAS_UP_GPGZ_SEND_RESP: Debug.Log("SYS_DATETIME_SYNC_RESP"); ticks = BitConverter.ToInt64(e.DataPack, 4); sql = string.Format("delete from GPGZSubmit where ticks = {0}", ticks); result = App.Instance.data.connection.Execute(sql); if(result==0) { Debug.Log("发送钢瓶罐装信息给服务器后-删除钢瓶错误:" + ticks); } break; case TcpCmdID.GAS_UP_GPCK_SEND_RESP: Debug.Log("GAS_UP_GPCK_SEND_RESP"); ticks = BitConverter.ToInt64(e.DataPack, 4); sql = string.Format("delete from GPCKSubmit where ticks = {0}", ticks); result = App.Instance.data.connection.Execute(sql); if(result==0) { Debug.Log("发送钢瓶出库信息给服务器后-删除钢瓶错误:" + ticks); } break; case TcpCmdID.GAS_UP_GP_SEND_RECV: Debug.Log("===============GAS_UP_GP_SEND_RECV============="); long SeqID = BitConverter.ToInt64(e.DataPack, 4); sql = string.Format("delete from GPSendRecvSubmit where SeqID = {0}", SeqID); result = App.Instance.data.connection.Execute(sql); if(result==0) { Debug.Log("发送钢瓶发货和回收信息给服务器后-删除钢瓶错误:" + SeqID); } break; case TcpCmdID.GAS_UP_GP_TH: Debug.Log("GAS_UP_GP_TH"); //ticks = BitConverter.ToInt64(e.DataPack, 4); //sql = string.Format("delete from GPTHSubmit where ticks = {0}", ticks); //hDbRecv.QueryAction(sql); break; } } catch (Exception ex) { Debug.Log("接收数据处理失败--"+ ex.Message); } }