CMPP SP end C # instance

zhaozj2021-02-16  89

Resource Download: http://download.9cbs.net/detail/shanhe/7538425

// attached CMPPClient.cs: / * Author: TNT Time: December 2003 File Description: This document implements the protocol developed SP side. * / using system.security.cryptography; using system.net.sockets; using system.net; using system.threading; using system.collections;

namespace CMPP.YOURCOMPANY {public delegate void ReportEventHandler (object sender, ReportEventArgs e); // declare a refer event (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 QueryrespeventHandler (Object Sender, Queryrespeventargs E); Public Delegate Void LogonsucceventHandler (Object Sender, Eventargs E); // When successfully logging in system public delegate void SocketClose DeventHandler (Object Sender, Eventargs E); // When the socket is detected to close the public delegate Void FailediteMdeDeleteDeventHandler (Object Sender, Waiting QueueItem "E); // 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

///

/// As the client of the CMPP protocol, the login, send, acceptable function /// will open 3 thread processing: 1, the processing needs to send MO (downlink) /// 2, Processing message from the mobile server over CMPP /// 3, processing connection breaks 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 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 (); // message queue storage QueueItem pri vate int sub_resp = 0; // return the last packet Sequence private DateTime _lastOkTime; // last time to send the correct message private bool _bNre = false; // null reference error, socket error // private ManualResetEvent _connectionDone = new ManualResetEvent (false ); // is connected to the socket server, that is, the CMPP server // private manualReseTevent_lastsendddone = new manualRetevent (false); // Last transmission is over // private manualReveTevent _lastRecvdone = new manualReseTevent (false); // One receives whether the PRIVATE VOID PING () // Sends a PING package, without the _outseqqueue is stored 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 survival time {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.toTString (). Padleft (2, '0') n. Second.toString (). Padleft (2, '0') "032 ");} private bool ispingTime () // Whether to get a time at Ping {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 () / / Is there any ping // query _waitingseqqueue exists whether there is no corresponding message {// survey Waiting Queue all messages, if the income time exceeds 60 for (int i = 0; I CMPPClient.CMPP_ACTIVE_TEST_T_TICKs) // {// timeout period needs to resend the message if (q.FailedCount> = CMPPClient.CMPP_ACTIVE_TEST_N_COUNT) {// report message transmission failure if (this.onWaitingItemDeltedHandler! = null) {WaitingQueueItemEventArgs E = New WaitingQueueiteMeventArgs (q); this.onwaitingItemDeltedHandler (this, e);} this.delfromwaitingQueue (q);

// From the waiting queue to delete the //q.msgState = (int) msg_state.sended_waitting;} else {// can try to continue 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.STMSGOBJ (MSG); // Set the message to Object Return (Q);} Private QueueItem getOutqueueItem (uint seq) // Get Message items in the MT queue {Return (QueueItem) this._outseqqueue [seq]);}} Private queueItem getWaitingQueueItem (uint seq) // Gets the message in the waiting queue {Return (QueueItem) this._waitingseqqueue [seq]);} private void addTooutQueue (QueueItem Q ) {Lock (this) {this.add (q.sequence, q);}} private void addtttowaitingQueue (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

}}} Return (NULL);} private arraylist gettop16queue () // Returns 16 top messages {Int arrlength = 0; ArrayList Rearr = new arraylist (); queueItem q = gettopoutqueue (); while (q! = Null || arrlength <= 16) {if (q! = null) {REARR.Add (q); arrlength ;} else {breaf;} q = gettopoutqueue ();} if (arrlength> 0) {RETURN (REARR); } else {return (null);}} private void delFromOutQueue (QueueItem q) {lock (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) {// Send login verification package systemID = SystemID; userName = spNum; PassWord = Password; uint seq = this.getNextSequence (); // get a serial 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; 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_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 (); // 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 (); // Take it in the send queue; 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 (TH is) {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 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 (); // 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 (); // Take it in the send queue; 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 queue Take it out; Lock (this) {OutItem.msgState = (int) msg_state.sending; this.delfromoutqueue (SEQ); this.addtowaitingQueue (OutItem);} tcp.send (Submit.Tobytes ()); outtem.msgState = INT) msg_state.sending_finished; breaf; case (uint) msg.cmpp_command_id.cmpp_terminate: msg.cmpp_m SG_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 (); NullReferenceException NRE) {this._bnre = true; // Empty quotation error this.Errorinfo = this.Errorinfo "/ r / n" nre.tostring ();}} private bool tcpiscanuse () // does not use {BOOL REVAL = TRUE; DateTime T = DateTime. Now; Timespan TS = T- this._lastoktime; if (ts.totalseconds> cmppclient.cmpp_active_test_t_ticks) // 60 second {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 loglastocktime (limited) {loc (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 = new msg.cmpp_msg_test (q.sequence); // Immediately send package past q.setmsgobj (TEST); THIS. AddToOutqueue (} 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 Receive // ​​Analysis Received data msg.cmpp_msg_header header; // = new msg.cmpp_msg_header (RBUF, INDEX); // Get a message WHILE (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.SEQUENCE; / / Looking for the message once this.delfromwaitingQueue (seq); // Delete the message in the waiting queue // Clear Waiting for the 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); // configuration message seq = cancel_reply.Sequence; this.delFromWaitingQueue (seq); if (this.onCancelRespHandler = null!) {CancelRespEventArgs e = new CancelRespEventArgs (cancel_reply); onCancelRespHandler (this, e) } Else {defaultcance ();} 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 " (" receive: 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 connectionrespeventargs (cn_reply); onConnectResphandler (this, e);} else {defaultConnectrespeventHandler ();} if (cn_reply.Isok) {this.islogin = true; Else {this.islogin = false;} this.delfromwaitingQueue (seq); // Remove 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 fail , Correctly handle the status package, not the status package to save to the Mo cache, indicating that the information is received, when 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 ;

