CMPP SP end C # instance

xiaoxiao2021-03-06  110

// attached CMPPClient.cs: / * Author: TNT Time: December 2003 File Description: This document implements the protocol developed SP side.

* / 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 a termination signal received 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 QueryRespEventHandle r (object 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 FailedItemDeletedEventHandler (object sender, WaitingQueueItemEventArgs e); // when a message is waiting queue of more than 60 seconds did not respond to public delegate void CMPPClientSvcStopEventHandler (object sender, ClientQueueStateArgs e); // when CMPP service stops when the trigger event ///

/// As the client of the CMPP protocol, there will be three thread processing: 1. Processing the message that needs to send Mo (downlink) /// 2, processing from the mobile server Come over CMPP message /// 3, process connection break and other information, check the message that needs to be retransmit, check the received report, SMS, and call the OnReport event onsms Event ///

public class CMPPClient {public static long CMPP_ACTIVE_TEST_C_TICKs = 30; // * 3; active_test // long test time connection public static long CMPP_ACTIVE_TEST_T_TICKs = 60; // time of 60 seconds Failure message public static int CMPP_ACTIVE_TEST_N_COUNT = 3; // 3 times / / public static int CMPP_MSG_MAX = 100; // once the maximum number of messages made public static int CMPP_Port = 7890; public event ReportEventHandler onReportHandler; // event handling code pointer pointing public event SMSEventHandler onSMSHandler; // message arrival process public event TestEventHandler onTestHandler ; public event TestRespEventHandler onTestRespHandler; public event ConnectRespEventHandler onConnectRespHandler; public event CancelRespEventHandler onCancelRespHandler; public event TerminateEventHandler onTerminateHandler; public event TerminateRespEventHandler onTerminateRespHandler; public event SubmitRespEventHandler onSubmitRespHandler; public event QueryRespEventHandler onQueryRespHandler; public event LogonSuccEventHandler onLogonSuccEventHandler; public event SocketClosedEventHandler onSocketClosedHandler; public event FailedItemDeletedEventHandler onWaitingItemDeltedHandler; // queue when the message timeout public event CMPPClientSvcStopEventHandler onClientSvcStopedHandler; // when the service stops when the event // private function area // private Socket tcp = null; private IPHostEntry ip = null; private IPEndPoint cmpp_ep = NULL; private int rectimeout = 1000; // 2000ms Accepting timeout private int sendtimeout = 2000; // 2000ms Send timeout private string cMPP_SERVER = "; // Mobile server IP or DNS name private string systemid =" "; / / Enterprise No. Private String UserName = "" "// SP number / corporate number private string password =" "; // password private bool isstop = false;

// This service is terminated whether the private bool islogin = false; // is already logged in to private thread send_thread; // send thread, dedicated to the mobile data package private thread recv_thread; // Specially processed the reception package private thread DEAMO_THREAD; // Monitor thread private string errorinfo = ""; // Store the last occurrence error message or reference information private datetime.now; // Last Ping time private uint lastsequence; // Decoction, each restart need to reset lastSequence private SortedList _outSeqQueue = new SortedList (); // message queue storage QueueItem, the transmit queue state storage private SortedList _waitingSeqQueue = new SortedList (); // message queue stores QueueItem private int sub_resp = 0; // The last returned 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 a set Sockets server, i.e. the server CMPP // private ManualResetEvent _lastsendDone = new ManualResetEvent (false); // time on whether the transmission is completed // private ManualResetEvent _lastrecvDone = new ManualResetEvent (false); a completion is received on private void ping // ( ) // Send a PING package, without Directly through _outSeqQueue out queue stored in the {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 SMS survival time {datetime n = d.addhai (2); // 2 hours return (n .Yar.toString (). Substring (2) n.month.toString (). Padleft (2, '0') n.day.toTString (). 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 () // if a ping to the time {System.TimeSpan l = (DateTime.Now - this._current_time); if (l.TotalSeconds> = (CMPPClient.CMPP_ACTIVE_TEST_C_TICKs)) {lock (this) {this ._current_time = datetime.now;}}}}}}}} private void checkresend () // Do you need another ping // Query _waitingSeqqueue does not have the previous message {/ / Investigate all messages in Waiting Queue, if the income time exceeds 60 for (int i = 0; i cmppclient.cmpp_active_test_t_ticks) // reach timeout time { // resending message if (q.FailedCount> = CMPPClient.CMPP_ACTIVE_TEST_N_COUNT) {// report message transmission failure if (this.onWaitingItemDeltedHandler = null!) {WaitingQueueItemEventArgs e = new WaitingQueueItemEventArgs (q); this.onW AITINGITEMDELTEDHANDLER (this, e);} this.delfromwaitingQueue (q); // From the waiting queue to delete the //q.msgState = (int) msg_state.sended_waitting;} else {// can try to continue sending q.inqueuetime = 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) // Generate a message queue member object instance {uint seq = this.getNextSequence (); // queueItem q =

New QueueItem (SEQ, (UINT) MSGTYPE, 0, MSGState; q.setmsgobj (MSG); // Setting Message is Object Return (Q);} Private QueueItem GetQueueItem (uint seq) // Get Messages in the MT queue Project {LOCK (this) {return ((QueueItem) this._outseqqueue [seq]);}} private queItem getWaitingQueueItem (UINT SEQ) // Get message in the waiting queue {Return (QueueItem) this._waitingseqqueue [seq]) ;} private void addToOutQueue (QueueItem q) {lock (this) {this._outSeqQueue.Add (q.Sequence, q);}} private void addToWaitingQueue (QueueItem q) {lock (this) {if (this._waitingSeqQueue!. Containskey (q.sequence)) {this._waitingseqqueue.add (q.sequence, q);}}} private queueItem gettopoutqueue () // need to judge {for (int i = 0; i 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 = password.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 (seq); this.addToWaitingQueue (outitem); active_TEST_resp // server waits} 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 specific message transmit queue lock (this) // remove the need to send {outitem.MsgState = (int) MSG_STATE .Sending; this.delfromoutqueue (seq);} OutItem.msgState = (int) msg_state.sending_finished; // Complete Return (Test_reply.tobytes ());

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} 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 (); // send a queue removed; 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.addto WaitingQueue (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 (); // Remove in the send queue; Lock (this) {OutItem.msgState = (int) msg_state.sending; this.delfromoutqueue (SEQ); this.addtowaitingQueue (OutItem.msgState = (intItem.msgState = ) 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 (); // remove the transmission queue;

lock (this) {outitem.MsgState = (int) MSG_STATE.SENDING; this.delFromOutQueue (seq); 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 (); // send a queue removed; 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 queue lock removed (this) {outitem.MsgState = (int) MSG_STATE.SENDING; this.delFromOutQueue (seq); this.addToWaitingQueue (outitem); active_TEST_resp // server waits} outitem.MsgState = (int) MSG_STATE.SENDED_WAITTING; return (test .tobytes ());}}} private void sendqueueItem (QueueItem OutItem) // Put Q ueueItem sent {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 () {OutItem.msgState = (int) {OUTITEM.MSGSTATE = (INT) {OUTITEM.MSGSTATE = (INT); this.dttowaitingQueue (OutItem); // Waiting for the server Active_Test_Resp} 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 the specific message required to send the specific message to the specific message (this) {OutItem.msgState = (int)); this.delfromoutqueue (seq);} TCP.SEND (); 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); // Waiting for response} TCP.SGETES ()); 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 (); // send a queue removed; lock (this) {outitem.MsgState = (int ) Msg_state.sending; this.delfromoutqueue (seq);} tcp.send (DELIVER_RESP.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 a queue removed; lock (this) {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; // Notifying other threads to exit Break; Case (uint) MSG. CMPP_COMMAND_ID.CMPP_TERMINATE_RESP: MSG.CMPP_MSG_TERMINATE_RESP terminate_resp = (MSG.CMPP_MSG_TERMINATE_RESP) outitem.getMsgObj (); // send a queue removed; lock (this) {outitem.MsgState = (int) MSG_STATE.SENDING; this.delFromOutQueue (seq); } Tcp.send (Terminate_resp.tobytes ()); 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 currently available tcp {bool reval = true; DateTime t = DateTime.Now; TimeSpan ts = t- this._lastOkTime; if (ts.TotalSeconds> CMPPClient.CMPP_ACTIVE_TEST_T_TICKs) // 60 seconds { Reval = false; // Not available} 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 last success message interaction time}} private void defaultReportHandler () // is the province reporting 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 = ne w MSG.CMPP_MSG_TEST (q.Sequence); // send a packet immediately past q.setmsgObj (test); this.addToOutQueue (q);} 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;}}} private void recacygmsgthread () // Processing the thread of the ISMG message {while (! 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); // Block Receive / / Analysis received data msg.cmpp_msg_header header; // = new msg.cmpp_msg_header (RBUF, INDEX); // Get a message why (Index

} 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 regardless of this.ErrorInfo = this. ErrorInfo "/ r / n" ( "receive: CMPP_ACTIVE_TEST_RESP"); MSG.CMPP_MSG_TEST_RESP test_reply2 = new MSG.CMPP_MSG_TEST_RESP (the_pk); // configuration message seq = test_reply2.Sequence; // find the last message was sent this .delFromWaitingQueue (seq); // delete the message queue waits for a response // empty 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 cancel_reply = new MSG.CMPP_MSG_CANCEL_RESP ( THE_PK); // Construct Message SEQ = Cancel_Reply.sequence; this.delfromwaitingQueue (SEQ); // Check the: case (uint) MSG.CMPP_COMMAND_ID.CMPP_CONNECT_RESP; if (this.onCancelRespHandler = null!) {CancelRespEventArgs e = new CancelRespEventArgs (cancel_reply); onCancelRespHandler (this, e);} else {defaultCancelRespEventHandler ();} break The correctness of the message, clearing the 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;

// Get 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;} this.delfromwaitingQueue (seq); // Delete the waiting connection information package in the queue Break; case (uint) msg.cmpp_command_id.cmpp_deliver: // Check the message is correct, immediately Returns correct or failure, the correctness is processed, not the status package is saved to the Mo cache, indicates that the information is received, and the status package determines the cache message to perform message delivery 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 number, you need to send a Deliver_Resp // one ISMG-> SP message msg.cmpp_msg_dliver_resp_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 ; // A state of this message // _ debugbs (THE_PK); ReportEventArgs arg = new reportEventArgs (THE_PK, MSG.CMPP_MSG_HEADER.HEADERLENGTH 8 21 1 1 1 1 21 1 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 is not considered report of {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, it should be completed quickly, do not rely on storage resources, etc.} else {defaultsmshandler ();}} Break; case (uint) MSG.CMPP_COMMAND_ID.CMPP_QUERY_RESP: this.ErrorInfo = this.ErrorInfo "/ r / n" ( "receive: CMPP_QUERY_RESP"); // message is received, stored in the database after treatment MSG.CMPP_MSG_QUERY_RESP query_resp = new MSG.CMPP_MSG_QUERY_RESP (THE_PK); this.delfromwaitingQueue (query_resp.sequence); // Remove the elements in the waiting queue (this.onqueryResphand ! Ler = 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 as tested delFromWaitingQueue (submit_resp.Sequence); // wait to delete a message if (! 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.ErrorInfo = 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" "receive: CMPP_TERMINATE_RESP"; tcp. Send (Terminate_resp.tobytes ()); if (this.onterminateHandler! = Null) {TerminateEventArgs E = New TerminateEventArgs (Terminate); THMINATEHANDLER (THIS, E); this.stopme (); // Prepare self-stop?} Else {DefaultlerMinateEventHandler ();} this._stopme (); // Send a termination return return; // Exit Thread Case (uint) msg.cmpp_command_id.cmpp_terminate_resp: this.Errorinfo = this.ErrorInfo "/ R / N" " to: CMPP_TERMINATE_RESP "; MSG.CMPP_MSG_TERMINATE_RESP ter_resp = new MSG.CMPP_MSG_TERMINATE_RESP (the_pk); seq = ter_resp.Sequence; // get water signal this.delFromOutQueue (seq); // delete the output table key projects if (this.onTerminateRespHandler =! NULL) {Terminaterespeventargs E = New Terminaterespeventargs (Terminateresphandler (this, e);

} Else {defaultter ();} 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 is normal { // This thread is the monitoring thread int T_count = 0; // cycle time count _RestartRecvnsend (); // Start receiving and sending while (! This.isstop) {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 that need to be re- Send message // 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.onsocketclosedhandler! = 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

// Send Each message} Catch (socketexception se) {// Send failed OutItem.failedCount ;}}}}}}}}}}}}}}}} private void _stopme () {Lock (this) {this. ISSTOP = true;}} private void _forcedSubthread (thread T) // Force stop thread {T.abort (); t.join ();} catch (exception) {}} // private function area // // public functions attribute area public bool Init (string CMPPServer, int CMPPPort) {return (this._init (CMPPServer, CMPPPort));} public bool Init (string CMPPServer, int CMPPPort, 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, CMPPPPORT);} public bool login (string systemid, string username, string password) {Try {sendlogin (SystemID, Username, Password); THISLOGLASTOKTIME (DateTime.Now); // The last correct transmission} catch (socketexception se) {// Send an error this.Errorinfo = this.ErrorInfo "/ r / n" Se.Tostring (); 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) {onLogonSuccEventHandler (this, e);} else {this.defaultConnectRespEventHandler ();} this.isLogin = true;} else {} break;}} this._lastOkTime = DateTime.Now; // Update the current final success transceiver units Time} catch (socketexception) {} system.timespan t = datetime.now - t1; if (t.totalseconds> 10) {Break;}}} {// Log in OK, immediately send Active_test package this.errorinfo = this.Errorinfo "/ r / n" "logon succ!"; startthreads (); // Start the main monitor DE 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; // charged under Article 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; sndmsg.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 svccode, 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_format.gb2312; sndmsg.sms_content.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 (seq);} public uint sendSMC (String Fee_user, string feecode, string svccode) // Send a monthly billing information {uint seq = this.getNextSequence () // to the billing user .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; // monthly billing sndmsg.FeeTerminalId = fe E_USER; SNDMSG.FEEUSERTYPE = (int) msg.FeeUsertype.Fee_terminal_id; // Billing Sn 3Msg.SPID = this.SystemID; // Corporate code Sndmsg.udhi = 0; // sndmsg.msgformat = uint) MSG.Msg_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_MONTH; / / Month metric Sndmsg.FeeterminalId = to_User; SndMsg.FeeUsertype = (int) msg.FeeUsertype.Fee_terminal_id; // Billing Snmsg.SPID = this.systemID; // Corporate code SNDMSG. UDHI = 0; // sndmsg.MSGFormat = (uint) MSG.Msg_Format.UCS2; sndmsg.SMS_Content = content; sndmsg.SrcID = spnum; // sp special symbol 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.addToOoutQueue (q); return (SEQ);} public uint sendquery (String svccode, String Whichday) // Query a total of a total of total count {String wd = whichday.trim (); int query_type = 0; if (svccode == null || svcccode.compareto (") == 0) {// query All pages} else {// Query a business query_type = 1;} if (wd == null || WD.Compareto (") == 0) {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 that day QueueItem Q = New QueueItem (SEQ, (UINT) msg.cmpp_command_id.cmpp_query, 0, 0); Q.SETMSGOBJ (QUERY); this.addTooutQueue (q); return (SEQ) ; // Return the internal number of the message} public uint stopcmppconnection () // Stop the Socket connection of the CMPP protocol {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 message Internal Number} Public Void Stopme () {if (! This.isstop) {if (this.tcpiscanuse ()) // Send a notification of the server {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.onclientsvcs ! TopedHandler = null) {ClientQueueStateArgs arg = new ClientQueueStateArgs (this._outSeqQueue, this._waitingSeqQueue); onClientSvcStopedHandler (this, arg);} else {this.defaultClientStopEventHandler ();} Thread.Sleep (500); // wait again active Thread end // Reports information in 2 queues in 2 queues} // Prepare for forced end _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 () {string t = this.Errorinfo; this.ERRORINFO = ""; RETURN (T);

} Public int getQueItemState (uint seq) // Find the status of the message object for the transmit internal queue {INT STATUS = 0; // (this._outseqqueue.containskey) // {IF in OutseqQueue (this._waitingseqqueue.contains (seq)) {// is sending waiting returns, status undecided} else {// has not sent}} else {if (this._waitingseqqueue.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 (); /// preparing 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; // Terminal user billing Sndmsg.msg_level = 0; sndmsg.msgformat = (uint) msg.msg_format.ucs2; sndmsg.sms_content = "test"; s ndmsg.srcid = "09880"; // long number Sndmsg.spid = this.systemid; sndmsg.svc_code = "cmcctest"; SNDMSG.UDHI = 0; sndmsg.validtime = getValidTime (datetime.now); // Survey 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 T2}}} DateTime T2}}} T = T2-T1; this.Errorinfo = this.Errorinfo "/ r / n" "Send:" Total "Bill message, total spending time:" T. TotalmilliseConds "Mix";} // Test Function for test mobile network test // Test the number of people /// // Common function attribute zone} // ************ Tool class end ********* ************************* Enum msg_state // CMPP message in the queue status enumeration value {new = 0, // Add to Queue Waiting Send it out to sending = 1, // is being locked by a thread, sended_waitting = 2, // Send out, waiting for the ResP message to return sending_finished = 3 // Get a response, generally waiting cleaning out queue} public class queItem // represents one The message stored in the cache queue, the serial number generates {uint _SEquence; // message index is the category of the water number uint _msgtype; // message is command_id, determine the original type INT _FAILEDCOUNT = 0 of Object _msgobj according to this value. / Failure count, if the number of failures 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 _inqueuetime; // message entries The time of the queue, the send time of the last message public int failedcount {set {this._failedcount = value;} get { return (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

DateTime.now.tolocaltime ()); sw.close ();}} public class reporteventArgs: Eventargs // Reporting the data portable data {string _smste; // Send SMS response results, meaning the STAT field definition in the SMPP protocol requirements the same. 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; // reported submitted MSGID, ismg returned to sp {return (this._smsstate);} set {this._smsstate;} set {this._smsstate = 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) // get reports from one byte array {byte [] Temp = New Byte [8 7 10 10 21 4]; for (int i = 0; i

} Public DateTime getSubmitTime () {return (getTime (this._submitTime));} public DateTime getDoneTime () {return (getTime (this._doneTime));} private DateTime getTime (string time_string) {int index = 0; int yy = Convert.TOINT32 ("20" Time_String.SubString (INDEX, 2)); IND MM = Convert.Toint32 (Time_String.Substring (INDEX, 2)); Index = 2; int DD = Convert.Toint32 (time_string.Substring (index, 2)); index = 2; int hh = Convert.ToInt32 (time_string.Substring (index, 2)); index = 2; int 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 int 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._smsstate = 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 the target ID string _svcccode; // service code int _tppid; // Reference GSM protocol INT _TPUDHI; // int _msgfrm; // message encoding _srcterminateID; // Source terminal ID, if the number of bytes of the report INT _MSGLENGTH; // message,

Not actual string length string _Content; // message body content public smseventargs (byte [] bs) {int msglen = bitconverter.toint32 (BS, 8 21 10 1 1 1 21 1); //// Number 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

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: Break; 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

} public object getmsg ()} public object getmsg () {return (this._msg);} public uint sequence {set {this._seq = value;} Get {return (this._seq);}}} public class testargs: EventArgs {private uint _seq; private MSG.CMPP_MSG_TEST _msg; public TestEventArgs (uint seq) {this._seq = seq;} public TestEventArgs (object msg) {this._msg = (MSG.CMPP_MSG_TEST) 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 testrespeventArgs: Eventargs { private uint _seq; private MSG.CMPP_MSG_TEST_RESP _msg; public TestRespEventArgs (uint seq) {this._seq = seq;} public TestRespEventArgs (object msg) {this._msg = (MSG.CMPP_MSG_TEST_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 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.Sequence;} 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 getQueItem () {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 ClientQueueStateArgs (SortedList outQueue, SortedList inQueue) {this._waiting = inQueue; this._out = outQueue;} public SortedList WaitingQueue {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; // How many Byte data} public enum smsdbqueue_status: int {new = 0, // new news, wait to send sended = 1, // is sending, waiting to respond to resp = 2, // to send SMSC, get msgid delivrd = 3, // Get report, status ok expired = 4, // expetted = 5, // has deleted this message Undeliv Acceptd = 6, // acceptd status is not delivered to accepted as an intermediate state, the gateway should be discarded after receiving the SMS center, Do not do any operation undeliv = 7, // Not delivered unknown = 8, // unknown Rejectd = 9 // Bound back} public class smsdbqueue {private uint _sequence = 0; // Corresponding cmppclient serial number private int _SMSDBID = 0; // The corresponding database Send automatic growth id private int _cmpp_msgtype; // CMPP The message type of the protocol is private object_cmpp_msg_object; // cmpp message object, 备, 备用 p 消 _ 体 = = =;; in 体 体 体 体 产生 产生; 设;;; 产生; 产生 产生 设; The returned SMSC gives the ID traffic 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 external SMS storage systems ***** **************** PUBLIC Interface IsMSTORE / / Define a storage interface {smsrec [] getSMSSFromStore (); // Get a message from external storage Void UpdateStoreObjec (int S toreObjectID, string state); // update id object represented by the state, for monitoring the status report void updateSMSCMsgID (int storeObjectID, UInt64 msgid); bool addSMS2Store (SMSRec sms); // to store the short message stored string getFeeCode (string svccode ); // according to the fee of the message returned to the message, set the expression in the PUBLIC CLASS SMSREC / / SMS Database {Private INT _RECID; private string _feeuser; // accounting user private int _SMSTYPE = 0; / / SMS type 0 normal text message SMS 1 flashing SMS 2 query command SMS 3 package monthly SMS private string _svcode; // service code private string _msg; // message private string _state; // message status prince _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._toUser = feeuser; this._svccode = svccode; this._msg = msg; this._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 (} set {this._svccode = value;}} public string feecode {get {return (this._feecode);} set {this._feecode = value;}} public string feeuser {rary (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._m SG = Value;}}} // **************************** Interface class end ******** ********************************************************** ** Define the SMS system class that handles the database interface, which provides CMPP processing function ********** // ** function, realizing queue monitoring, processing fail messaging, success message, processing timing storage update organizations abstraction function will CMPPClient package provides public class SMSSystem {private iSMSStore dbcls = null; private CMPPClient client = null; private string pwd; private string systemid; private string spnum; public void setISMSStoreInterface (iSMSStore ismsstore) {dbcls = ismsstore; } Public smssystem (String SystemID, String SPNUM, String Password, String CMPPServerip, int CMpport) {Client = New CMPPCLIENT ();

Client.init (cmppserverip, cmpport); this.spnum = spnum; this.systemid = systemId; this.pwd = password;}} // ***************************** ************ Handle the SMS system class end 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 SMS reply CMPP_ACTIVE_TEST = 0x00000008, // activating the test CMPP_ACTIVE_TEST_RESP = 0x80000008 // activation test Answer} public enum feeusertype {feed_rminal_id = 0, // feed_source_id = 1, feed = 2, Fee_Null = 3} public enum msg_format {ascii = 0, Writec ARD = 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 *********************************** ********* // ************************************************* ***************** public class CMPP_MSG_Header // message header {private byte [] initValue = new byte [MSG.CMPP_MSG_Header.HeaderLength]; public CMPP_MSG_Header (CMPP_COMMAND_ID command_ID) // send Before {BICONVERT.INT2BYTES ((UINT) Command_ID) .copyto (InitValue, 4);} public cMPP_MSG_Header (byte [] bs) // According to byte Line-based byte sequence {int L = msg.cmpp_msg_header.HeaderLength; for (int i = 0; i

}}} Public uint command_id {get {return (Biconvert.Bytes2uint (InitValue, 4));} set {byte [] t = biconvert.int2bytes (value); for (int i = 0; i <4; 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 into byte } Public void frombytes (byte [] bs) {for (int i = 0; i

) {TEMP [i] = BS [i];} Byte [] body = new byte [BS.LENGTH - msg.cmpp_msg_header.HeaderLength]; for (int i = 0; i

GetTimeStamp (); // Get the value of the authentication code 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 () // Returns the byte array impression of the current object {byte [] Reval = new byte [msg.cmpp_msg_header.HeaderLength this.bodylength]; header.tobytes (). Copyto (Reval, 0); // message heads 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 [] temp_head = new Byte [MSG.CMPP_MSG_Header.HeaderLength]; int index = 0; for (int i = 0; i

} Public bool isOk {get {return (true);}} public string Ver {get {return (Convert.ToString (this._Version, 16));}} 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 {Get { return (header.SequenceId);}}} public class 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; // Does whether the state report INT _MSGTOTAL = 1; // The number of rods of the same message int _msgnumber = 1; // int _msglevel = 0; // message level, Covered 0 string _svcode = ""; // Business type int _feeusertype = 0; // billing user type field 0: Getting on the destination terminal MSISDN; 1: For the source terminal MSISDN fee; 2: Betting on SP; 3: indicates that this field is invalid, please refer to Who for the FeE_Terminal_ID field string _feeterminalid = ""; // By accounting terminal INT _TPPID = 0; int _tpudhi = 0; uint _msgfmt = 0; // message format string _msgsrc = "" ; // message Source, SPID STRING _FEETYPE = msg.Feetype.Fee_Terminal_PerItem; // String _feecode = ""; // tariff string _validtime = ""; // Survival String _attime = "; // Scheduling time string _srcid = ""; // source number, the number INT _DESTUSRNUM = 0 displayed on the phone; // String [] _DestTerMinalids = new string [] _Destterminalids = new string [] _DestTerminalIDS = new string [100]; // up to 100 numbers INT _MSGLENGT = (int) MSG.Msg_Format.GB2312; string _MsgContent = ""; UInt64 _MsgID; // returns the message ID public CMPP_MSG_SUBMIT (uint sequence) {header = new MSG.CMPP_MSG_Header (CMPP.YOURCOMPANY.MSG.CMPP_COMMAND_ID.CMPP_SUBMIT); head er.SequenceId = sequence;} // Properties public string SMS_Content {set {this._MsgContent = value; byte [] t = Encoding.ASCII.GetBytes (value); this._msgLengt = t.Length;}} public int SMS_Delivery_Type / / Whether to return status confirmation report: 0: No need 1: Need 2: Generate SMC bill (This type of SMS is only for gateway billing, does not send to destination terminal) {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 long number {set { THIS._SRCID = Value;}} public string feetype {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 = value;} get {return (this._msgid);}} // Attribute End // Public Void AddterminalId (String ID) {IF (this._destusRnum <100) {this._destuserids [this._DestusRnum ] = ID;}} public Byte [] Tobytes () // Return to byte 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.ascii.getbytes; spid.copyto; index = index 6; Byte [] feetype = encoding.ascii.getbytes (this._feetype); Feetype.copy; index = index 2; byte [] feecode = encoding.ascii.getbytes; feecode.copy (SubmitData, Index); index = index 6; // byte [ ] ValidTime = Encoding.ascii.getbytes; //validtime.copy; ingx = index 17; // Byte [] attime = encoding.ascii.getbytes; / /attime.copy; index = index 17; Byte [] srcid = encoding.ascii.getbytes (this._srcid ); Srcid.copy (SubmitData, index); index = index 21; SubmitData [index ] = (byte) this._destusRnum; for (int i = 0; i

(Byte) msg.Length; // Reset length index = index msg.Length; Break; case (uint) msg.msg_format.binary: msg = encoding.ascii.getbytes (this._msgcontent); msg.copyto (SubmitData) , index; submitdata [index-1] = (byte) msg.Length; // Reset length index = index msg.Length; Break; case (uint) msg.msg_format.gb2312: msg = encoding.default.Gettes (THISG.COPYTENT); Msg.copyTo (SubmitData, Index); SubmitData [index-1] = (byte) msg.Length; // Reset length index = index msg.length; break; case (uint) msg .Msg_format.ucs2: msg = encoding.biGendianunicore.getbytes; msg.copyto; submitData [index-1] = (byte) msg.Length; // Reset length index = index msg.Length; Break; case (uint) msg.msg_format.writecard: // write card operation msg = encoding.ascii.getbytes (this._msgcontent); msg.copyto (SubmitData, index); submitData [index-1] = (Byte) msg.Length; // Reset length index = index msg.length Break; default: msg = encoding.ascii.getbytes; msg.copyto; submitdata [index-1] = (byte) msg.Length; // Reset length index = index msg.Length; Break;} index = index 8; // 8 reserved bytes} Header.msglength = (uint) index; // Determine the transmission data byte length byte [] Reval = new byte according to INDEX [index]; header.tobytes (). COPYTO (REVAL, 0); for (int i = msg.cmpp_msg_header.HeaderLength; i

Byte [] initValue; public cMPP_MSG_SUBMIT_RESP (Byte [] BS) {initValue = new byte [bs.length]; for (int i = 0; i

}} Public CMPP_MSG_QUERY (uint sequence) {header = new MSG.CMPP_MSG_Header (MSG.CMPP_COMMAND_ID.CMPP_QUERY); header.SequenceId = sequence;} public byte [] toBytes () {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 M SG.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 (t his._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.ASCII.GETSTRING (BS, INDEX, 21); index = index 21; this._svccode = encoding.ascii.getstring (BS, INDEX, 10); index = index 10; thermo_tpid = (int) BS [Index ]; this._udhi = (int) BS [index ]; this._msgfmt = (int) BS [index ]; this._srctid = encoding.ascii.getstring (BS, INDEX, 21); Index = 21; if (BS [index ] == 1) {this._isreport = true;} else {this._isreport = false;} this._msglength = (int) BS [DEX ]; if (! This._isreport) { Switch (this._msgfmt) {case (int) msg.msg_format.ascii: this._msg = encoding.ascii.getstring (BS, INDEX, THIS._MSGLENGTH); Index = this._msglength; break; 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._MSGLLENGTH); 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 {// this status report ._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.tostring (BS, INDEX, 10); INDEX = 10;

this._reportDesttid = BitConverter.ToString (bs, index, 21); index = 21; this._smscSequence = (int) BIConvert.Bytes2UInt (bs, index);}} public bool isReport {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 {income (this._msgid) to the application;}} public string statereport {get {{return (this._reportstate);}}} PUBLIC UInt64 ReportMsgID {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 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 [] r eVal = 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 @};

转载请注明原文地址:https://www.9cbs.com/read-102892.html

New Post(0)