<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    注銷

    注銷

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      112 隨筆 :: 7 文章 :: 18 評(píng)論 :: 0 Trackbacks

    //附CMPPClient.cs:
    /*
    作者:TNT?時(shí)間:2003年12月
    文件說(shuō)明:本文件實(shí)現(xiàn)SP端的協(xié)議開(kāi)發(fā)。
    */
    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);? //聲明一個(gè)事件的指代(指針)
    ?public delegate void SMSEventHandler(object sender, SMSEventArgs e);?? //聲明一個(gè)事件的指代(指針)
    ?public delegate void TerminateEventHandler(object sender,TerminateEventArgs e);?? //聲明收到終止信號(hào)
    ?public delegate void TerminateRespEventHandler(object sender,TerminateRespEventArgs e);? //回應(yīng)事件發(fā)生
    ?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); //當(dāng)成功登錄系統(tǒng)
    ?public delegate void SocketClosedEventHandler(object sender,EventArgs e); //當(dāng)套接字被檢測(cè)到關(guān)閉
    ?public delegate void FailedItemDeletedEventHandler(object sender,WaitingQueueItemEventArgs e); //當(dāng)一條等待隊(duì)列的消息超過(guò)60秒沒(méi)有回應(yīng)
    ?

    ?public delegate void CMPPClientSvcStopEventHandler(object sender, ClientQueueStateArgs e); //當(dāng)CMPP服務(wù)停止時(shí)候觸發(fā)事件

    ?/// <summary>
    ?/// 作為CMPP協(xié)議的客戶端,具有的登陸、發(fā)送、接受功能
    ?/// 會(huì)開(kāi)3 個(gè)線程處理: 1、處理需要發(fā)送 MO(下行)的消息
    ?///?????? 2、處理從移動(dòng)服務(wù)器發(fā)送過(guò)來(lái)CMPP的消息
    ?///?????? 3、處理連接斷等信息,檢查需要重發(fā)的消息,檢查收到的報(bào)告、短信,并調(diào)用 OnReport 事件 OnSMS事件
    ?/// </summary>
    ?public class CMPPClient
    ?{
    ??public static long?CMPP_ACTIVE_TEST_C_TICKs= 30? ;? // *3 ;? //長(zhǎng)連接的active_test測(cè)試時(shí)間
    ??public static long?CMPP_ACTIVE_TEST_T_TICKs= 60 ;??? // 消息失敗時(shí)間 60秒
    ??public static int?CMPP_ACTIVE_TEST_N_COUNT=3;? //3次?
    ??//public static int?CMPP_MSG_MAX=100;?? //一次取得的最大消息數(shù)量
    ??public static int?CMPP_Port=7890;
    ?
    ??public event ReportEventHandler onReportHandler;?? //指向事件處理代碼的指針
    ??public event SMSEventHandler onSMSHandler;???? //短信到來(lái)處理
    ??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; //當(dāng)?shù)却?duì)列消息超時(shí)
    ?
    ??public event CMPPClientSvcStopEventHandler onClientSvcStopedHandler;??//當(dāng)服務(wù)停止時(shí)候的事件

    ??//private 函數(shù)區(qū)域//////////////////////////////////////////////////////////////////////
    ??private Socket??tcp=null;????
    ??private IPHostEntry ip=null;??
    ??private IPEndPoint? cmpp_ep=null;??
    ??private int???RecvTimeOut =1000;?????? //2000ms的接受超時(shí)
    ??private int???SendTimeout =2000;?????? //2000ms的發(fā)送超時(shí)
    ??private string??CMPP_Server="";???//移動(dòng)的服務(wù)器IP或者DNS名
    ??private string??systemID="";???//企業(yè)編號(hào)
    ??private string??userName="";???//sp的號(hào)碼 /企業(yè)編號(hào)
    ??private string??PassWord="";???//口令?
    ??private bool??isStop=false;???//本服務(wù)是否終止運(yùn)行
    ??private bool??isLogin=false;???//是否已經(jīng)登錄???
    ??private?Thread??Send_Thread;???//發(fā)送線程,專門處理對(duì)移動(dòng)的數(shù)據(jù)包
    ??private Thread??Recv_Thread;???//專門處理接收包
    ??private Thread??Deamo_Thread;???//監(jiān)控線程
    ??private string??ErrorInfo="";???//存放最后一次發(fā)生的錯(cuò)誤信息 或者參考信息?????
    ??private DateTime?_current_time=DateTime.Now;???? //上一次 ping的時(shí)間?
    ??private uint??lastSequence;???//流水號(hào),每一次重新啟動(dòng)都需要重新設(shè)定 lastSequence
    ??private SortedList?_outSeqQueue=new SortedList();?? //消息隊(duì)列存儲(chǔ) QueueItem,存儲(chǔ)發(fā)送隊(duì)列中的狀態(tài)
    ??private SortedList? _waitingSeqQueue=new SortedList();?//消息隊(duì)列存儲(chǔ) QueueItem
    ??private int???sub_resp=0;???????//最后返回的包 Sequence
    ??private DateTime?_lastOkTime;??????//最后正確發(fā)送消息時(shí)間
    ??private bool??_bNre=false;??????//空引用錯(cuò)誤,套接字錯(cuò)誤
    ?
    ??//private ManualResetEvent _connectionDone=new ManualResetEvent(false); //是否連接到套接字服務(wù)器,也就是CMPP服務(wù)器
    ??//private ManualResetEvent _lastsendDone=new ManualResetEvent(false);? //上一次發(fā)送是否完畢
    ??//private ManualResetEvent _lastrecvDone=new ManualResetEvent(false);? //上一次接收是否完畢
    ??? ??
    ??private void ping()??? //發(fā)送一次ping包 ,不經(jīng)過(guò)_outSeqQueue 直接存儲(chǔ)在 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(q);
    ??}
    ??
    ??private string getValIdTime(DateTime d)??????? //返回短信存活時(shí)間
    ??{
    ???DateTime n=d.AddHours(2); //2小時(shí)
    ???return(n.Year.ToString().Substring(2) + n.Month.ToString().PadLeft(2,'0')+n.Day.ToString().PadLeft(2,'0')+n.Hour.ToString().PadLeft(2,'0')+n.Minute.ToString().PadLeft(2,'0')+n.Second.ToString().PadLeft(2,'0')+"032+");???????????
    ??}
    ?
    ??private bool isPingTime( )? //是否到了ping一次的時(shí)間
    ??{
    ???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()??? //是否需要再一次ping //查詢 _waitingSeqQueue 是否存在 上一次 沒(méi)有相應(yīng)的消息
    ??{?? //調(diào)查waiting queue 中的所有消息,如果入列時(shí)間超過(guò)60
    ???for(int i=0;i<this._waitingSeqQueue.Count;i++)
    ???{
    ????Thread.Sleep(20);
    ????QueueItem q=(QueueItem)this._waitingSeqQueue.GetByIndex(i);??
    ????if(q!=null)
    ????{
    ?????DateTime this_time=DateTime.Now ; //去當(dāng)前時(shí)間
    ?????TimeSpan t=this_time-q.inQueueTime ;
    ?????if(t.TotalSeconds >CMPPClient.CMPP_ACTIVE_TEST_T_TICKs ) //達(dá)到超時(shí)時(shí)間
    ?????{//需要重新發(fā)送消息
    ??????if(q.FailedCount>=CMPPClient.CMPP_ACTIVE_TEST_N_COUNT)
    ??????{
    ???????//報(bào)告消息發(fā)送失敗
    ???????if(this.onWaitingItemDeltedHandler!=null)
    ???????{
    ????????WaitingQueueItemEventArgs e=new WaitingQueueItemEventArgs(q);
    ????????this.onWaitingItemDeltedHandler(this,e);
    ???????}
    ???????this.delFromWaitingQueue(q); //從等待隊(duì)列中刪除
    ???????//q.MsgState =(int)MSG_STATE.SENDED_WAITTING;
    ??????}
    ??????else
    ??????{//可以嘗試?yán)^續(xù)發(fā)送
    ???????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)? //生成一個(gè)消息隊(duì)列成員對(duì)象實(shí)例
    ??{
    ???uint seq=this.getNextSequence();?? //
    ???QueueItem q=new QueueItem(seq,(uint)msgtype,0,msgstate);
    ???q.setmsgObj(msg);?????? //設(shè)定消息為 object
    ???return(q);
    ??}
    ?
    ??private QueueItem getOutQueueItem(uint seq)? //獲取MT 隊(duì)列中的消息項(xiàng)目
    ??{
    ???lock(this)
    ???{
    ????return((QueueItem)this._outSeqQueue[seq]) ;
    ???}
    ??}
    ?
    ??private QueueItem getWaitingQueueItem(uint seq)? //獲取等待隊(duì)列中的消息
    ??{
    ???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()???? //需要在取之前進(jìn)行判斷
    ??{
    ???for(int i=0;i<this._outSeqQueue.Count;i++)
    ???{
    ????QueueItem q=(QueueItem)this._outSeqQueue.GetByIndex(i);??
    ????if(q!=null)
    ????{
    ?????if(q.MsgState==(int)MSG_STATE.NEW)? //新消息,立即返回
    ?????{
    ??????lock(this)
    ??????{
    ???????q.MsgState =(int)MSG_STATE.SENDING;?//發(fā)送狀態(tài)
    ??????}
    ??????return(q);??
    ?????}
    ?????else
    ?????{
    ??????q=null;
    ?????}
    ????}
    ???}???
    ???return(null);
    ??}
    ?
    ??private ArrayList getTop16Queue() //返回16條最頂?shù)南?br />??{
    ???int arrlength=0;
    ???ArrayList reArr=new ArrayList() ;
    ???QueueItem q=getTopOutQueue();
    ???while(q!=null || arrlength <= 16)
    ???{????
    ????if(q!=null)
    ????{
    ?????reArr.Add(q);
    ?????arrlength++;
    ????}
    ????else
    ????{
    ?????break;
    ????}
    ????q=getTopOutQueue();
    ???}
    ???
    ???if(arrlength>0)
    ???{
    ????return(reArr);??
    ???}
    ???else
    ???{
    ????return(null);
    ???}
    ??}
    ?
    ??private void delFromOutQueue(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)
    ??{//發(fā)送登錄驗(yàn)證包???
    ???systemID=SystemID;
    ???userName=spNum;
    ???PassWord=Password;
    ???uint seq=this.getNextSequence(); //取得一個(gè)流水號(hào)
    ???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)//將QueueItem發(fā)送出去
    ??{
    ???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(); //發(fā)送隊(duì)列中取出
    ?????lock(this)
    ?????{
    ??????outitem.MsgState =(int)MSG_STATE.SENDING;
    ??????this.delFromOutQueue(seq);
    ??????this.addToWaitingQueue(outitem);??? //等待服務(wù)器的active_TEST_resp
    ?????}
    ?????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(); //發(fā)送隊(duì)列中取出//取出需要發(fā)送的具體消息
    ?????lock(this)
    ?????{
    ??????outitem.MsgState =(int)MSG_STATE.SENDING ;
    ??????this.delFromOutQueue(seq);
    ?????}
    ?????outitem.MsgState = (int)MSG_STATE.SENDING_FINISHED ;? //完成
    ?????return(test_reply.toBytes());
    ??????
    ??????
    ?
    ????case (uint)MSG.CMPP_COMMAND_ID.CMPP_CANCEL :
    ?????MSG.CMPP_MSG_CANCEL cancel=(MSG.CMPP_MSG_CANCEL)outitem.getMsgObj();??? //還原成消息類
    ?????lock(this)
    ?????{
    ??????outitem.MsgState =(int)MSG_STATE.SENDING ;
    ??????this.delFromOutQueue(seq);
    ??????this.addToWaitingQueue(outitem);??? //等待回應(yīng)
    ?????}
    ?????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(); //發(fā)送隊(duì)列中取出;
    ?????lock(this)
    ?????{
    ??????outitem.MsgState =(int)MSG_STATE.SENDING ;
    ??????this.delFromOutQueue(seq);
    ?????}
    ?????outitem.MsgState=(int)MSG_STATE.SENDING_FINISHED? ;? //完成
    ?????return (deliver_resp.toBytes());??????
    ??????
    ?
    ????case (uint)MSG.CMPP_COMMAND_ID.CMPP_QUERY? :
    ?????MSG.CMPP_MSG_QUERY query = (MSG.CMPP_MSG_QUERY )outitem.getMsgObj(); //發(fā)送隊(duì)列中取出;
    ?????lock(this)
    ?????{
    ??????outitem.MsgState =(int)MSG_STATE.SENDING? ;
    ??????this.delFromOutQueue(seq);
    ??????this.addToWaitingQueue(outitem);
    ?????}
    ?????outitem.MsgState =(int)MSG_STATE.SENDED_WAITTING ; //等待回應(yīng)
    ?????return(query.toBytes());??????
    ??????
    ????case (uint)MSG.CMPP_COMMAND_ID.CMPP_SUBMIT :
    ?????MSG.CMPP_MSG_SUBMIT submit =(MSG.CMPP_MSG_SUBMIT)outitem.getMsgObj(); //發(fā)送隊(duì)列中取出;
    ?????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(); //發(fā)送隊(duì)列中取出;
    ?????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(); //發(fā)送隊(duì)列中取出;
    ?????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(); //發(fā)送隊(duì)列中取出
    ?????lock(this)
    ?????{
    ??????outitem.MsgState =(int)MSG_STATE.SENDING;
    ??????this.delFromOutQueue(seq);
    ??????this.addToWaitingQueue(outitem);??? //等待服務(wù)器的active_TEST_resp
    ?????}
    ?????outitem.MsgState =(int)MSG_STATE.SENDED_WAITTING ;
    ?????return(test.toBytes());?
    ???}???
    ??}

    ??private void sendQueueItem(QueueItem outitem)//將QueueItem發(fā)送出去
    ??{
    ???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(); //發(fā)送隊(duì)列中取出
    ??????lock(this)
    ??????{
    ???????outitem.MsgState =(int)MSG_STATE.SENDING;
    ???????this.delFromOutQueue(seq);
    ???????this.addToWaitingQueue(outitem);??? //等待服務(wù)器的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(); //發(fā)送隊(duì)列中取出//取出需要發(fā)送的具體消息
    ??????lock(this)
    ??????{
    ???????outitem.MsgState =(int)MSG_STATE.SENDING ;
    ???????this.delFromOutQueue(seq);
    ??????}
    ??????tcp.Send(test_reply.toBytes());
    ??????outitem.MsgState = (int)MSG_STATE.SENDING_FINISHED ;? //完成
    ??????break;
    ?
    ?????case (uint)MSG.CMPP_COMMAND_ID.CMPP_CANCEL :
    ??????MSG.CMPP_MSG_CANCEL cancel=(MSG.CMPP_MSG_CANCEL)outitem.getMsgObj();??? //還原成消息類
    ??????lock(this)
    ??????{
    ???????outitem.MsgState =(int)MSG_STATE.SENDING ;
    ???????this.delFromOutQueue(seq);
    ???????this.addToWaitingQueue(outitem);??? //等待回應(yīng)
    ??????}
    ??????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(); //發(fā)送隊(duì)列中取出;
    ??????lock(this)
    ??????{
    ???????outitem.MsgState =(int)MSG_STATE.SENDING ;
    ???????this.delFromOutQueue(seq);
    ??????}
    ??????tcp.Send(deliver_resp.toBytes());
    ??????outitem.MsgState=(int)MSG_STATE.SENDING_FINISHED? ;? //完成
    ??????break;
    ?
    ?????case (uint)MSG.CMPP_COMMAND_ID.CMPP_QUERY? :
    ??????MSG.CMPP_MSG_QUERY query = (MSG.CMPP_MSG_QUERY )outitem.getMsgObj(); //發(fā)送隊(duì)列中取出;
    ??????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 ; //等待回應(yīng)
    ??????break;
    ?
    ?????case (uint)MSG.CMPP_COMMAND_ID.CMPP_SUBMIT :
    ??????MSG.CMPP_MSG_SUBMIT submit =(MSG.CMPP_MSG_SUBMIT)outitem.getMsgObj(); //發(fā)送隊(duì)列中取出;
    ??????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(); //發(fā)送隊(duì)列中取出;
    ??????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;???? //通知其他線程可以退出了
    ??????break;
    ?
    ?????case (uint)MSG.CMPP_COMMAND_ID.CMPP_TERMINATE_RESP :
    ??????MSG.CMPP_MSG_TERMINATE_RESP terminate_resp=(MSG.CMPP_MSG_TERMINATE_RESP)outitem.getMsgObj(); //發(fā)送隊(duì)列中取出;
    ??????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 );? //記錄當(dāng)前最后一次消息soket正確時(shí)間
    ???}
    ???catch(SocketException se)
    ???{
    ????//發(fā)生套接字錯(cuò)誤
    ????this.ErrorInfo =this.ErrorInfo +" "+se.ToString ();
    ???}
    ???catch(NullReferenceException nre)
    ???{
    ????this._bNre =true;? //出現(xiàn)空引用錯(cuò)誤
    ????this.ErrorInfo =this.ErrorInfo +" "+nre.ToString ();
    ???}
    ??}
    ?
    ??private bool tcpIsCanUse()? //測(cè)試當(dāng)前tcp是否可用
    ??{
    ???bool reval=true;
    ???DateTime t=DateTime.Now ;
    ???TimeSpan ts=t- this._lastOkTime;
    ???if(ts.TotalSeconds > CMPPClient.CMPP_ACTIVE_TEST_T_TICKs ) //60秒
    ???{
    ????reval=false;? //不可用
    ???}
    ???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;? //設(shè)定最后成功消息交互時(shí)間
    ???}
    ??}
    ?
    ??private void defaultReportHandler() //卻省的報(bào)告事件處理函數(shù)
    ??{
    ?
    ??}
    ?
    ??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 ); //立即發(fā)送包過(guò)去
    ???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); //連接
    ????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 +" "+ofe.ToString();
    ?????lastSequence=uint.MinValue;
    ????}???????
    ????return(lastSequence);
    ???}
    ??}
    ?
    ??private void RecvISMGMsgThread()?? //處理ISMG消息的線程
    ??{
    ???while(!this.isStop )
    ???{
    ????try
    ????{????
    ?????byte[] rbuf=new byte[10240];?//結(jié)果緩沖區(qū)
    ?????byte[] recv_temp=new Byte[1024];?//recv臨時(shí)緩沖區(qū)
    ?????int index=0;
    ?????int msglength=tcp.Receive(rbuf);? //阻塞接收//分析收到的數(shù)據(jù)
    ?
    ?????MSG.CMPP_MSG_Header header;? //=new MSG.CMPP_MSG_Header(rbuf,index); //取得一個(gè)消息???????????????????
    ?????while(index<msglength) //逐個(gè)消息分析
    ?????{
    ??????header=new MSG.CMPP_MSG_Header(rbuf,index); //取得一個(gè)消息??????
    ??????byte[] the_pk= new byte[header.MSGLength] ;?? //生成此消息的大小
    ??????for(int i=0;i<header.MSGLength ;i++)
    ??????{
    ???????the_pk[i]=rbuf[index++];
    ??????}??????
    ??????uint seq; //取得回復(fù)消息的下一個(gè)流水序列號(hào)
    ??????switch(header.Command_ID)
    ??????{
    ???????case (uint)MSG.CMPP_COMMAND_ID.CMPP_ACTIVE_TEST : //服務(wù)器給客戶的測(cè)試信號(hào)
    ????????this.ErrorInfo =this.ErrorInfo +" "+"收到:CMPP_ACTIVE_TEST";
    ????????MSG.CMPP_MSG_TEST test=new MSG.CMPP_MSG_TEST(the_pk);
    ????????seq=test.Sequence;?????? //取得發(fā)送過(guò)來(lái)的流水號(hào)
    ????????MSG.CMPP_MSG_TEST_RESP test_reply=new MSG.CMPP_MSG_TEST_RESP(seq);??
    ????????tcp.Send(test_reply.toBytes());??? //馬上送出回應(yīng)包,不需要進(jìn)入隊(duì)列?
    ????????if(this.onTestHandler!=null)
    ????????{
    ?????????TestEventArgs e=new TestEventArgs(test);
    ?????????onTestHandler(this,e);
    ????????}
    ????????else
    ????????{
    ?????????defaultTestEventHandler();
    ????????}
    ????????this.ErrorInfo =this.ErrorInfo +" "+"發(fā)送:CMPP_ACTIVE_TEST_RESP ";
    ????????break;
    ?
    ???????case (uint)MSG.CMPP_COMMAND_ID.CMPP_ACTIVE_TEST_RESP : //服務(wù)器的回應(yīng)消息,應(yīng)當(dāng)丟棄不管
    ????????this.ErrorInfo =this.ErrorInfo +" "+("收到:CMPP_ACTIVE_TEST_RESP ");
    ????????MSG.CMPP_MSG_TEST_RESP test_reply2=new MSG.CMPP_MSG_TEST_RESP(the_pk); //構(gòu)造消息
    ????????seq=test_reply2.Sequence;??? //尋找 曾經(jīng)發(fā)送過(guò)去的消息????????
    ????????this.delFromWaitingQueue(seq);????? //刪除等待隊(duì)列中的消息 //清空等待回應(yīng)隊(duì)列
    ????????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 +" "+("收到:CMPP_CANCEL_RESP ");
    ????????MSG.CMPP_MSG_CANCEL_RESP cancel_reply=new MSG.CMPP_MSG_CANCEL_RESP(the_pk);//構(gòu)造消息
    ????????seq=cancel_reply.Sequence;
    ????????this.delFromWaitingQueue(seq);
    ????????if(this.onCancelRespHandler!=null)
    ????????{
    ?????????CancelRespEventArgs e=new CancelRespEventArgs(cancel_reply);
    ?????????onCancelRespHandler(this,e);
    ????????}
    ????????else
    ????????{
    ?????????defaultCancelRespEventHandler();
    ????????}
    ????????break;
    ?
    ???????case (uint)MSG.CMPP_COMMAND_ID.CMPP_CONNECT_RESP :?? //檢查下消息的正確性,清除等待隊(duì)列 設(shè)定連接成功標(biāo)志
    ????????this.ErrorInfo =this.ErrorInfo +" "+("收到:CMPP_CONNECT_RESP ");
    ????????MSG.CMPP_MSG_CONNECT_RESP cn_reply=new MSG.CMPP_MSG_CONNECT_RESP(the_pk);
    ????????seq=cn_reply.Sequence;???? //取得消息的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);??? //刪除隊(duì)列中的等待連接信息包
    ????????break;
    ?
    ???????case (uint)MSG.CMPP_COMMAND_ID.CMPP_DELIVER:??? //檢查消息正確定,立即返回 正確 或者 失敗,正確則處理是否狀態(tài)包,不是狀態(tài)包則存到MO緩存,表示收到信息,時(shí)狀態(tài)包則判斷緩存消息進(jìn)行消息送達(dá)處理
    ????????this.ErrorInfo =this.ErrorInfo +" "+("收到:CMPP_DELIVER ");
    ????????BIConvert.DumpBytes(the_pk,"c:\CMPP_DELIVER.txt");//保留映像
    ????????MSG.CMPP_MSG_DELIVER deliver=new MSG.CMPP_MSG_DELIVER(the_pk);???????
    ????????seq=(uint)deliver.ISMGSequence;?????? //發(fā)過(guò)來(lái)的流水號(hào),需要立即發(fā)送一個(gè)deliver_resp?????? //一條 ISMG--〉SP 的消息
    ????????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 +" "+("發(fā)送:CMPP__DELIVER_RESP ");
    ????????if(deliver.isReport)
    ????????{????? //刪除等待隊(duì)列的消息//報(bào)告消息已經(jīng)正確發(fā)送到????????
    ?????????//UInt64 ReportMsgID=deliver.ReportMsgID ; //取得消息ID ,更新 MsgID
    ?????????string StateReport=deliver.StateReport; //取得關(guān)于此消息的狀態(tài)
    ?????????//_debugBs(the_pk);
    ?????????ReportEventArgs arg=new ReportEventArgs(the_pk,MSG.CMPP_MSG_Header.HeaderLength+8+21+10+1+1+1+21+1+1);??? //構(gòu)造報(bào)告事件參數(shù)
    ?????????//ReportEventArgs arg=new ReportEventArgs(ReportMsgID.ToString(),
    ?????????if(this.onReportHandler!=null) //ReportEventArgs傳遞的字節(jié)數(shù)組是 報(bào)告信息包的數(shù)據(jù),在此不考慮多個(gè)報(bào)告的情況
    ?????????{
    ??????????onReportHandler(this,arg);
    ?????????}
    ?????????else
    ?????????{
    ??????????this.defaultReportHandler();?
    ?????????}
    ????????}
    ????????else
    ????????{//SMSEventArgs 傳遞的整個(gè)deliver包
    ?????????SMSEventArgs smsarg=new SMSEventArgs (the_pk,MSG.CMPP_MSG_Header.HeaderLength);?
    ?????????if(this.onSMSHandler!=null)
    ?????????{
    ??????????onSMSHandler(this,smsarg);?? //觸發(fā)事件,應(yīng)當(dāng)很快結(jié)束處理,不要靠考慮存儲(chǔ)之類的耗費(fèi)資源事宜
    ?????????}
    ?????????else
    ?????????{
    ??????????defaultSMSHandler();
    ?????????}
    ????????}???
    ????????break;
    ?
    ???????case (uint)MSG.CMPP_COMMAND_ID.CMPP_QUERY_RESP :
    ????????this.ErrorInfo =this.ErrorInfo +" "+("收到:CMPP_QUERY_RESP ");
    ????????//收到消息,處理后存入數(shù)據(jù)庫(kù)
    ????????MSG.CMPP_MSG_QUERY_RESP query_resp=new MSG.CMPP_MSG_QUERY_RESP(the_pk);
    ????????this.delFromWaitingQueue(query_resp.Sequence );?? //將等待的隊(duì)列中的元素刪除
    ????????if(this.onQueryRespHandler!=null)
    ????????{
    ?????????QueryRespEventArgs e=new QueryRespEventArgs(query_resp);
    ????????}
    ????????else
    ????????{
    ?????????defaultQueryRespEventHandler();
    ????????}
    ????????break;
    ?
    ???????case (uint)MSG.CMPP_COMMAND_ID.CMPP_SUBMIT_RESP :??? //收到服務(wù)器送達(dá)的慧英消息
    ????????this.ErrorInfo =this.ErrorInfo +" "+("收到: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");//保留映像
    ????????//BIConvert.DumpBytes(initValue,"c:\CMPP_SUBMIT_RESP.txt");//保留映像
    ????????sub_resp++; //該變量?jī)H供測(cè)試使用
    ????????delFromWaitingQueue(submit_resp.Sequence);? //刪除需要等待的消息
    ????????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 +" "+"收到: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 +" "+"收到:CMPP_TERMINATE_RESP";
    ????????tcp.Send(terminate_resp.toBytes());?
    ????????if(this.onTerminateHandler!=null)
    ????????{
    ?????????TerminateEventArgs e=new TerminateEventArgs(terminate);
    ?????????onTerminateHandler(this,e);
    ?????????this.StopMe() ;?//準(zhǔn)備自我停止?
    ????????}
    ????????else
    ????????{
    ?????????defaultTerminateEventHandler();
    ????????}
    ????????this._StopMe();? //發(fā)出終止設(shè)定????????
    ????????return;???//退出線程????????
    ?
    ???????case (uint)MSG.CMPP_COMMAND_ID.CMPP_TERMINATE_RESP :
    ????????this.ErrorInfo =this.ErrorInfo +" "+"收到:CMPP_TERMINATE_RESP";
    ????????MSG.CMPP_MSG_TERMINATE_RESP ter_resp=new MSG.CMPP_MSG_TERMINATE_RESP(the_pk);
    ????????seq=ter_resp.Sequence ;? //取得流水信號(hào)
    ????????this.delFromOutQueue(seq);?? //刪除輸出表重點(diǎn)項(xiàng)目
    ????????if(this.onTerminateRespHandler!=null)
    ????????{
    ?????????TerminateRespEventArgs e=new TerminateRespEventArgs(ter_resp);
    ?????????onTerminateRespHandler(this,e);
    ????????}
    ????????else
    ????????{
    ?????????defaultTerminateRespEventHandler();
    ????????}
    ????????this._StopMe();
    ????????break;
    ??????}????????????
    ?????}?????
    ?????LogLastOkTime(DateTime.Now );? //記錄當(dāng)前最后一次消息soket正確時(shí)間
    ????}
    ????catch(SocketException se)
    ????{
    ?????//超時(shí)???
    ????}
    ????Thread.Sleep(50);
    ???}??
    ??}
    ??//debug
    //??private void _debugBs(byte[] the_pk) //存儲(chǔ)byte字節(jié)
    //??{
    //???
    //??}
    ??//debug
    ?
    ??private void DeamonThread()??? //監(jiān)視本系統(tǒng)連接是否正常
    ??{//此線程是監(jiān)視線程
    ???int? t_count =0;?? //循環(huán)時(shí)間計(jì)數(shù)
    ???_reStartRecvNSend();?? //啟動(dòng)接收和發(fā)送
    ???while(! this.isStop)
    ???{? ????
    ????t_count++;??? //0.1秒???
    ????if(tcpIsCanUse())?
    ????{
    ?????if(this.isPingTime())
    ?????{
    ??????this.ping();? //發(fā)送一個(gè)ping包
    ?????}
    ?????if(t_count>50)? // 500*100=50000=50秒
    ?????{
    ??????t_count=0;
    ??????checkReSend() ; //檢查需要重新發(fā)送的消息
    ??????//觸發(fā)一個(gè)事件,讓系統(tǒng)自動(dòng)檢查消息隊(duì)列,存儲(chǔ)消息隊(duì)列中的消息狀態(tài)
    ?????}
    ????}
    ????else
    ????{
    ?????EventArgs e=new EventArgs();
    ?????if(this.onSocketClosedHandler!=null)
    ?????{
    ??????onSocketClosedHandler(this,e);
    ?????}
    ?????else
    ?????{?????
    ?????}
    ?????this.isStop =true;? //通知其他線程退出
    ????}
    ????Thread.Sleep(1000);
    ???}
    ??}??
    ?
    ??private void SendSPMsgThread()
    ??{
    ???while (!this.isStop )
    ???{
    ????Thread.Sleep(10);
    ????if(this.isLogin)
    ????{
    ?????ArrayList lists=this.getTop16Queue();? //取出16條最頂?shù)南????
    ?????if(lists!=null? && lists.Count >0)
    ?????{
    ??????int count=lists.Count;????????????
    ??????ArrayList pks=new ArrayList( count);?//定義容量
    ??????for (int i=0;i<lists.Count; i++)
    ??????{
    ???????QueueItem outitem=(QueueItem)lists[i]; //取出每一個(gè)消息對(duì)象
    ???????if(outitem!=null)
    ???????{
    ????????try
    ????????{
    ?????????sendQueueItem(outitem);??? //發(fā)送每一個(gè)消息
    ????????}
    ????????catch(SocketException se)
    ????????{
    ?????????//發(fā)送失敗
    ?????????outitem.FailedCount ++;
    ????????}
    ???????}??????
    ??????}
    ?????}
    ????}
    ????Thread.Sleep(100);
    ???}??
    ??}?

    ??private void _StopMe()
    ??{
    ???lock(this)
    ???{
    ????this.isStop =true;
    ???}
    ??}
    ?
    ??private void _forcedSubThread(Thread t)?? //強(qiáng)制停止線程
    ??{
    ???try
    ???{
    ????t.Abort();
    ????t.Join();?
    ???}
    ???catch(Exception )
    ???{}
    ??}
    ?
    ??//private 函數(shù)區(qū)域//////////////////////////////////////////////////////////////////
    ?
    ?
    ??//公用函數(shù) 屬性區(qū)域////////////////////////////////////////
    ??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,CMPPPort));
    ??}
    ??
    ??public bool Login(string SystemID,string UserName,string Password)
    ??{
    ???try
    ???{
    ????SendLogin(SystemID, UserName, Password);
    ????this.LogLastOkTime(DateTime.Now);??? //最后一次正確的發(fā)送
    ???}
    ???catch(SocketException se)
    ???{
    ????//發(fā)送出錯(cuò)
    ????this.ErrorInfo = this.ErrorInfo +" "+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 ;? //更新當(dāng)前最后成功收發(fā)套接字的時(shí)間
    ????}
    ????catch(SocketException)
    ????{
    ????}
    ????System.TimeSpan t=DateTime.Now - t1;
    ????if(t.TotalSeconds > 10)
    ????{
    ?????break;
    ????}
    ???}??
    ???if(this.isLogin)
    ???{ //登錄ok,就立即發(fā)送active_test包
    ????this.ErrorInfo =this.ErrorInfo + " "+" Logon succ! ";????
    ????startThreads();? // 啟動(dòng) 主監(jiān)視程序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();?? //取得下一個(gè)sequence
    ???sndmsg=new MSG.CMPP_MSG_SUBMIT(seq);
    ???sndmsg.FeeCode =fee_code;
    ???sndmsg.FeeTerminalId =to_user;
    ???sndmsg.FeeType=MSG.FeeType.FEE_TERMINAL_PERITEM; //按條收取
    ???sndmsg.FeeUserType = fee_usertype ;
    ???sndmsg.Msg_Level=0;
    ???sndmsg.MSGFormat = (uint)MSG.Msg_Format.UCS2;
    ???sndmsg.SMS_Content=content;
    ???sndmsg.SrcID=spnum;???????? //長(zhǎng)號(hào)碼
    ???sndmsg.SPID=this.systemID ;
    ???sndmsg.Svc_Code= svc_code;
    ???sndmsg.UDHI=0;
    ???sndmsg.ValIdTime=getValIdTime(DateTime.Now);??????? //存活時(shí)間
    ???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 ;??? //計(jì)費(fèi) 按照計(jì)費(fèi)號(hào)碼計(jì)費(fèi)
    ???sndmsg.SPID =this.systemID ;???????? //企業(yè)代碼
    ???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)? //向計(jì)費(fèi)用戶發(fā)送一條包月計(jì)費(fèi)信息
    ??{
    ???uint seq=this.getNextSequence();
    ???MSG.CMPP_MSG_

    posted on 2006-10-19 11:07 注銷..... 閱讀(206) 評(píng)論(0)  編輯  收藏

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 国产亚洲福利在线视频| 国产精品免费观看久久| 亚洲一区无码精品色| 另类小说亚洲色图| 国产伦一区二区三区免费| 亚洲高清国产拍精品熟女| 国产免费小视频在线观看| 色噜噜的亚洲男人的天堂| 啊v在线免费观看| 国产VA免费精品高清在线| 久久亚洲中文字幕精品一区| 国产精品免费无遮挡无码永久视频 | 亚洲国产精品无码久久青草 | 久久免费动漫品精老司机| 图图资源网亚洲综合网站| 99在线观看精品免费99| 亚洲国产av高清无码| 无码毛片一区二区三区视频免费播放 | 日韩电影免费在线观看| 亚洲成aⅴ人在线观看| 国产精品久久久久久久久久免费| 亚洲乱理伦片在线观看中字| 免费A级毛片无码A∨男男| 成全视频免费观看在线看| 亚洲最大黄色网址| 日韩免费一区二区三区| a级毛片免费观看在线| 久久亚洲精品无码AV红樱桃| 成年女人毛片免费观看97| 成在线人直播免费视频| 亚洲高清在线观看| 日韩高清免费在线观看| 中国一级毛片免费看视频| 亚洲一区免费在线观看| 亚洲国产成人久久综合一区77 | 欧美三级在线电影免费| 一区在线免费观看| 日韩亚洲精品福利| 99re这里有免费视频精品| 国产精品亚洲一区二区三区| 亚洲AV人人澡人人爽人人夜夜|