// sent over the serial number, you need to send immediately a deliver_resp // a 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) {//// Deleting a message // report message on the wait queue is sent correctly to // uint64 reportmsgid = DELIVER.REPORTMSGID; / / get the message ID, update the 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 21 10 1 1 1 21 1 1); // event reporting configuration parameters // ReportEventArgs arg = new ReportEventArgs (ReportMsgID .Tostring (), if (this.onReportHandler! = Null) // ReportEventArgs passed byte array is the data of the report packet, where multiple reports are not considered {onReportHandler (this, arg);} else {THIS .DEFAULTREPO rtHandler ();}} 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 events, should be completed soon, do not rely on considering resource-consuming resources} else {defaultsmshandler ();}} Break; case (uint) msg.cmpp_command_id.cmpp_query_resp: this.Errorinfo = this.ERRORINFO "/ R / N " (" Received: CMPP_QUERY_RESP "); // Received the message,

After processing into the database MSG.CMPP_MSG_QUERY_RESP query_resp = new MSG.CMPP_MSG_QUERY_RESP (the_pk); this.delFromWaitingQueue (query_resp.Sequence); // wait queue the element deletion 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 " (" received: 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: //cmpp_submit_resp.txt"); // Reserved Image Sub_Resp ; // This variable is for testing only using DelfromwaitingQueue (Submit_resp.sequence); // Remove Message IF you need to wait (this.OnSubmitResphandler! = null ) {Submitrespeventargs E = new submitrespeventargs (submit_resp); // su . Bmit_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" "closed To: cMPP_TERMINATE_RESP ";

