Ejemplo n.º 1
0
 private void ReceivingThread()
 {
     try
     {
         int b;
         do
         {
             b = tcpClient.GetStream().ReadByte();
             if (b >= 0)
             {
                 data.WriteByte((byte)b);
                 if (data.Length == 4)
                 {
                     var buf = data.GetBuffer();
                     length = (uint)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
                 }
                 if (data.Length == length)
                 {
                     OnSmppPduReceived(this, SmppPdu.CreateFromBytes(data.GetBuffer(), length));
                     data   = new MemoryStream();
                     length = 0;
                 }
             }
         } while (tcpClient != null && tcpClient.Connected && b >= 0);
     }
     catch { }
     finally
     {
         if (tcpClient != null)
         {
             tcpClient.Close();
             tcpClient = null;
         }
         receiveThread = null;
         OnDisconnected(this);
     }
 }
Ejemplo n.º 2
0
        void SmppConnection_OnSmppPduReceived(SmppClient sender, SmppPdu pdu)
        {
            switch (pdu.CommandId)
            {
            case SmppPdu.SmppCommandType.bind_transmitter:
                OnBindTransmitterReceived(this, (SmppPduBindTransmitter)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.bind_transmitter_resp:
                OnBindTransmitterRespReceived(this, (SmppPduBindTransmitterResp)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.bind_receiver:
                OnBindReceiverReceived(this, (SmppPduBindReceiver)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.bind_receiver_resp:
                OnBindReceiverRespReceived(this, (SmppPduBindReceiverResp)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.bind_transceiver:
                OnBindTransceiverReceived(this, (SmppPduBindTransceiver)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.bind_transceiver_resp:
                OnBindTransceiverRespReceived(this, (SmppPduBindTransceiverResp)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.unbind:
                OnUnbindReceived(this, (SmppPduUnbind)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.unbind_resp:
                OnUnbindRespReceived(this, (SmppPduUnbindResp)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.generic_nack:
                OnGenerickNackReceived(this, (SmppPduGenerickNack)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.submit_sm:
                OnSubmitSmReceived(this, (SmppPduSubmitSm)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.submit_sm_resp:
                OnSubmitSmRespReceived(this, (SmppPduSubmitSmResp)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.deliver_sm:
                OnDeliverSmReceived(this, (SmppPduDeliverSm)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.deliver_sm_resp:
                OnDeliverSmRespReceived(this, (SmppPduDeliverSmResp)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.data_sm:
                OnDataSmReceived(this, (SmppPduDataSm)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.data_sm_resp:
                OnDataSmRespReceived(this, (SmppPduDataSmResp)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.query_sm:
                OnQuerySmReceived(this, (SmppPduQuerySm)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.query_sm_resp:
                OnQuerySmRespReceived(this, (SmppPduQuerySmResp)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.cancel_sm:
                OnCancelSmReceived(this, (SmppPduCancelSm)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.cancel_sm_resp:
                OnCancelSmRespReceived(this, (SmppPduCancelSmResp)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.enquire_link:
                OnEnquireLinkReceived(this, (SmppPduEnquireLink)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.enquire_link_resp:
                OnEnquireLinkRespReceived(this, (SmppPduEnquireLinkResp)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;

            case SmppPdu.SmppCommandType.alert_notification:
                OnAlertNotificationReceived(this, (SmppPduAlertNotification)SmppPdu.CreateFromBytes(pdu.GetData()));
                break;
            }
        }