using System; using System.Security.Cryptography; using System.Net.Sockets; using System.Net; using System.Text; using System.Threading; using System.Collections; namespace CMPP.YOURCOMPANY {public delegate void ReportEventHandler (object sender, ReportEventArgs e); // declare an event refers to (pointer) public delegate void SMSEventHandler (object sender, SMSEventArgs e); // declare an event refers to (pointer) public delegate void TerminateEventHandler (object sender, TerminateEventArgs e); // declare receiving a termination signal public delegate void TerminateRespEventHandler (object sender, TerminateRespEventArgs e); // respond to the incident public delegate void TestEventHandler (object sender, TestEventArgs e); public delegate void TestRespEventHandler (object sender, TestRespEventArgs e); public delegate void ConnectRespEventHandler (object sender, ConnectRespEventArgs e); public delegate void CancelRespEventHandler (object sender, CancelRespEventArgs e); public delegate void SubmitRespEventHandler (object sender, SubmitRespEventArgs e); public delegate void QueryRespEventHandler (o bject sender, QueryRespEventArgs e); public delegate void LogonSuccEventHandler (object sender, EventArgs e); // if successful login public delegate void SocketClosedEventHandler (object sender, EventArgs e); // detected when the socket is closed public delegate void FailediteMdeeteDeventHandler (Object Sender, WaitingQueueItem (// When a waiting queue is more than 60 seconds without response
Public Delegate Void CMPPClientSvcStopeventHandler (Object Sender, ClientQueuestoteRgs E); // Trigger events when CMPP service is stopped
///
// private function area // private Socket tcp = null; private IPHostEntry ip = null; private IPEndPoint cmpp_ep = null; private int RecvTimeOut = 1000; // 2000ms receiving timeout private int SendTimeout = 2000; // 2000ms transmission timeout private String cmpp_server = ""; // Mobile server IP or DNS name private string systemid = ""; // Enterprise number private string username = ""; // sp = ""; // Password bool isstop = false; // This service is terminated to terminate the private bo = false; // Have you logged in to the private thread send_thread; // Send thread, specifically handle the mobile data package private thread recv_thread; // Special handled reception PRIVATE THREAD DEAMO_THREAD; / / Monitoring Thread Private String ErrorInfo = ""; // Store the last occurrence error message or reference information private datetime _current_time = datetime.now; // Last Ping time private uint lastsequence; // Water water number, each time need restart reset lastSequence private SortedList _outSeqQueue = new SortedList (); // store the QueueItem message queue, transmit queue state storage private SortedList _waitingSeqQueue = new SortedList (); // store QueueItem private message queue INT sub_resp = 0; // last return package sequence private datetime _lastoktime; // finally send message time private bool _bnre = false; // empty reference error, socket error // private manualReveTevent _ConnectionDone = new manualReveTevent (false); // Whether to connect to the socket server, that is, the CMPP server // private manualRetevent _lastsendddone = new manualResetEvent (false); // Last transmission is over // private manualReveTevent _lastRecvdone = new manualReseTevent (false); // Last reception Private void ping () // Send a PING package, unreasonable to store directly in Out Queue {uint seq = this.getnextsequence (); msg.cmpp_msg_test test = new msg.cmpp_msg_test (seq); queueItem Q =
New QueueItem (SEQ, (UINT) msg.cmpp_command_id.cmpp_active_test, 0,0); q.SETMSGOBJ (TEST); this.addTooutQueue (});} private string getValidtime (datetime d) // Return to SMS Savory {DateTime N = D. ADDHOURS (2); // 2 hours Return (n.year.tostring (). Substring (2) n.month.tostring (). Padleft (2, '0') n.day.tostring ( .Padleft (2, '0') n.Hour.toString (). Padleft (2, '0') n.minute.toString (). Padleft (2, '0') n.second.toString () .Padleft (2, '0') "032 ");} private bool ispingTime () // Whether to go to Ping once {System.TimeSpan L = (DateTime.Now - this._current_time); if ( l.TotalSeconds> = (CMPPClient.CMPP_ACTIVE_TEST_C_TICKs)) {lock (this) {this._current_time = DateTime.Now; return (true);}} else {return (false);}} private void checkReSend () // need Once again ping // Query _waitingseqqueue does not have the last message {// survey all messages in Waiting Queue, if the income time exceeds 60 for (int i = 0; I
} Else {// can try to continue Q.INQUEETIME = this_time; q.FailedCount ; q.msgState = (int) msg_state.sended_waitting; this.sendqueueItem (q);}}}}} private void startthreads ()} Deamo_Thread = new Thread (new ThreadStart (this.DeamonThread)); Deamo_Thread.Start ();} private QueueItem newQueueItem (int msgtype, int msgstate, object msg) // object instance generating a message queue members {uint seq = this.getNextSequence (); // QueueItem Q = New QueueItem (SEQ, (UINT) MSGTYPE, 0, MSGState; Q.SETMSGOBJ (MSG); // Setting Message is Object Return (Q);} Private QueueItem GetQueItem (uint SEQ) // Get the message item {Lock (this) {return ((QueueItem) this._outseqqueiety [seq]);}}}}}}}}}}}}}}}}}}}}}}}}}}} }.com This._waitingseqqueue [seq]);} private void addttooutqueue (QueueItem Q) {Lock (this) {this._outseqqueue.add (q.sequence, q);}} private void addttowaitingQueue (Queuei Tem Q) {Lock (this) {if (! this._waitingseqqueue.containskey (q.sequence)) {this._waitingseqqueue.add (q.sequence, q);}}} private queueItem gettopoutqueue () // need to take Judgment {for (int i = 0; i New arraylist (); QueueItem Q = gettopoutqueue (); while (q! = null || arrlength <= 16) {if (q! = null) {RearR.Add (q); arrlength ;} else {Break;} Q = getTOPOUTQUEUE ();} if (arrlength> 0) {RETURN (REARR);} else {return (null);}} private void Delfromoutqueue (this) {this._outseqqueue.remove (Q.SEquence) );}} private void delFromOutQueue (uint seq) {lock (this) {this._outSeqQueue.Remove (seq);}} private void delFromWaitingQueue (QueueItem q) {lock (this) {this._waitingSeqQueue.Remove (q.Sequence );}} private void delFromWaitingQueue (uint seq) {this._waitingSeqQueue.Remove (seq);} private void SendLogin (string SystemID, string spNum, string Password) {// login authentication packet sent systemID = SystemID; userName = spNum; Password = password; uint seq = this.getNextSequence (); // get a water number msg.cmpp_msg_connect cn = new msg.cmpp_msg_connect (seq); cn.password = pass Word.trim (); cn.sourceAdd = systemid.trim (); tcp.send (cn.tobytes ());} private byte [] prepairPKs (QueueItem outitem) // sent to QueueItem {uint seq = outitem.Sequence; uint msgtype = outitem.MsgType; switch (msgtype) {case (uint) MSG.CMPP_COMMAND_ID.CMPP_ACTIVE_TEST: MSG.CMPP_MSG_TEST test = (Msg.cmpp_msg_test) OutItem.getmsgobj (); // Remove Lock (this) {OutItem.msgState = (int) msg_state.sending; this.delfromoutqueue; this.addtowaitingQueue (OutItem); // Waiting active_TEST_resp server} outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING; return (test.toBytes ()); case (uint) MSG.CMPP_COMMAND_ID.CMPP_ACTIVE_TEST_RESP: MSG.CMPP_MSG_TEST_RESP test_reply = (MSG.CMPP_MSG_TEST_RESP) outitem.getMsgObj (); // Remove / / Remove the specific message required for send queue Lock (this) {OUTITEM.MSGSTATE = (int)) {OutItem.ssgState = (int));} outitite.ssgState = (int)) msg_state.sending_finished; / / Complete return (Test_reply.tobytes ()); case (uint) msg.cmpp_command_id.cmpp_cancel: msg.cmpp_msg_can CEL cancel = (MSG.CMPP_MSG_CANCEL) outitem.getMsgObj (); // restore the message type lock (this) {outitem.MsgState = (int) MSG_STATE.SENDING; this.delFromOutQueue (seq); this.addToWaitingQueue (outitem); // wait for a response} outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING; return (cancel.toBytes ()); case (uint) MSG.CMPP_COMMAND_ID.CMPP_DELIVER_RESP: MSG.CMPP_MSG_DELIVER_RESP deliver_resp = (MSG.CMPP_MSG_DELIVER_RESP) outitem.getMsgObj () ; // Take it in the send queue; Lock (this) {OutItem.msgState = (int) msg_state.sending; this.delfromoutqueue (seq);} OutItem.msgState = (int) msg_state.sending_finished; // Complete Return (Deliver_ReSP. Tobytes ()); case (uint) MSG.CMPP_COMMAND_ID.CMPP_QUERY: MSG.CMPP_MSG_QUERY query = (MSG.CMPP_MSG_QUERY) outitem.getMsgObj (); // send a queue removed; lock (this) {outitem.MsgState = (int) MSG_STATE.SENDING; this .delFromOutQueue (seq); this.addToWaitingQueue (outitem);} outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING; // wait for a response return (query.toBytes ()); case (uint) MSG.CMPP_COMMAND_ID.CMPP_SUBMIT: MSG. CMPP_MSG_SUBMIT submit = (MSG.CMPP_MSG_SUBMIT) outitem.getMsgObj (); // send a queue removed; lock (this) {outitem.MsgState = (int) MSG_STATE.SENDING; this.delFromOutQueue (seq); this.addToWaitingQueue (outitem) ;} outitem.MsgState = (int) MSG_STATE.SENDING_FINISHED; return (submit.toBytes ()); case (uint) MSG.CMPP_COMMAND_ID.CMPP_TERMINATE: MSG.CMPP_MSG_TERMINATE terminate = (MSG.CMPP_MSG_TERMINATE) outitem.getMsgObj (); // Take it in the send queue; Lock (this) {OutItem.msgState = (int) msg_state.sending; this.delfromoutqueue (SE q); this.addToWaitingQueue (outitem);} outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING; return (terminate.toBytes ()); case (uint) MSG.CMPP_COMMAND_ID.CMPP_TERMINATE_RESP: MSG.CMPP_MSG_TERMINATE_RESP terminate_resp = (MSG.CMPP_MSG_TERMINATE_RESP Outitem.getmsgobj (); // Take it in the send queue; Lock (this) {OutItem.msgState = (int) msg_state.sending; this.delfromoutqueue (seq);} OutItem.msgState = (int) msg_state.sending_finished; return (TERMINATE_RESP.TOBYTES ()); default: test = (MSG.CMPP_MSG_TEST) outitem.getMsgObj (); // send a queue extraction lock (this) {outitem.MsgState = (int) MSG_STATE.SENDING; this.delFromOutQueue (seq); this.addToWaitingQueue (outitem) ; // Waiting for the server's active_test_resp} OutItem.msgState = (int) msg_state.sended_waitting; return (Test.Tobytes ());}} private void sendQueueItem (QueueItem outitem) // sent to QueueItem {uint seq = outitem.Sequence; uint msgtype = outitem.MsgType; try {switch (msgtype) {case (uint) MSG.CMPP_COMMAND_ID.CMPP_ACTIVE_TEST: MSG.CMPP_MSG_TEST test = (Msg.cmpp_msg_test) OutItem.getmsgobj (); // Remove Lock (this) {OutItem.msgState = (int) msg_state.sending; this.delfromoutqueue; this.addtowaitingQueue (OutItem); // Waiting active_TEST_resp server} tcp.Send (test.toBytes ()); outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING; break; case (uint) MSG.CMPP_COMMAND_ID.CMPP_ACTIVE_TEST_RESP: MSG.CMPP_MSG_TEST_RESP test_reply = (MSG.CMPP_MSG_TEST_RESP) outitem. GETMSGOBJ (); // Remove / / Remove / / Remove the specific message required to send Lock (this) {OUTITEM.MSGSTATE = (int) msg_state.sending; this.delfromoutqueue (SEQ);} tcp.send (Test_reply.tobytes )); OUTITEM.MSGSTATE = (int) msg_state.sending_finished; // Complete Break; Case (uint) msg.cmpp_command_id .CMPP_CANCEL: MSG.CMPP_MSG_CANCEL cancel = (MSG.CMPP_MSG_CANCEL) outitem.getMsgObj (); // restore the message type lock (this) {outitem.MsgState = (int) MSG_STATE.SENDING; this.delFromOutQueue (seq); this. addToWaitingQueue (outitem); // wait for a response} tcp.Send (cancel.toBytes ()); outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING; break; case (uint) MSG.CMPP_COMMAND_ID.CMPP_DELIVER_RESP: MSG.CMPP_MSG_DELIVER_RESP deliver_resp = ( Msg.cmpp_msg_deliver_resp) OutItem.getmsgobj (); // Take it in the send queue; Lock (this) {OutItem.msgState = (int) msg_state.sending; this.delfromoutqueue (seq);} TCP.Tobytes () ); outitem.MsgState = (int) MSG_STATE.SENDING_FINISHED; // complete break; case (uint) MSG.CMPP_COMMAND_ID.CMPP_QUERY: MSG.CMPP_MSG_QUERY query = (MSG.CMPP_MSG_QUERY) outitem.getMsgObj (); // send a queue removed; Lock (this) {OUTITEM.MSGSTATE = (int) msg_state.sending; this.delfromoutqueue (SEQ); this.addtoWaitingQueue (OutItem);} tcp.send (query.tobytes ()); OutItem.msgState = (int) msg_state. SENDED_WAITTING; // wait for a response break; case (uint) MSG.CMPP_COMMAND_ID.CMPP_SUBMIT: MSG.CMPP_MSG_SUBMIT submit = (MSG.CMPP_MSG_SUBMIT) outitem.getMsgObj (); // send a queue removed; lock (this) {outitem.MsgState = (int) MSG_STATE.SENDING; this.delFromOutQueue (seq); this.addToWaitingQueue (outitem);} tcp.Send (submit.toBytes ()); outitem.MsgState = (int) MSG_STATE.SENDING_FINISHED; break; case (uint) Msg.cmpp_command_id.cmpp_terminate: msg.cmpp_msg_terminate Terminate = (msg.cmpp_msg_terminate) OutItem.getmsgobj (); // Send queue {OutItem.msgState = (int) msg_state.sending; this.delfromoutqueue (SEQ); this.addtowaitingQueue (OutItem);} if (this.tcpiscanuse ()) {tcp.send (Terminate.Tobytes )); outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING;} this.isStop = true; // notify other threads can withdraw from the break; case (uint) MSG.CMPP_COMMAND_ID.CMPP_TERMINATE_RESP: MSG.CMPP_MSG_TERMINATE_RESP terminate_resp = (MSG.CMPP_MSG_TERMINATE_RESP Outitem.getmsgobj (); // Take it in the send queue; Lock (this) {OutItem.msgState = (int) msg_state.sending; this.delfromoutqueue (seq);} tcp.send (); OutItem.msgState = (int) msg_state.sending_finished; break;} loglastoktime (datetime.now); // Record the current last message SOKET correct time} catch (socketexception se) {// Socket error this.ErrorInfo = THIS . Errorinfo "/ r / n" se.tostring ();} catch (nullreferenceException nre) {this._bnre = true; // Empty reference error this.errorinfo = this.Errorinfo "/ r / n" NRE.TOSTRING ();}} private bool tcpiscanuse () // Test whether the current TCP can be used {bool review = true; datetime t = datetime.now; timespan ts = t- this._lastoktime; if (ts.totalseconds> CMppClient. CMPP_ACTIVE_TEST_T_TICKs) // 60 seconds {reval = false; // unavailable} if (this._bNre) {reval = false;} return (reval);} private void _reStartRecvNSend () {Send_Thread = new Thread (new ThreadStart (this. SendSPMsgThread)); Send_Thread.Start (); Recv_Thread = new Thread (new ThreadStart (this.RecvISMGMsgThread)); Recv_Thread.Start ();} private void LogLastOkTime (DateTime lastoktime) {lock (this) {this._lastOkTime = lastoktime; // Set the last Success message interaction time}} private void defaultReportHandler () // province has reported the event handler {} private void defaultSMSHandler () {} private void defaultTeminateHandler () {} private void defaultTestEventHandler () {} private void defaultTestRespEventHandler () {} private void defaultTerminateEventHandler () {} private void defaultTerminateRespEventHandler () {} private void defaultCancelRespEventHandler () {} private void defaultQueryRespEventHandler () {} private void defaultConnectRespEventHandler () {QueueItem q = new QueueItem (this.getNextSequence (), (uint) MSG .Cmpp_command_id.cmpp_active_test, 0, (int) msg_state.new); Msg.cmpp_msg_test test = new msg.cmpp_msg_test (q.sequence); // Release the package in the past q.setmsgobj (TEST); this.addToOoutqueue (} private void defaultsubmitrespeventhandler () {} private void defaultClientStopEventHandler () {} private void rePortError (string info) {} private bool _init (string CMPPServer, int CMPPPort) {bool reVal = false; CMPP_Server = CMPPServer; CMPP_Port = CMPPPort; try {tcp = new Socket (AddressFamily.InterNetwork , SocketType.Stream, ProtocolType.Tcp); ip = Dns.GetHostByName (CMPP_Server); cmpp_ep = new IPEndPoint (ip.AddressList [0], CMPP_Port); tcp.Connect (cmpp_ep); // connected reVal = true;} catch (SocketException se) {ErrorInfo = "Socker Error:" se.ToString ();} return (reVal);} private uint getNextSequence () {lock (typeof (CMPPClient)) {try {lastSequence ;} catch (OverflowException ofe) {This.Errorinfo = this.Errorinfo "/ r / n" off.tostring (); lastsequence = uint.minvalue;} return (lastsequence);}} private void recsMGMSGTHREAD () // Processing ISMG message thread {whilele (! this.isstop) {Try {byte [] rbuf = new byte [10240]; // Result buffer BYTE [] RECV_TEMP = New Byte [1024]; // RECV temporary buffer int index = 0; int msglength = tcp.receive (rbuf); // blocking received // analysis received data msg.cmpp_msg_header header; //// = new msg.cmpp_msg_header (rbuf, index); // get a message why (index // The next stream sequence number Switch (header.command_id) {copy (uint) msg.cmpp_command_id.cmpp_active_test: // server is called THIRRORINFO "/ r / n" "received: CMPP_ACTIVE_TEST"; MSG.CMPP_MSG_TEST test = new MSG.CMPP_MSG_TEST (the_pk); seq = test.Sequence; // get sent over the serial number MSG.CMPP_MSG_TEST_RESP test_reply = new MSG.CMPP_MSG_TEST_RESP (seq); tcp. Send (Test_reply.tobytes ()); // Take a response package immediately, no need to enter the queue IF (this.ontesthandler! = Null) {TESTEVENTARGS E = New TESTEVENTARGS (TEST); onTestHandler (this, e);} else {DefaulttestementHandler ();} This.Errorinfo = this.Errorinfo "/ r / n" "send: cmpp_active_test_resp"; Break; case (uint) msg.cmpp_command_id.cmpp_active_test_resp: // server response message should be discarded no matter what this.ErrorInfo = this.Errorinfo "/ r / n" ("received: cmpp_active_test_resp"); msg.cmpp_msg_test_resp test_reply2 = new msg.cmpp_msg_test_resp (THE_PK); // Construction message SEQ = Test_reply2.sequ Ence; // Look for the message this.delfRomwaitingQueue (seq); // Delete the message in the waiting queue // clears the wait response queue IF (this.ontestResphandler! = null) {TestresPeventargs E = New TestresPeventArgs (Test_reply2); onTestRespHandler (this, e);} else {defaultTestRespEventHandler ();} break; case (uint) MSG.CMPP_COMMAND_ID.CMPP_CANCEL_RESP: this.ErrorInfo = this.ErrorInfo "/ r / n" ( "receive: CMPP_CANCEL_RESP") ; Msg.cmpp_msg_cancel_resp cardel_reply = new msg.cmpp_msg_cancel_resp (the_pk); // configuration message seq = cancel_reply.Sequence; this.delFromWaitingQueue (seq); if (! This.onCancelRespHandler = null) {CancelRespEventArgs e = new CancelRespEventArgs (cancel_reply); onCancelRespHandler (this, e);} else {defaultCancelRespEventHandler (); } BREAK; case (uint) msg.cmpp_command_id.cmpp_connect_resp: // Check the correctness of the message, clear waiting queue setting connection success sign this.Errorinfo = this.Errorinfo "/ r / n" ("received: CMPP_CONNECT_RESP "); MSG.CMPP_MSG_CONNECT_RESP cn_reply = new MSG.CMPP_MSG_CONNECT_RESP (the_pk); seq = cn_reply.Sequence; // acquired message seq if (this.onConnectRespHandler = null) {ConnectRespEventArgs e = new ConnectRespEventArgs (cn_reply);! onConnectRespHandler ( This, e);} else {defaultConnectrespeventHandler ();} if (cn_reply.isok) {this.islogin = true;} else {this.islogin = false;} TH Is.delfromwaitingQueue (SEQ); // Delete the waiting connection information package in the queue; case (uint) msg.cmpp_command_id.cmpp_deliver: // Check the message is correct, return to correct or failure immediately, correctly handle the status package, not The status package is saved to the Mo cache, indicates that the information is received, and the status package determines the cache message for message delivery processing this.Errorinfo = this.ErrorInfo "/ r / n" ("received: cmpp_deliver"); biconvert .Dumpbytes (the_pk, "c: //cmpp_deliver.txt"); // Reserved image msg.cmpp_msg_deliver deliver = new msg.cmpp_msg_deliver (THE_PK); SEQ = (uint) Deliver.ismgSequence; // The water flow number, You need to send a deliver_resp // one ISMG-> SP message msg.cmpp_msg_deliver_resp Deliver_Resp = new msg.cmpp_msg_deliver_resp (seq); Deliver_resp.msgid = Deliver.msgid; Deliver_resp.result = 0; Byte [] T = Deliver_resp.tobytes (); TCP.SEND (T); this.Errorinfo = this.ErrorInfo "/ r / n" ("Send : CMPP__DELIVER_RESP "); if (Deliver.IsReport) {// Remove message // report message in the waiting queue // Report message has been sent correctly to // uint64 reportmsgid = DELIVER.ReportMsgID; // get a message ID, update Msgid string statereport = Deliver.StateReport ; // get the status of this message // _ debugbs (THE_PK); ReportEventArgs arg = new reportEventArgs (THE_PK, MSG.cMPP_MSG_HEADER.HEADERLENGTH 8 1 1 1 1 1 21 1); / / Construct Report Event Parameters // ReportEventArgs Arg = New ReportEventArgs (ReportMsgid.toString (), IF (this.onReportHandler! = NULL) // ReportEventArgs passed byte array is the data of the report packet, here does not consider multiple reports case {onReportHandler (this, arg);} else {this.defaultReportHandler ();}} else {// SMSEventArgs deliver packets transmitted across SMSEventArgs smsarg = new SMSEventArgs (the_pk, MSG.CMPP_MSG_Header.HeaderLength); IF (this.onsmshandler! = null) {onsmshandler (this, smsarg); // Trigger event, you should end the process quickly, do not rely on the considering of the resource-consuming resource,} else {defaultsmshandler ();}} Break; Case; (uint) msg.cmpp_command_id.cmpp_query_resp: this.Errorinfo = this.ErrorInfo "/ r / n" ("received: cmpp_query_resp"); // Receive a message, save the database msg.cmpp_msg_query_resp query_resp = new Msg.cmpp_msg_query_resp (THE_PK); this.delfromwaitingQueue (query_resp.sequence); // Wait to the elements in the queue to delete IF (this.onqueryResphandler! = null) {QueryRespEventArgs e = new QueryRespEventArgs (query_resp);} else {defaultQueryRespEventHandler ();} break; case (uint) MSG.CMPP_COMMAND_ID.CMPP_SUBMIT_RESP: // server receives the delivery message Hye-young this.ErrorInfo = this.ErrorInfo "/ r / n" ( "receive: CMPP_SUBMIT_RESP"); MSG.CMPP_MSG_SUBMIT_RESP submit_resp = new MSG.CMPP_MSG_SUBMIT_RESP (the_pk); BIConvert.DumpBytes (the_pk, "c: //CMPP_SUBMIT_RESP.txt"); // reserved Image //biconvert.dumpbytes( InitValue, "C:TXT"; // Reserved Image Sub_RESP ; // This variable is only for testing using delFromWaitingQueue (Submit_resp.sequence); // Remove message if you need to wait ! this.onSubmitRespHandler = null) {SubmitRespEventArgs e = new SubmitRespEventArgs (submit_resp); // submit_resp onSubmitRespHandler (this, e);.} else {defaultSubmitRespEventHandler ();} break; case (uint) MSG.CMPP_COMMAND_ID.CMPP_TERMINATE: this. Errorinf o = this.ErrorInfo "/ r / n" "receive: CMPP_TERMINATE"; MSG.CMPP_MSG_TERMINATE terminate = new MSG.CMPP_MSG_TERMINATE (the_pk); seq = terminate.Sequence; MSG.CMPP_MSG_TERMINATE_RESP terminate_resp = new MSG.CMPP_MSG_TERMINATE_RESP (seq ); This.errorinfo = this.Errorinfo "/ r / n" "received: cMpp_terminate_resp"; tcp.send (Terminate_resp.tobytes ()); if (this.OnterminateHandler! = Null) {TerminateEventArgs E = New TerminateEventArgs (TERMINATE); OnterminateHandler (this, E); this.stopme (); // Prepare yourself stop?} Else {defaultterminateEventHandler ();} this._stopme (); // Send a termination set return; // Exit Thin Case (uint) msg.cmpp_command_id.cmpp_terminate_resp: this.ErrorInfo = this.ErrorInfo "/ r / n" "receive: CMPP_TERMINATE_RESP"; MSG.CMPP_MSG_TERMINATE_RESP ter_resp = new MSG.CMPP_MSG_TERMINATE_RESP (the_pk); seq = ter_resp.Sequence; // obtain water signal this.delFromOutQueue (seq); // delete the output table key items if (! this.onTerminateRespHandler = null) {TerminateRespEventArgs e = new TerminateRespEventArgs (ter_resp); onTerminateRespHandler (this, e);} else {defaultTerminateRespEventHandler ();} this._StopMe (); break;}} LogLastOkTime (DateTime. NOW); // Record the current last message SOKET correct time} catch (socketexception se) {// timeout} thread.sleep (50);}} // debug // private void _debugbs (byte [] THE_PK) // Storage Byte byte // {// //} // debug private void deamonthread () // Monitor this system connection Normal {// This thread is the monitoring thread int T_count = 0; // cycle time count _RestartRecvnsend (); // Start reception and sending while (! {t_count ; //0.1 seconds if (TCPiscanuse ()) {if (this.IspingTime ()) {this.ping (); // Send a ping package} if (t_count> 50) // 500 * 100 = 50000 = 50 second {t_count = 0; checkresend (); // Check the message you need to resend // trigger an event, let the system automatically check the message queue, store the message status in the message queue}} else {Eventargs E = New Eventargs (); if (this.onnesocketclosedhandler! = null) {OnsetCloseDHandler (this, e);} else {} this.isstop = true; // Notify other threads exit} thread.sleep (1000);}} private void sendspmsgthread () {while (! This.isstop) {thread.sleep (10); if (this.islogin) {ArrayList Lists = this.gettop16queue (); // Remove 16 of the top message if (Lists! = Null && lists.count> 0) {int count = lists.count; arraylist pks = new arraylist (count); // Define capacity for (INT i = 0; i Private void _Stopme () {lock (this) {this.isstop = true;}} private void _forcedSubthread (thread t) // Force stop thread {TRY {T.Abort (); t.join ();} catch (Exception ) {}} // private function area // // Public function attribute area public bool init (String cmppserver, int cMpport) {return (this._init (cmppserver, cmpport);} public bool init (String Cmppserver, int CMpport) , int recvtimeout, int sendtimeout) {this.RecvTimeOut = recvtimeout; this.SendTimeout = sendtimeout; return (this._init (CMPPServer, CMPPPort));} public bool Init (string CMPPServer, int CMPPPort, int recvtimeout) {this.RecvTimeOut = recvtimeout; this.SendTimeout = recvtimeout; return (this._init (CMPPServer, CMPPPort));} public bool Login (string SystemID, string UserName, string Password) {try {SendLogin (SystemID, UserName, Password); this.LogLastOkTime (DateTime.now); // Last corrective send} catch (socketexception se) {// send error this.Errorinfo = this.ErrorInfo "/ r / n" se.tostrin g (); return (false);} DateTime T1 = DATETIME.NOW; while (! this.islogin) {byte [] rbuf = new byte [400]; int L; try {l = tcp.receive (RBUF); if (l> 16) {if (BIConvert.Bytes2UInt (rbuf, 4) == (uint) MSG.CMPP_COMMAND_ID.CMPP_CONNECT_RESP) {MSG.CMPP_MSG_CONNECT_RESP resp = new MSG.CMPP_MSG_CONNECT_RESP (rbuf); if (resp.isOk) {EventArgs E = New Eventargs (); if (OnLogonsucceventHandler! = null) {OnLogonsucceventLer (this, e);} else {this.defaultConnectrespeventHandler ();} this.islogin = true;} else {} Break; }}}} This._lastoktime = datetime.now; // Update the time of the current last successful transceiver socket} catch (socketexception) {} system.timespan t = datetime.now - t1; if (t.totalseconds> 10) {Break }}} If (this.islogin) {// Login OK, immediately send an Active_Test package this.Errorinfo = this.Errorinfo "/ r / n" "Logon Succ!"; StartThreads (); // Start Monitor de program thread return (true);} else {return (false);}} public uint SubmitSMS (string to_user, string fee_code, string svc_code, string fee_user, string spnum, string content, int fee_usertype) {MSG.CMPP_MSG_SUBMIT sndmsg; uint seq = this.getNextSequence (); // get next sequence sndmsg = new MSG.CMPP_MSG_SUBMIT (seq); sndmsg.FeeCode = fee_code; sndmsg.FeeTerminalId = to_user; sndmsg.FeeType = MSG.FeeType.FEE_TERMINAL_PERITEM; // Article charged sndmsg.FeeUserType = fee_usertype; sndmsg.Msg_Level = 0; sndmsg.MSGFormat = (uint) MSG.Msg_Format.UCS2; sndmsg.SMS_Content = content; sndmsg.SrcID = spnum; // long number sndmsg.SPID = this.systemID; s ndmsg.Svc_Code = svc_code; sndmsg.UDHI = 0; sndmsg.ValIdTime = getValIdTime (DateTime.Now); // survival time sndmsg.addTerminalID (to_user); QueueItem q = new QueueItem (seq, (uint) MSG.CMPP_COMMAND_ID.CMPP_SUBMIT , 0, 0); q.SETMSGOBJ (SNDMSG); this.addToOutqueue (q); return (SEQ);} public uint sendmsg (String to_user, string fee_user, string fee, string svcode, string content, string spnum) {uint seq = this.getNextSequence (); MSG.CMPP_MSG_SUBMIT sndmsg = new MSG.CMPP_MSG_SUBMIT (seq); sndmsg.FeeCode = fee; sndmsg.FeeType = MSG.FeeType.FEE_TERMINAL_PERITEM; sndmsg.FeeTerminalId = fee_user; Sndmsg.FeeUsertype = (int) msg.FeeUsertype.Fee_null; // Billing Sndmsg.SPID = this.systemID; // Corporate code SNDMSG.UDHI = 0; // sndmsg.msgformat = (uint) MSG.Msg_Format.GB2312; sndmsg.SMS_Content = content; sndmsg.SrcID = spnum; sndmsg.Svc_Code = svccode; sndmsg.addTerminalID (to_user); QueueItem q = new QueueItem (seq, (uint) MSG.CMPP_COMMAND_ID.CMPP_SUBMIT, 0, 0); q.SETMSGOBJ (SNDMSG); this.addToOutQueue (q); return;} public uint sendSMC (String Fee_user, string feecode, string svccode) // Send a monthly billing information to billing users {uint seq = this.getNextSequence (); MSG.CMPP_MSG_SUBMIT sndmsg = new MSG.CMPP_MSG_SUBMIT (seq); sndmsg.SMS_Delivery_Type = 2; // generate monthly SMC sndmsg.FeeCode = feecode; sndmsg.FeeType = MSG.FeeType.FEE_TERMINAL_MONTH; // Month metrics = feE_User; Sndmsg.FeEusertype = (int) msg.FeeUsertype.Fee_terminal_id; // Billing Sn 3Msg.SPID = this.systemID; // Corporate code SNDMSG.UDHI = 0; // sndmsg.msgformat = (uint) msg.m sg_Format.UCS2; sndmsg.SMS_Content = "SMC"; sndmsg.SrcID = this.userName; // sp special symbol number sndmsg.Svc_Code = svccode; sndmsg.addTerminalID (fee_user); QueueItem q = new QueueItem (seq, (uint ) MSG.CMPP_COMMAND_ID.CMPP_SUBMIT, 0,0); q.setmsgObj (sndmsg); this.addToOutQueue (q); return (seq);} public uint SendSMT (string to_user, string feecode, string svccode, string spnum, string content ) {uint seq = this.getNextSequence (); MSG.CMPP_MSG_SUBMIT sndmsg = new MSG.CMPP_MSG_SUBMIT (seq); sndmsg.SMS_Delivery_Type = 1; // generate monthly SMC sndmsg.FeeCode = feecode; // monthly billing codes sndmsg.FeeType = Msg.Feetype.Fee_Terminal_Mont; // Month metering Sndmsg.FeeterminalId = to_User; SndMsg.FeeUsertype = (int) msg.FeeUsertype.FeE_terminal_id; // Billing Sndmsg.spid = this.systemID; // Corporate code SNDMSG.UDHI = 0; // sndmsg.msgformat = (uint) msg.msg_format.ucs2; sndmsg.sms_content = content; sndmsg.srcid = SPNUM; // SP character number Sndmsg.svc_code = svccode; SNDMSG. addTerminalID (to_user); QueueItem q = new QueueItem (seq, (uint) MSG.CMPP_COMMAND_ID.CMPP_SUBMIT, 0,0); q.setmsgObj (sndmsg); this.addToOutQueue (q); return (seq);} public uint SendQuery (String svccode, string whichday) // Query a total of a total count {string wd = whichday.trim (); int query_type = 0; if (svccode == null || svcccode.compareto (") == 0) {// Query all pages} Else {// Query a service query_type = 1;} if (wd == null || wd.com) {datetime d = datetime.now; wd = D.Year.Tostring () D.MONTH.TOSTRING (). Padleft (2, '0') D.day.toString (). Padleft (2, '0');} uint seq = this.getNextSequence ); MSG.CMPP_MSG_QUERY query = new MSG.CMPP_MSG_QUERY (seq); query.Query_Type = query_type; query.Query_Code = svccode; query.Time = wd; // set the day QueueItem q = new QueueItem (seq, (uint) MSG. CMPP_COMMAND_ID.CMPP_QUERY, 0, 0); Q.SETMSGOBJ (QUERY); this.addToOutQueue (q); return (seq); // Return message internal number} public uint stopcmppconnection () // Stop CMPP protocol Socket connection { uint seq = this.getNextSequence (); MSG.CMPP_MSG_TERMINATE t = new MSG.CMPP_MSG_TERMINATE (seq); QueueItem q = new QueueItem (seq, (uint) MSG.CMPP_COMMAND_ID.CMPP_TERMINATE, 0,0); q.setmsgObj (t) This.addtooutqueue (q); return (seq); // returns termination message waiting facilitate} public uint CancelMsg (string msgid) {uint seq = this.getNextSequence (); MSG.CMPP_MSG_CANCEL cancel = new MSG.CMPP_MSG_CANCEL (seq); cancel.MsgID = msgid; QueueItem Q = New QueueItem (SEQ, (UINT) msg.cmpp_command_id.cmpp_cancel, 0, 0); Q.SETMSGOBJ (Cancel); this.addToOoutQueue (q); return (seq); // Return to the internal number of the message} PUBLIC Void stopme () {if (! this.isstop) {if (this.tcpiscanuse ()) // Send a pair of advertisements {uint seq = this.getnextsequence (); msg.cmpp_msg_terminate t = new msg.cmpp_msg_terminate (SEQ ); QueueItem Q = New QueueItem (SEQ, (UINT) msg.cmpp_command_id.cmpp_terminate, 0, 0); q.SETMSGOBJ (T); this.addtooutqueue (q);} thread.sleep (500); // Wait 1000ms , Inform the server this._stopme (); tcp.close (); if (this.onClientSvcStopedHandler = null!) {ClientQueueStateArgs arg = new ClientQueueStateArgs (this._outSeqQueue, this._waitingSeqQueue); onClientSvcStopedHandler (this, arg);} else {this.defaultClientStopEventHandler ();} Thread.Sleep (500); / / Re-active waiting thread end // Report the information in 2 queues in 2 queues} // Prepare for forcing _forcedSubthread (this.send_thread); thread.sleep (500); // Wait 1000ms, tell the server _forcedSubthread (this.recv_thread) Thread.sleep (500); // Wait 1000ms, tell the server _forcedSubthread (this.deamo_thread); thread.sleep (500); // Wait 1000ms, inform the server} public string getloginfo ()}}}} PUBLIC STRING GETLOGINFO ()}}} THIS.ERRORINFO = ""; return (t); Public int getQueItemState (uint seq) // is looking for status {int status = 0; // state unknown IF (this._outseqqueue.containskey) // {IF (SEQ)) // {@ ou ( THIS._WAITINGSEQQUE.CONTAINS (SEQ)) {// is sending waiting returns, status undecided} else {// has not been sent}} else {if (this._waitingsequeue.containskey (seq)) {// Waiting for response} else {// has been transmitted}}} return (status);} public void testsubmit (String [] NUMS, INT TOPI, INT TOPJ) // Send test package {int count = 0; int total = 0; arraylist pks = new ArrayList (); // Prepare 100 pack for (int i = 0; i <10; i ) {for (int J = 0; j <10; j ) {uint seq = this.getNextSequence (); // Preparation serial MSG.CMPP_MSG_SUBMIT sndmsg = new MSG.CMPP_MSG_SUBMIT (seq); sndmsg.FeeCode = "000001"; sndmsg.FeeTerminalId = nums [i]; sndmsg.FeeType = MSG.FeeType.FEE_TERMINAL_PERITEM; // charged under Article sndmsg.FeeUserType = 0; // end user billing Sndmsg.msg_level = 0; sndmsg.msgformat = (uint) msg.msg_format.ucs2; sndmsg.sms_content = "test"; SNDMS g.srcid = "09880"; // long number Sndmsg.spid = this.systemID; sndmsg.svc_code = "cmcctest"; sndmsg.udhi = 0; sndmsg.validtime = getValidTime (datetime.now); // Survival time SNDMSG .addterminalid (NUMS [I]); PKS.Add (SNDMSG.Tobytes ()); // Deposits Array}} DateTime T1 = DATETIME.NOW; for (INT i = 0; I Send error: " se.tostring ();} if (count> = 16) {count = 0; // Reset thread.sleep (50); // Pause 20ms}}} DateTime T2 = DateTime.now; Timespan T = T2-T1; this.Errorinfo = this.Errorinfo "/ r / n" "send:" TOTAL "section message, total spending time:" T. TotalmilliseConds "} // Test function For test mobile network testing // Test Han count area // // Common function attribute area} // ************ Tool class end ********** ************************ Enum msg_state // CMPP message in the queue's status enumeration value {new = 0, // Add to the queue waiting to send Going out from sending = 1, // is being locked in Sended_Waitting = 2, //, and waiting for the ResP message to return to sending_finished = 3 // Get a response, generally waiting cleaning out queue} public class queItem // Represents a storage In the cache queue, the serial number generates {uint _SEquence; // message index is the category of the water number uint _msgtype; // message is the COMMAND_ID, determine the original type INT _FAILEDCOUNT = 0 of the object _msgobj according to this value. Failure count, if the number of failed exceeds 3 this need to clean the int _msgState; // current message state, specifically the enumeration type Object _msgobj; // store message object, specific type reference _msgtype datetime _inqueueetime; // message entered the queue Time, send time of last message PUBLIC INT failedcount {set {this._failedcount = value;} Get {r eturn (this._failedCount);}} public object getMsgObj () {return (this._msgObj);} public void setmsgObj (object inmsg) {this._msgObj = inmsg;} public DateTime inQueueTime {set {this._inQueueTime = value; } Get {return (this._inqueuetime);}} public uint msgtype {get {return (this._msgtype);}} public int msgState {get {return (this._msgstate);} set {this._msgState = value;} } Public uint sequence {get {return (this._sequence);} set {this._sequence = value; }} Public QueueItem (uint sequence, uint msgtype, int faildedcount, int msgstate) {this._failedCount = faildedcount; this._msgState = msgstate; this._msgType = msgtype; this._sequence = sequence;} public QueueItem (uint sequence, uint msgtype, int faildedcount, int msgstate, object msgobj) {this._failedCount = faildedcount; this._msgState = msgstate; this._msgType = msgtype; this._sequence = sequence; this.setmsgObj (msgobj);}} public class BIConvert // Byte Plastic Conversion Class Network Format Converts to Memory Format {Public Static Byte [] INT2BYTES (UINT I) / / Transfer Capacity Data Network Order byte array {byte [] t = bitconverter.getBytes (i); byte b = t [0]; T [0] = T [3]; T [3] = B; B = T [1]; T [1] = T [2]; T [2] = B; return (t); } Public static uint bytes220 (byte [] bs, int startex) // Returns the integer number of the number array representative, 4 array {byte [] t = new byte [4]; for (int i = 0; i <4 && i Public static void debugstring (string bs, string txt) {system.io.streamwriter sw = new system.io.StreamWriter (txt); sw.writeline ("-----" DateTime. Now.tolocalTime ()); sw.close ();}} public class reportEventArgs: Eventargs // Reporting the data portable data {string _smstate; // Send SMS response results, meaning the STAT field as the STAT field in the SMPP protocol. SP determines the processing status of the CMPP_SUBMIT message based on this field. String _Submittime; // Submit the SMS time, or decide whether to reissue String _donetime; // to send the destination time string _destnum; // Delivered by the message UINT _SEQUENCE; / / CMPP gateway generated water number uint64 _msg_id; // The reported submitted MSGID, ISMG returned to SP in Submit_Resp Public string state {get {return (this._smste);} set {this._smste = value;}} public uint sequence {get {return (this._sequence);} set {this._sequence = value;}} public string Tousernum {get {return (this._destnum);} set {this._destnum = value;}} public string msgid {get {return (this._msgid);} set {this._msgid = value;}} public string submittime { get {return (this._submitTime);} set {this._submitTime = value;}} public string DoneTime {get {return (this._doneTime);} set {this._doneTime = value;}} public ReportEventArgs (byte [] BS) // Reported from a byte array {byte [] Temp = new byte [8 7 10 10 21 4]; for (int i = 0; i Index = 2; INT mm = convert.Toint32 (Time_String.Substring (INDEX, 2)); INDDEX = 2; INT DD = Convert.Toint32 (Time_String.Substring (INDEX, 2)); Index = 2; int hh = convert .Toint32 (Time_String.Substring (INDEX, 2)); IND MMS = Convert.Toint32 (Time_String.Substring (INDEX, 2)); DateTime T = New DateTime (YY, MM, DD, HH, MMS, 0); RETURN (T);} private vidin {BICONVERT.DUMPBYTES (BS, "C: //reportEventArgs.txt"); // Reserved Image INDEX = 0; this._msg_id = BitConverter .TOUINT64 (BS, INDEX); //bitconverter.touint64(bs ,index); this._msgid = (this._msg_id.tostring ()); // biconvert.debugstring (this._msgid, "C: // msgid. TXT "); INDEX = 8; this._smste = encoding.ascii.getstring (BS, INDEX, 7); Index = 7; this._submittime = Encoding.ascii.getstring (BS, INDEX, 10); index = 10 "This._donetime = encoding.ascii.getstring (BS, INDEX, 10); index = 10; this._destnum = encoding.ascii.getstring (BS, INDEX, 21); index = 21; this._sequence = Biconvert.bytes2uint (BS, INDEX) }}} Public class smseventargs: Eventargs {uint64 _msgid; // 8 byte message indicates string _destid; // Accept information target ID string _svccode; // service code int _tppid; // Reference GSM protocol INT _TPUDHI; // INT_MSGFRM; // Message Code Format String _srcterminateID; // Source Terminal ID, if the number of bytes of the report INT _MSGLENGTH; // message is not the actual string length string _Content; // message text content Public smseventargs (byte [] bs) {int msglen = bitconverter.Toint32 (BS, 8 21 10 1 1 1 21 1); // get a message length byte length int Templen = MSGLEN 8 21 10 1 1 1 21 1 1 msglen 8; Byte [] Temp = New Byte [Templen]; for (INT i = 0; I INDEX = 0; this._msgid = bitconverter.touint64 (BS, 0); index = 8; this._destid = encoding.ascii.getstring (BS, index, _getRealBytesLength (BS, INDEX)); index = 21; this. _SVCCODE = Encoding.ascii.getstring (BS, INDEX, _GETREALBYTESLENGTH (BS, INDEX)); Index = 10; this._tppid = (int) BS [index ]; this._tpudhi = (int) BS [index ]; this. _msgfrm = (int) BS [index ]; this._srcterminateID = encoding.ascii.getstring (BS, index, _getRealBytesLength (BS, index)); index = 21; index ; // is a status report byte this._msglength = (int) BS [Index ]; // Take the byte length Switch (this._msgfrm) {case (int) msg.msg_format.ascii: this._content = Encoding.ascii.getstring (BS, INDEX, THIS._MSGLENGTH); break; case (int) MSG.Msg_Format.GB2312: this._Content = Encoding.Default.GetString (bs, index, this._msgLength); break; case (int) MSG.Msg_Format.UCS2: this._Content = Encoding.BigEndianUnicode .Getstring (BS, INDEX, THIS._MSGLENGTH); Break; Case (int) msg.msg_format.binary: B reak; case (int) MSG.Msg_Format.WRITECARD: break; default: break;}} public string toSPNum {get {return (this._destID);}} public string SrcNum {get {return (this._srcTerminateID);}} Public string content {get {return (this._content);}} public string svccode {get {return (this._svccode);}} public uint64 msgid {get {return (this._msgid);} // set // { // this._msgid = value; //}} Public string msgidstring {get {return (this._msgid) .tostring ();}} Private int _getrealbyteslength (byte [] bts, int index) {Int i = index; for (; i {RETURN (THIS_MSG);} public uint sequence};}}}} public class cancelrespeventArgs: EventArgs {private uint _seq; private MSG.CMPP_MSG_CANCEL_RESP _msg; public CancelRespEventArgs (uint seq) {this._seq = seq;} public CancelRespEventArgs (object msg) {this._msg = (MSG.CMPP_MSG_CANCEL_RESP) msg; this._seq = this. _msg.Sequence;} public object getMSG () {return (this._msg);} public uint Sequence {set {this._seq = value;} get {return (this._seq);}}} public class QueryRespEventArgs: EventArgs { private uint _seq; private MSG.CMPP_MSG_QUERY_RESP _msg; public QueryRespEventArgs (uint seq) {this._seq = seq;} public QueryRespEventArgs (object msg) {this._msg = (MSG.CMPP_MSG_QUERY_RESP) msg; this._seq = this._msg. PUBLIC OBJECT getmsg () {return (this._msg);} public uint sequence {Set {this._seq = value;} get {return (this._seq);}}} public class ConnectRespEventArgs: EventArgs {private uint _seq; private MSG.CMPP_MSG_CONNECT_RESP _msg; public ConnectRespEventArgs (uint seq) {this._seq = seq ;} public ConnectRespEventArgs (object msg) {this._msg = (MSG.CMPP_MSG_CONNECT_RESP) msg; this._seq = this._msg.Sequence;} public object getMSG () {return (this._msg);} public uint Sequence {set {This._seq = value;} get {return (this._seq);}}} public class submitrespeventargs: Eventargs {private uint _seq; private msg.cmpp_msg_submit_resp_msg; public SubmitRespEventArgs (uint seq) {this._seq = seq;} public SubmitRespEventArgs (object msg) {this._msg = (MSG.CMPP_MSG_SUBMIT_RESP) msg; this._seq = this._msg.Sequence;} public object getMSG () {return (this._msg);} public uint Sequence {set {this._seq = value;} get {return (this._seq);}}} public class WaitingQueueItemEventArgs: EventArgs {private uint _seq; private object _q; public WaitingQueueItemEventArgs (uint SEQ) {this._seq = seq;} public waitingQueueiteMeventargs (Object q) {this._q = q;} public uint sequence {set {this._seq = value;} get {return (this._seq);}} public object GetQueueItem () {return (this._q);}} public class clientQueuestteArgs // When the service of the CMPP Client stops, the queue's status parameter {private sortedlist_waiting; private sortedlist_out; Public ClientQueuestteArgs (sortedlist inqueue) {this._waiting = inqueue; this._out = Outqueue; Public sortedlist waiting queue {get {return (this._waiting);} set {this._waiting = value;}} Public sortedlist outqueue {get {return (this._out);} set {this._out = value;}}} public class StateObject {public Socket workSocket = null; // Client socket public const int BufferSize = 1024;. // Size of receive buffer public byte [] buffer = new byte [BufferSize];. // Receive buffer public byte []. Result_buf = null; // Receive the final result buffer public int _MSGLENGTH = 0; // receive how many byte data} Public enum smsdbqueue_status: int {new = 0, // New message, waiting to send sended = 1, // is sending, waiting to respond to resp = 2, // Delivered to SMSC, get MSGID delivrd = 3, // Get report, status OK Expired = 4, // Expired DELETED = 5, // I have deleted this message Undeliv Acceptd = 6, // ACCEPTD Status Not delivered to accepted as the intermediate state, the gateway should be discarded after receiving the SMS center, do not do any operation Undeliv = 7, // Unpredictted unknown = 8, // Unknown Rejectd = 9 // Bound back} public class smsdbqueue {private uint _sequence = 0; // Corresponding cMppClient serial number private int _SMSDBID = 0; / / automatic transmission corresponding database grows ID private int _cmpp_msgType; // protocol defines message type cmpp private object _cmpp_msg_object; // cmpp message objects retrieved for private int _currentStatus; // current status of the message body private DateTime _inQueueTime = DateTime. Now; // Message Generate Setpoint Private Uint64_MSGID; // Message Returned Id Turn Public uint sequence {get {return (this._sequence);} set {this._sequence = value;}} Public int smsdbid {get {return (this._smsdbid);} set {this._smsdbid = value;}} Public int currentstatus {get {return (this._currentstatus);} set {this._currentstatus = value;}}} Public int CMPPMSGTYPE {get {return (this._cmpp_msgtype);} set {this._cmpp_msgtype = value;}} Public DateTime Inqueuetime {get {return (this._inqueuetime);} set {this._inqueuetime = value;}} Public object msgobject {get {return (this._cmpp_msg_object);} set {this._cmpp_msg_object = value;}} Public uint64 uimsgid {get {return (this._msgid);} set {this._msgid = value;}} Public string msgid {get {return (this._msgid.tostring ());} set {this._msgid = convert.touint64 (value);}}} // ************ Tool Class end ********************************* / * *********** ********* Interface class, used to connect to the external SMS storage system ****************************** PUBLIC Interface IsMsStore // Define a storage Interface {SMSRec [] getSMSsFromStore (); // Get message from the external storage void updateStoreObjec (int storeObjectID, string state); // update id object represented by the state, for monitoring the status report void updateSMSCMsgID (int storeObjectID, UInt64 msgid) Bool addsms2Store (SMSREC SMS); / / Store short messages in the Store String getFeecode (String Svccode); / / According to the charge of the message according to SVCCode, set} according to the mobile parameters} Public class smsrec // SMS Database {private int _recid; private string _feeuser; // billing user private int _SMSTYPE = 0; // SMS type 0 Ordinary text message SMS 1 flashing SMS 2 query command SMS 3 monthly SMS Private string _svccode; // service code private string _msg; // message private string _state; // status message private string _feecode; private string _spnum; private string _toUser; public SMSRec (int recid, string feeuser, string feecode, string svccode, string MSG, String SPNUM) {this._recid = Recid; this._feeuser = feEuser; this._svccode = svccode; this._msg = msg; thermo_spnum = spnum;} public SMSRec (int recid, string feeuser, string touser, string feecode, string svccode, string msg, string spnum) {this._RecID = recid; this._feeUser = feeuser; this._toUser = touser; this._svccode = svccode; this ._msg = msg; this._spnum = spnum;} public string svccode {get {return (this._svccode);} set {this._svccode = value;}} Public String Feecode {get {return (this._feecode);} set {this._feecode = value;}} Public String Feeuser {get {return (this._feeuser);} set {this._feeuser = value;}} private string Touser {get {return (this._touser);} set {this._touser = value;}} Public string spnum {get {return (this._spnum);} set {this._spnum = value;}} Public string message {get {return (this._msg);} set {this._msg = value;}} } // ********************************************************************************************* ******************* // *************************************************************************************************** **** // ** function, implement queue monitoring, processing failed messages, success messages, handling timed storage updates, etc., provide CMPPCLIENT packaging Public class smssystem {private ismsstract dbcls = null; private cmppclient client = null; private string pwd; private string spnum; Public void setismStoreInterface (ismsstore ismsstore) {dbcls = ismsteore;} public SMSSystem (string systemid, string spnum, string password, string cmppserverip, int cmppport) {client = new CMPPClient (); client.Init (cmppserverip, cmppport); this.spnum = spnum; this.systemid = systemid; this.pwd = Password;} } // ****************************** Hands the end of the SMS system class Namespace msg // message class definition {// ************* Enumeration type start ********************************* ************ public enum CMPP_COMMAND_ID: uint {CMPP_CONNECT = 1, CMPP_CONNECT_RESP = 0x80000001, CMPP_TERMINATE = 0x00000002, // terminates the connection CMPP_TERMINATE_RESP = 0x80000002, // terminate the connection response CMPP_SUBMIT = 0x00000004, // Submit SMS CMPP_SUBMIT_RESP = 0x80000004, // submit a response message CMPP_DELIVER = 0x00000005, // text messages sent under CMPP_DELIVER_RESP = 0x80000005, // under texting response CMPP_QUERY = 0x00000006, // send SMS status query CMPP_QUERY_RESP = 0x80000006, // send SMS status query response CMPP_CANCEL = 0x00000007, // delete messages CMPP_CANCEL_RESP = 0x80000007, // delete the SMS response CMPP_ACTIVE_TEST = 0x00000008, // activate a test activation CMPP_ACTIVE_TEST_RESP = 0x80000008 // test responses} public enum FeeUserType {FEE_TERMINAL_ID = 0, // FEE_SOURCE_ID = 1, FEE_SP = 2, FEE_NULL = 3} public enum Msg_Format {ASCII = 0, WRITECARD = 1, BINARY = 2, UCS2 = 8, GB2312 = 15} public enum SUBMIT_RESULT {SUCC = 0, MSG_STRUCTURE_ERR = 1, COMMANID_ERR = 2, MSG_SEQUENCE_ERR = 3, MSG_LENGTH_ERR = 4, FeE_CODE_ERR = 5, OUT_OF_MSG_LEN_ERR = 6, SVC_CODE_ERR = 7, FLUX_ERR = 8, Other_ERR = 9} // ************ Enumeration Type end ***** ****************************** ************* Structure definition start ** ****************************************** Public Struct Feetype {Public Static Readonly String FeE_Terminal_Free = "01"; Public Static ReadOnly String fee_terminal_peritem = "02"; public static readonly string fee_terminal_month = "03"; public static readonly string feE_TERMINAL_TOP = "04"; public static readonly string fee_terminal_sp = "05" ;} Public struct DELIVER_STATE {public static readonly string DELIVERED = "DELIVRD"; public static readonly string EXPIRED = "EXPIRED"; public static readonly string DELETED = "DELETED"; public static readonly string UNDELIVERABLE = "UNDELIV"; public static readonly string Accepted = "acceptd"; public static readonly string unknown = "unknown"; public static readonly string rejected = "rejectd";} // ************ The structure type ends ***** ******************************************************* Messages ******************************************************** PUBLIC CLASS CMPP_MSG_HEADER / / News Head {Private Byte [] initValue = new byte [MSG.CMPP_MSG_Header.HeaderLength]; public CMPP_MSG_Header (CMPP_COMMAND_ID command_ID) // before sending {BIConvert.Int2Bytes ((uint) command_ID) .CopyTo (initValue, 4);} public CMPP_MSG_Header (byte [] bs) / / According to the byte, the texture sequence {INT L = msg.cmpp_msg_header.HeaderLength; for (int i = 0; i ) {INITVALUE [i 4] = T [I];}}} public uint sequenceid {get {return (Biconvert.Bytes2uint (initValue, 8));} set {byte [] t = biconvert.int2bytes (value); For (int i = 0; i <4; i ) {initValue [i 4 4] = t [i];}}} public byte [] Tobytes () {return (initValue); // Transform field transformation into Byte} public void frombytes (byte [] bs) {for (int i = 0; i BS [msg.cmpp_msg_header.HeaderLength i]; // Put the byte of the message} header = new msg.cmpp_msg_header (temp); // Construct message header.msglength = (this.bodylength msg.cmpp_msg_header .HeaderLength); header.Command_ID = (uint) MSG.CMPP_COMMAND_ID.CMPP_CONNECT;} public int BodyLength {get {return (6 16 4 1);}} public string SourceAdd {set {_SystemID = value; byte [] T = encoding.ascii.getbytes (_systemid); // Convert to byte array T.COPYTO (body, 0);}} public string password {set {_password = value;}} public string version {set {ver = Convert .Tobyte ("0x" value, 16);}} private static string getTimeStamp () // Returns a timestamp 4 byte {datetime msgtime = datetime.now; string u = msgtime.month.toString (). Padleft 2, '0'); u = u msgtime.day.tostring (). Padleft (2, '0'); u = u msgtime.Hour.tostring (). Padleft (2, '0'); u = u msgtime.minute.toString (). Padleft (2, '0'); u = u msgtime.second.tostr ING (). Padleft (2, '0'); return (u);} private byte [] getmd5code () {md5 md5 = new md5cryptoserviceProvider (); // creation MD5 category BYTE [] buf = new byte [6 9 _password.length 10]; byte [] s_a = Encoding.ascii.getbytes; // source_add is the business code BYTE [] S_0 = {0, 0, 0, 0, 0, 0, 0, 0 0}; // 9 bytes 0, this is as a right complement 0 byte [] s_p = encoding.ascii.getbytes (_password); // password this._timestamp = getTimeStamp (); // get the authentication code Assignment string Byte [] s_t = encoding.ascii.getbytes (_TimeStamp); // 10 bit string byte array s_a.copyto (buf, 0); // base 0 s_0.copyto (buf, 6); // base 6 s_p.copyto (buf, 6 9); // base 6 9 s_t.copyto (buf, 6 9 _password.length); // base 6 9 password.length return (MD5. Computehash (BUF, 0, BUF.LENGTH);} private byte [] getSourceAdd () {return (encoding.ascii.getbytes);} public byte [] Tobytes () // Return the word of the current object An array impression {byte [] revAL = new byte [msg.cmpp_msg_header.HeaderLength this.bodylength]; Header.Tobytes (). CopyTo (Reval, 0); // Message GetSourceAdd (). CopyTo (Reval, MSG. CMPP_MSG_Header.HeaderLength); // company code address source getMd5Code () CopyTo (reVal, MSG.CMPP_MSG_Header.HeaderLength 6);. // authentication md5 reVal [MSG.CMPP_MSG_Header.HeaderLength 6 16] = this.ver; / / version byte BIConvert.Int2Bytes (Convert.ToUInt32 (this._timestamp)) CopyTo (reVal, MSG.CMPP_MSG_Header.HeaderLength 6 16 1);. return (reVal);}} public class CMPP_MSG_CONNECT_RESP {CMPP_MSG_Header header; byte Status; Byte [] Authenticatorismg; Byte_Version; Public CMPP_MSG_CONNECT_RESP (Byte [] BS) {byte [] T emp_head = new Byte [MSG.CMPP_MSG_Header.HeaderLength]; int index = 0; for (int i = 0; i }} Public string ISMGREturnAuthCode {get {return (Encoding.ASCII.GetString (AuthenticatorISMG));}} public uint Command_ID {get {return (header.Command_ID);} set {header.Command_ID = value;}} public uint Sequence { get {return (header.SequenceId);}}} public class CMPP_MSG_TERMINATE {CMPP_MSG_Header header; public CMPP_MSG_TERMINATE (uint sequence) {header = new MSG.CMPP_MSG_Header (CMPP.YOURCOMPANY.MSG.CMPP_COMMAND_ID.CMPP_TERMINATE); header.MSGLength = (uint ) MSG.CMPP_MSG_Header.HeaderLength; header.SequenceId = sequence;} public CMPP_MSG_TERMINATE (byte [] bs) {header = new MSG.CMPP_MSG_Header (bs);} public byte [] toBytes () {return (header.toBytes ()) Public uint sequence {get {return (header.sequenceid);}}} public class cMPP_MSG_TERMINATE_RESS CMPP_MSG_TERMINATE_RESP {CMPP_MSG_HEADER Header; public cMPP_MSG_TERMINATE_RESP (BYTE [] BS) {Header = new CMPP_MSG_Header (bs);} public CMPP_MSG_TERMINATE_RESP (uint sequence) {header = new MSG.CMPP_MSG_Header (MSG.CMPP_COMMAND_ID.CMPP_TERMINATE_RESP); header.MSGLength = (uint) MSG.CMPP_MSG_Header.HeaderLength; header.SequenceId = sequence; } Public byte [] Tobytes () {return (header.tobytes ());} public uint command_id {get {return (header.command_id);} set {header.command_id = value;}} public uint sequence {get {Return (HEADER.SEQUENCEID);}}} public class cMPP_MSG_SUBMIT {CMPP_MSG_HEADER Header; INT _ISREPORTORSMC = 1; // Do not require state report int _msgtotal = 1; // The number of the same message int _msgnumber = 1; // int _msglevel = 0; // message level, winning 0 string _svccode = ""; // business type int _feeusertype = 0; // billing user type field 0 : Getting on the destination terminal MSISDN; 1: Term of the source terminal MSISDN; 2: For the SP billing; 3: This field is invalid, please refer to Who for the fee_terminal_id field string _feeterminalid = ""; // Billing terminal INT _TPPID = 0; int _tpudhi = 0; uint _msgfmt = 0; // message format string _msrc = ""; // message source is SPID string _feetype = msg.Feetype.FeE_terminal_PerItem; // String _feecode = "; // Tariff string _validtime = ""; // Survival String _attime = ""; // Scheduling time string _srcid = ""; // source number, the number displayed on the phone INT _DestusRnum = 0; // Accept message mobile phone Number string [] _destterminalids = new string [100]; // up to 100 numbers int _msglengt = (int) msg.msg_format.gb2312; string _msgcontent = "; uint64 _msgid; // Return Message ID) public CMPP_MSG_SUBMIT (uint sequence) {header = new MSG.CMPP_MSG_Header (CMPP.YOURCOMPANY.MSG.CMPP_COMMAND_ID.CMPP_SUBMIT); header.SequenceId = sequence;} // Properties public string SMS_Content {set {this._MsgContent = value; byte [] T = encoding.ascii.getBytes (value); this._msglength = T.LENGTH;}} public int sms_delivery_type // is required to return status confirmation report: 0: No need 1: Need 2: Generate SMC bill (this type SMS Only for gateway board, do not send to destination terminals) {set {_isreportorsmc = value;}} public int msg_level {set {this._msglevel = value;}} public string svc_code {set {this._svccode = value;}} public int FeeUserType {set {this._feeUserType = value;}} public string FeeTerminalId {set {this._feeTerminalId = value;}} public int UDHI {set {this._tpUDHI = value;}} public uint MSGFormat {set {this. _msgfmt = value;}} public string spid {set { This._msgsrc = value;}} public string srcid // You can determine the long number {set {this._srcid = value;}} public string feet {set {this._feetype = value.padLeft (2, '0') ;}} public string FeeCode {set {this._feeCode = value;}} public string valIdTime {set {this._valIdTime = value;}} public string AtTime {set {this._atTime = value;}} public UInt64 MsgID {set {THIS._MSGID = VALUE;} get {return (this._msgid); }} // Attribute end // public void address {if (this._destusrnum <100) {this._destterminalids [this._destusRnum ] = ID;}} public byte [] TobYtes () // Return byte Number impression {byte [] submitdata = new byte [400]; int index = msg.cmpp_msg_header.HeaderLength; // Current Package Fill pointer {// process INDEX = INDEX 8; // msgID Skip SubmitData [index ] = (byte) this._msgTotal; submitData [index ] = (byte) this._msgNumber; submitData [index ] = (byte) this._isReportOrSMC; submitData [index ] = (byte) this._msgLevel; byte [] svccode = Encoding.ASCII.GetBytes (this._svcCode); svccode.CopyTo (submitData, index); // copied to the target index = index 10; // index increases submitData [index ] = (byte) this._feeUserType; byte [] feetid = Encoding.ASCII.GetBytes (this._feeTerminalId); feetid.CopyTo (submitData, index); index = index 21; submitData [index ] = (byte) this._tpPid; submitData [index ] = (byte) THIS._TPUDHI; SubmitData [INDEX ] = (byte) this._msgfmt; byte [] spid = encoding.asc Ii.getbytes; Spid.copyto (SubmitData, Index); index = index 6; byte [] feetype = encoding.ascii.getbytes; Feetype.copyTo (SubmitData, Index); Index = index 2; byte [] feecode = encoding.ascii.getbytes; feecode.copy (SubmitData, index); index = index 6; // Byte [] validtime = encoding.ascii.getbytes (this ._validtime.copy; ingx = index 17; // byte [] attime = encoding.ascii.getbytes (this._validtime); //attime.copyto (SubmitData, Index); index = index 17; byte [] srcid = Encoding.ASCII.GetBytes (this._srcId); srcid.CopyTo (submitData, index); index = index 21; submitData [index ] = (byte) this._destUsrNum; for (INT i = 0; i Index msg.Length; Break; default: msg = encoding.ascii.getbytes; msg.copyto (submitData, index); submitData [index-1] = (byte) msg.length; // Reset Depending length index = index msg.Length; Break;} index = index 8; // 8 reserved byte} header.msglength = (uint) index; // Determine the transmission data byte length byte according to INDEX length ] Reval = new byte [index]; header.tobytes (). COPYTO (REVAL, 0); for (int i = msg.cmpp_msg_header.HeaderLength; i public string MsgID {get {return BitConverter.ToUInt64 (this.Msg_Id, 0) .ToString ();}} public uint Command_ID {get {return (header.Command_ID);} set {header.Command_ID = value;}} public uint Sequence {get {return (header.sequenceid);}} public bool isok {get {byte b = initvalue [msg.cmpp_msg_header.HeaderLength 8]; if ((int) b == 0) {Return (TRUE);} else {return (false);}}}} public class CMPP_MSG_QUERY {CMPP_MSG_Header header; string _time; int _queryType = 0; string _queryCode; public string Time {set {_time = value;}} public int Query_Type {set {_queryType = value ;}} public string Query_Code {set {_queryCode = value;}} public CMPP_MSG_QUERY (uint sequence) {header = new MSG.CMPP_MSG_Header (MSG.CMPP_COMMAND_ID.CMPP_QUERY); header.SequenceId = sequence;} pu BLIC BYTE [] REVAL = New Byte [msg.cmpp_msg_header.HeaderLength 8 1 10 8]; int index = 0; header.tobytes (). COPYTO (REVAL, INDEX); Index = INDEX MSG.CMPP_MSG_HEADER.HEADERLENGTH; Encoding.ASCII.GetBytes (this._time) .copyto (revAL, INDEX); // 8 OCTET STRING Time YYYYMMDD (Precise New Day) INDEX = Index 8; Reval [INDEX ] = Convert.ToByte (this._queryType); Encoding.ASCII.GetBytes (this._queryCode) .CopyTo (reVal, index); return (reVal);}} public class CMPP_MSG_QUERY_RESP {CMPP_MSG_Header header; string _time; byte _queryType; string _queryCode; System.uint32 _mt_tlmsg; system.uint32 _mt_tlusr; System.UInt32 _MT_Scs; System.UInt32 _MT_WT; System.UInt32 _MT_FL; System.UInt32 _MO_Scs; System.UInt32 _MO_WT; System.UInt32 _MO_FL; public CMPP_MSG_QUERY_RESP (byte [] bs) {header = new MSG.CMPP_MSG_Header (bs); int index = MSG.CMPP_MSG_Header.HeaderLength; _time = BitConverter.ToString (bs, index, 8); index = index 8; this._queryType = bs [index ]; this._queryCode = BitConverter.ToString (bs, index, 10) ; index = index 10; this._MT_TLMsg = BIConvert.Bytes2UInt (bs, index); index = index 4; this._MT_Tlusr = BIConvert.Bytes2UInt (bs, index); index = index 4; this._MT_Scs = BIConvert .BYTES2UINT (BS, INDEX); index = index 4; this._mt_wt = Biconvert.bytes2uint (BS, INDEX); index = index 4; this._mt_fl = biconvert.bytes2uint (bs, index); index = index 4; this._mo_scs = biconvert.bytes2uint (BS, INDEX); index = index 4; this._mo_wt = Biconvert.bytes2uint (BS, index); index = index 4; this._mo_fl = biconvert.bytes2uint (BS, INDEX);} public string time {Get {return (this._time);}} public int Qery_Type {get {return (this._queryType);}} public string QueryCode {get {return (this._queryCode);}} public uint Sequence {get {return ( header.SequenceId);}} public uint MT_TLMsg {get {return (this._MT_TLMsg);}} public uint MT_TLUsr {get {return (this._MT_Tlusr);}} public uint MT_Src {get {return (this._MT_Scs); }}} Public uint mt_wt {get {return (this._mt_wt); }} Public uint mt_fl {get {return (this._mt_fl);}} public uint mo_src {get {return (this._mo_scs);}}} public uint mo_wt {get {return (this._mo_wt);}} public uint MO_FL {get {return (this._MO_FL);}}} public class CMPP_MSG_DELIVER {CMPP_MSG_Header header; System.UInt64 _msgid; string _destid; string _svccode; int _tpid; int _udhi; int _msgfmt; string _srctid; bool _isReport; int _msglength; string _msg; System.UInt64 _reportForMsgid; string _reportState; string _submitTime; string _doneTime; string _reportDesttid; int _smscSequence; public CMPP_MSG_DELIVER (byte [] bs) {header = new MSG.CMPP_MSG_Header (bs); int index = MSG.CMPP_MSG_Header.HeaderLength; THIS._MSGID = BITCONVERTER.TOUINT64 (BS, INDEX); INDEX = 8; this._destid = Encoding.ascii.getstring (BS, INDEX, 21); index = index 21; this._svccode = encoding.ascii.g ETSTRING (BS, INDEX, 10); index = index 10; this._tpid = (int) BS [index ]; this._udhi = (int) BS [index ]; this._msgfmt = (int) BS [index ] T_ = 21; INDEX = 21; IF (BS [index ] == 1) {this._isreport = true;} else {this._isreport = false;} this ._msglength = (int) BS [index ]; if (! this._isreport) {Switch (this._msgfmt) {case (int) msg.msg_format.ascii: this._msg = Encoding.ascii.getstring (BS, INDEX, THIS._MSGLENGTH); Index = this._msglength; CASE (int) msg.msg_format.binary: this._msg = encoding.default.getstring (BS, INDEX, THIS._MSGLENGTH); Index = this._msglength; break; case (int) msg.msg_format.gb2312: this._msg = Encoding.Default.GetString (bs, index, this._msglength); index = this._msglength; break; case (int) MSG.Msg_Format.UCS2: this._msg = Encoding.BigEndianUnicode.GetString (bs, index, this. _msglength); index = this._msglength; break; default: break;}} else {// status report this._reportForMsgid = BitConverter.ToUInt64 (bs, index); index = 8; this._reportState = BitConverter.ToString (bs, Index, 7); Index = 7; this._submittime = bitconverter.tostring (BS, INDEX, 10); Index = 10; this._donetime = Bitconverter.toTRING (BS, INDEX, 10); Index = 10; this._reportdesttiD = BITCONVERTER.TOSTRING (BS, INDEX, 21); INDEX = 21; this._smscsequence = (int) Biconvert.bytes2uint (BS, INDEX);}} public bool is Report {get {return (_isreport);}} public string msg {get {return (this._msg);}} public string srcid {get {return (this._srctid);}} public string svccode {get {return (this ._svccode);}} public string destid {get {return (this._destid);}} public uint64 msgid // provides serial number {get {return (this._msgid);}} public string statereport {Get {{ Return (this._reportstate);}}} public msgi {get {{return (this._reportformsgid); }}} Public string SubmitTime {get {{return (this._submitTime);}}} public string DoneTime {get {{return (this._doneTime);}}} public string ReportbyDestID {get {{return (this._reportDesttid) ;}}} Public int smscsequence {get {return (this._smscsequence);}} public int ISMGSequence {get {return ((int) this.header.SequenceId);}} public int MsgBytelen {get {return (this._msglength); // returns deliver report packet body length}}} public class CMPP_MSG_DELIVER_RESP {CMPP_MSG_Header header; int _result; // byte [] _msgidbytes = new byte [8]; System.UInt64 _msgid; public CMPP_MSG_DELIVER_RESP (uint sequence) {header = new MSG.CMPP_MSG_Header (MSG.CMPP_COMMAND_ID.CMPP_DELIVER_RESP); header.SequenceId = sequence; header.MSGLength = (uint) MSG.CMPP_MSG_Header.HeaderLength 8 1;} public int Result {set {this._result = value;}} public UInt64 MsgID {set {this._msgid = value;}} public byte [] toBytes () {byte [] reVal = new byte [MSG.CMPP_MSG_Header.HeaderLength 9]; int index = 0;. header.toBytes () CopyTo (reVal, index); index = index MSG.CMPP_MSG_Header.HeaderLength; BitConverter .Getbytes (this._msgid) .copyto (revAL, INDEX); index = index x 8; reVal [index ] = Convert.ToByte (this._result); return (reVal);}} public class CMPP_MSG_CANCEL {CMPP_MSG_Header header; byte [] Msg_Id = new byte [8]; string _msgid; public CMPP_MSG_CANCEL (uint sequence) {header = new MSG.CMPP_MSG_Header (MSG.CMPP_COMMAND_ID.CMPP_CANCEL); header.SequenceId = sequence; header.MSGLength = (uint) (MSG.CMPP_MSG_Header.HeaderLength 8);} public string MsgID {set {this._msgid = Value;}} public byte [] Tobytes () {byte [] revAL = new byte [msg.cmpp_msg_header.HeaderLength 8]; int index = 0; header.tobytes (). CopyTo (Reval, INDEX); index = index MSG.CMPP_MSG_Header.HeaderLength; Encoding.ASCII.GetBytes (this._msgid) .CopyTo (reVal, index); return (reVal);}} public class CMPP_MSG_CANCEL_RESP {CMPP_MSG_Header header; bool _Suceeid; public CMPP_MSG_CANCEL_RESP (byte [ ] bs) {header = new msg.cmpp_msg_header (BS); if (BS [msg.cmpp_msg_header.Headerlength] == 0) {this._suceeid = false;} else {this._suceeid = true;}} public bool @}}} public bool @ get {return (this._Suceeid);}} public uint Sequence {get {return (this.header.SequenceId);} set {header.SequenceId = value;}}} public class CMPP_MSG_TEST {CMPP_MSG_Header header; public CMPP_MSG_TEST (uint sequence ) {header = new MSG.CMPP_MSG_Header (MSG.CMPP_COMMAND_ID.CMPP_ACTIVE_TEST); header.MSGLength = (uint) MSG.CMPP_MSG_Header.HeaderLength; header.SequenceId = sequence;} public CMPP_MSG_TEST (byte [] bs) {header = new MSG. CMPP_MSG_H eader (bs);} public byte [] toBytes () {return (header.toBytes ());} public uint Sequence {get {return (header.SequenceId);}}} public class CMPP_MSG_TEST_RESP {CMPP_MSG_Header header; public CMPP_MSG_TEST_RESP ( uint sequence) {header = new MSG.CMPP_MSG_Header (MSG.CMPP_COMMAND_ID.CMPP_ACTIVE_TEST_RESP); header.MSGLength = (uint) (MSG.CMPP_MSG_Header.HeaderLength 1); header.SequenceId = sequence;} public CMPP_MSG_TEST_RESP (byte [] bs) {Header = new msg.cmpp_msg_header (bs); public uint sequence {get {return (header.sequenceID);