TCP.Send (Terminate_resp.tobytes ()); if (this.onterminateHandler! = null) {TerminateEventArgs E = New TerminateEventArgs (Terminate); THISTOPME (); 帖子 帖子 帖子Else {DefaultTerminateEventHandler ();} this._stopme (); // Send Termination Return; // Exit Thread Case (UINT) msg.cmpp_command_id.cmpp_terminate_resp: this.ErrorInfo = this.ErrorInfo "/ R / N" "received: 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 {defaultterminaterespeventhandler (); }im ();} .._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 deamthread () // Monitor this system connection 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 second 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, allow the system to automatically check the message queue, store the message status in the message queue}} else {Eventargs E = New EventArgs (); if (this.onsocketclosedhandler! {OnSocketCloseDHandler (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 Top Messages IF (Lists! = Null && Lists.count> 0) {INT Count = Lists.count; 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 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.now; // update the current last successful transceiver socket time} catch (socketexception) {} system.timespan t = datetime.now - T1; IF (T. Totalseconds> 10) {Break;}} {// Login OK, immediately send an active_test package this.ErrorInfo = this.Errorinfo "/ r / n" "Logon succ ";! startThreads (); // start the main thread monitor de 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.feetypeType.Fee_terminal_PerItem; // Take Sndmsg.Feeusrtype = FeE_USG_LEVEL = 0; SNDMSG.MSGFORMAT = (U int) 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; 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; // charging in a charging Number 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 (seq );} public uint SendSMC (string fee_user, string feecode, string svccode) // send the user a monthly billing to the billing information {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.FeetypeTerminalId = FeE_User; sndmsg.Feeusertype = (int) msg.Feeusertype.Fee_Terminal_ID; / / Billing Snmsg.SPID = this.systemID; // Enterprise Code Sndmsg.udhi = 0; // sndmsgmat = (uint) msg.msg_Format .Ucs2; sndmsg.sms_content = "SMC"; SNDMSG.SRCID = this.userName; // SP character number Sndmsg.svc_code = svcccode; 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; // monthly basis Fee Sndmsg.FeterminalId = 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.addToOutQueue (q); return (seq);} public uint sendquery (String svccode, string whichday) // query 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 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 socket connection protocol CMPP {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); // Return to termination message, easy to wait} 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.addToOutQueue (q); return (seq); // Return to the internal number of the message} PUBLIC VOID Stopme () {if (! This.isstop) {if (this.tcpiScanuse () ) // send an advertisement to 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.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.u CS2; sndmsg.SMS_Content = "test"; sndmsg.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 ()); // Deposit in array}} DateTime T1 = DateTime.now; for (int i = 0 i

} Catch (socketexception se) {this.Errorinfo = this.Errorinfo "/ r / n" "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 "Bill news, total spending time:" T. TotalmilliseConds "Mix";} // Test function for test mobile network test // Test Han number area // // Common Function Properties 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 out sending = 1, // is being locked by a thread Sended_Waitting = 2, // Send it, wait a resp message to return Sending_finished = 3 // Get a response, generally waiting cleaning out queue} public class QueueItem // represents a message stored in the cache queue, the serial number generates {uint _sequence; // message index is the water number uint_msgtype; / The category of / message is command_id, determine the original type INT _FAILEDCOUNT = 0 of Object _msgobj according to this value, if the number of failures exceeds 3 this need to clean the int _msgState; / / current message state, specifically MSG_State enumeration Type Object_msgobj; // Store message object, specific type reference _MSGTYPE dateTime _in Queuetime; // Message to enter the queue time, the last message transmission time public int failedcount {set {this._failedcount = value;} Get {return (this._failedcount);}}} public object getmsgobj ()} (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};} 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 network format Convert to memory format {public static Byte [] int2bytes (uint i) // Transfer {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 bytes2uint (byte " BS, int StartIndex) // Return the integer number of the byte array representative, 4 array {byte [] t = new byte [4]; for (int i = 0; i <4 && i

