void ClientPost(object Msg) { CounterSendMsg initMsgNow = (CounterSendMsg)Msg; string strEncCode = CryptoModule.encrypt(initMsgNow.strSendMsg.ToString().Trim()); string strReturnData = string.Empty; lock (lockerPost) { try { initMsgNow.strSendMsg = initMsgNow.bMultiFlag ? initMsgNow.strSendMsg : ""; strReturnData = Post(VarGlobal.ServerUrl.ToString().Trim(), strEncCode.ToString().Trim(), initMsgNow.strSendMsg.ToString().Trim()); LogHelper.WriteLog("SendResult " + strReturnData.Replace("\r\n", "-")); } catch (OutOfMemoryException ex) { LogHelper.WriteLog("OutOfMemoryException post " + initMsgNow.strSendMsg + ex.ToString()); } catch (Exception ex) { AppLog.Fatal("ClientPost " + ex.ToString()); LogHelper.WriteLog("Exception ClientPost " + ex.ToString()); } } }
void ClientPost(object Msg) { CounterSendMsg initMsgNow = (CounterSendMsg)Msg; string strEncCode = CryptoModule.encrypt(initMsgNow.strSendMsg.ToString().Trim()); string strReturnData = string.Empty; lock (lockerPost) { try { initMsgNow.strSendMsg = initMsgNow.bMultiFlag ? initMsgNow.strSendMsg : ""; strReturnData = Post(VarGlobal.ServerUrl.ToString().Trim(), strEncCode.ToString().Trim(), initMsgNow.strSendMsg.ToString().Trim()); LogHelper.WriteLog("SendResult " + strReturnData.Replace("\r\n", "-")); } catch (Exception ex) { //string bufret1 = (ex.Message.ToString() // + strReturnData + "/r/n" // + strEncCode + "/r/n" // + m_VtmUrl.ToString().Trim()); //string bufret = (ex.Message.ToString() + "/r/n" // + strReturnData + "/r/n" // + strEncCode + "/r/n" // + m_VtmUrl.ToString().Trim()); //showApiData(bufret, richApiLog); } } }
/// <summary> /// 过滤器后 进入该方法 /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> protected override void ExecuteCommand(UdpSession session, MyUdpRequestInfo requestInfo) { if (requestInfo.Key.Contains(HandleUdpUtils.C_SESSION_KEY) || requestInfo.Key.Contains(HandleUdpUtils.H_SESSION_KEY) || requestInfo.Key.Contains(HandleUdpUtils.T_SESSION_KEY)) { if (requestInfo.TerminalCounterData.TranType == 10) { LogHelper.WriteLog(DateTime.Now.ToString() + " " + requestInfo.Key + ": HeartBeat success " + session.NickName); string strReaderCode = requestInfo.TerminalCounterData.ReaderID; string SnDate = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now).Substring(3, 10); string strHeartbeat = string.Empty; strHeartbeat += "at=TDATA"; //-----1 数据类型 --- strHeartbeat += ("&sn=" + (SnDate)); //-----1 通信序列号--- strHeartbeat += ("&ti=" + (strReaderCode)); //-----1 reader id---- strHeartbeat += ("&lst=" + (string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now).Substring(0, 14))); //-1 最终shot 时间--- strHeartbeat += ("&ip=" + (VarGlobal.DeviceIP)); //---1 通信接收时间--生成此命令时间 LogHelper.WriteLog("Heart " + requestInfo.Key + "~" + requestInfo.SessionID + "~" + strHeartbeat); try { CounterSendMsg cntMsg = new CounterSendMsg(); cntMsg.bMultiFlag = false; cntMsg.strSendMsg = strHeartbeat; //startThreadSend(cntMsg);//Heart data Task task = Task.Factory.StartNew(() => ClientPost(strHeartbeat)); } catch (OutOfMemoryException ex) { LogHelper.WriteLog("OutOfMemoryException 10 Code" + ex.ToString()); } catch (Exception ex) { string strex = ex.ToString(); AppLog.Error(requestInfo.SessionID + " 10 Code " + strex); LogHelper.WriteLog("Exception 10 Code" + ex.ToString()); } } else if (requestInfo.TerminalCounterData.TranType == 46) { LogHelper.WriteLog("Normal " + requestInfo.Key + "~" + requestInfo.SessionID + "~ " + session.NickName + " ~ " + requestInfo.TerminalCounterData.allParams); try { //strbuf46 = (m_strOneIDAllParam + "=============radio = 3 启动线程=== single =========="); //showApiData(VarGlobal.TokenKey, richApiLog); //showApiData(strbuf46, richApiLog); CounterSendMsg cntMsg = new CounterSendMsg(); cntMsg.bMultiFlag = false; cntMsg.strSendMsg = requestInfo.TerminalCounterData.allParams; //startThreadSend(cntMsg);//Counter Data Task task = Task.Factory.StartNew(() => ClientPost(requestInfo.TerminalCounterData.allParams)); } catch (OutOfMemoryException ex) { LogHelper.WriteLog("OutOfMemoryException 10 Code" + ex.ToString()); } catch (Exception ex) { string strex = ex.ToString(); AppLog.Error(requestInfo.SessionID + " 46 Code " + strex); LogHelper.WriteLog("Exception 46 Code" + ex.ToString()); //WriteLogFileName(strex, "StartThreadToSend"); //return -5; } } else { LogHelper.WriteLog("Error " + requestInfo.Key + "~" + requestInfo.SessionID + "~" + requestInfo.TerminalCounterData.allParams); } //if (requestInfo.Key.Contains("0123456")) //{ // session.Send("Server receive success - " + requestInfo.Key); //} //session.Send("hello"); } else { LogHelper.WriteLog(requestInfo.SessionID + "不存在该设备"); } }
void startThreadSend(CounterSendMsg initMsg) { Thread threadSend = new Thread(ClientPost); //创建了线程还未开启 threadSend.Start(initMsg); //用来给函数传递参数,开启线程 }