Public static void dumpbytes (byte [] bs, string txt) {system.io.streamwriter sw = new system.io.StreamWriter (txt); for (int i = 0; i

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

} Private DateTime getTime (string time_string) {int index = 0; int yy = Convert.ToInt32 ( "20" time_string.Substring (index, 2)); index = 2; int mm = Convert.ToInt32 (time_string.Substring ( Index, 2)); INDD = 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 = communication.Toint32 (Time_String.Substring (INDEX, 2)); DateTime T = New DateTime (YY, MM, DD, HH, MMS, 0); Return (T);} private void Init (Byte [ ] BS) {Biconvert.dumpbytes (BS, "C: //reportEventArgs.txt"); // Reserved Image INDEX = 0; this._msg_id = bitconverter.touint64 (BS, Index); //bitconverter.touint64(BTCONVERTER.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 = encod ING.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: 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 TestRespEventArgs (object msg) {this._msg = (MSG.CMPP_MSG_TEST_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 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 WAITINGQUEITEMEVENTARGS (Object Q) {this._q = q;} public uint sequence {set {this._seq = value;} Get {return (this._seq);}} public object getQueItem () {RETU RN (THIS._Q);}} public class clientqueuestteatArgs // 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, wait to send sended = 1, / / Send, wait for response to resp = 2, // to send SMSC, get msgid delivrd = 3, // Get report, status OK Expired = 4, // Expired DELETED = 5, // has been removed this message Undeliv Acceptd = 6 The // ACCEPTD status is not delivered to accepted as an intermediate state, if the gateway should be discarded after receiving the SMS center, do not do any operation undeliv = 7, // Not delivered unknown = 8, // Unknown Rejectd = 9 // Rebound }

public class SMSDBQueue {private uint _sequence = 0; // cmppclient sequence number corresponding private int _smsdbID = 0; // automatic transmission corresponding increase ID private int _cmpp_msgType database; // protocol defines message type cmpp private object _cmpp_msg_object ; // CMPP message object, check the private int _CurrentStatus; // Current Message Status Private DateTime _inqueUetime = DATETIME.NOW; // Message Generate Setpoint Private Uint64_MSGID; // The message returned by the SMSC

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 *********************************

// ************************************************************************************************************** ***** Public interface ismster // Defines a storage interface {smsrec [] getSMSSFromStore (); // Get the message Void UpdateStoreObject (Int StoreObjectID, String State); / / Update the object status of the ID, with In the monitoring status report Void UpdatesMscmsgid (int storeObjectID, UINT64 MSGID); Bool AddSms2Store (SMSREC SMS); // Store short message String getFeecode (String svccode) to the Store; / / According to the charge of the message according to the SVCCode, set 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._svcccode);} 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 feet {public static ready 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";} // ************ * End of structural type ********************************** * ********* ******* Message ********************************************** 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) // before sending {BIConvert.Int2Bytes ((uint) command_ID) .CopyTo (initValue, 4);} Public CMPP_MSG_HEADER (Byte [] BS) // Concrete 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

New byte [msg.cmpp_msg_header.headerLength]; for (int i = 0; i

// source_add is the enterprise code byte [] S_0 = {0, 0, 0, 0, 0, 0, 0, 0, 0}; // 9 bytes 0, this is treated as the right complement 0 byte [] s_p = Encoding.ascii.getbytes (_password); // Password this._timestamp = getTimeSTAMP (); // Get the authentication code to assign a value string Byte [] s_t = encoding.ascii.getbytes (_TimeStamp); // 10 characters 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.couth (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 of current objects {byte [] revAL = new byte [msg.cmpp_msg_header.HeaderLength this.bodylength]; header .tobytes (). COPYTO (REVAL, 0); // Message head getSourceAdd (). COPYTO (REVAL, MSG.CMPP_MSG_HEADER.HEADERLENGTH); // Source address GETMD5CODE (). COPYTO (REVAL, Msg.cmpp_msg_Header.Headerlength 6); // Certified MD5 Reval [msg.cmpp_msg_header.HeaderLength 6 16] = this.Ver; // version byte B IConvert.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

// Status byte Authenticatorismg = new byte [16]; // Responding to summary for (int i = 0; i

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; // whether the status report int _msgTotal = 1; // number of the same message int _msgNumber = 1; // int _msglevel = 0; // message level, winning 0 string _svcccode = ""; // Business type int _feeusertype = 0; // billing user type field 0: Terminal to destination terminal MSISDN; 1: Source Terminal MSISDN fee; 2: For SP charging; 3: indicates that this field is invalid, please refer to Who for FEE_TERMINALID = ""; // Betting Terminal INT _TPPID = 0; int _tpudhi = 0; uint _msgfmt = 0; // message format string _msgsrc = ""; // message source is spid string _feetype = msg.Feetype.Fee_terminal_PerItem; // String _feecode = ""; // tariff string _validtime = ""; // Survogenic String _attime = ""; // Scheduling time string _srcid = ""; // The source number is the number INT _DESTUSRNUM = 0 on the phone; // accepts the number of mobile phones to accept the message [] _DestTerminalIDS = new string [100]; // Ultach 100 Number INT _MSGLENGT = (int) msg.msg_format.gb2312 ; String _msgcontent = ""; uint64 _msgid; // returned 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 {t His._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 AddTerminalId (String ID) {IF (this._destusRnum <100) {this._destterminalids [this._DestusRnum ] = ID;}} Public Byte [] TobYtes () // Return to byte number impression {Byte [] SubmitData = new byte [400]; int index = msg.cmpp_msg_header.HeaderLength; // Current Package fill pointer {// process 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; svccode.copy (SUBMITDATA, INDEX); // Copy to Target INDEX = INDEX 10; // INDEX Add 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 ] = (B Yte) THIS._TPUDHI; SubmitData [INDEX ] = (byte) this._msgfmt; byte [] spid = encoding.ascii.getbytes; Spid.copyto (SubmitData, Index); index = index 6; Byte [] feetype = Encoding.ASCII.GetBytes (this._feeType); feetype.CopyTo (submitData, index); index = index 2; byte [] feecode = Encoding.ASCII.GetBytes (this._feeCode); feecode.CopyTo ( SubmitData, index; index = index 6; // Byte [] validtime = encoding.ascii.getbytes (this._validtime); //validtime.copy (SubmitData, index); index = index 17;

// Byte [] attime = encoding.ascii.getbytes (this._validtime); //attime.copy (SubmitData, Index); index = index 17; byte [] srcid = encoding.ascii.getbytes (this._srcid) Srcid.copyto; index = index 21; SubmitData [index ] = (byte) this._destusRnum; for (int i = 0; i

Encoding.ascii.getbytes; 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); 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 [index] according to 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_hea der (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 (Precision Day) Index = Index 8; Reval [Index ] = Convert.Tobyte (this._querytype); Encoding.ASCII.GetBytes (this._querycode) .copyto (REVAL); 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 = bico Nvert.bytes2uint (BS, INDEX); index = index 4; this._mo_fl = Biconvert.bytes2uint (bs, index);} public string time {get {return (this._time);}} public int}}} 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); in t 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.getstring (BS, INDEX, 10); index = index 10; this._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 [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; 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._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); Index EX = 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 (_ism);}} 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) to the application; _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 .Getb ytes (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 [] 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 isSucc {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_Header (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;

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

New Post(0)