Esempio n. 1
0
        private static void SendMessage(string command)
        {
            var parts       = command.Split(' ');
            var phoneNumber = parts[1];
            var message     = string.Join(" ",
                                          parts,
                                          2,
                                          parts.Length - 2);

            // This is set in the Submit PDU to the SMSC
            // If you are responding to a received message, make this the same as the received message
            var submitDataCoding = DataCodings.Default;

            // Use this to encode the message
            // We need to know the actual encoding.
            var encodeDataCoding = DataCodings.ASCII;

            // There is a default encoding set for each connection. This is used if the encodeDataCoding is Default

            SubmitSm     submitSm     = null;
            SubmitSmResp submitSmResp = null;

            connectionManager.SendMessage(phoneNumber,
                                          null,
                                          Ton.National,
                                          Npi.ISDN,
                                          submitDataCoding,
                                          encodeDataCoding,
                                          message,
                                          out submitSm,
                                          out submitSmResp);
        }
Esempio n. 2
0
 public IAnResponseBulder SubmitSmResp(SubmitSmResp submitSmResp)
 {
     try
     {
         response.statusCode = Converter.ToStatusCode(submitSmResp.Status);
         if (!response.IsSuccessful)
         {
             response.SubmitSmRespErrorData = JsonConvert.SerializeObject(submitSmResp);
         }
     }
     catch (Exception ex)
     {
     }
     return(this);
 }
        private async void WhenReceiveSubmitSmFromClient(object sender, SmppServerClient serverClient, SubmitSm receivedPdu)
        {
            _storage.SubmitReceived(receivedPdu);

            SubmitSm pduToSMSC = receivedPdu.Clone();

            //reset sequence number to allow proxyClient to assigne next sequence number from his generator
            pduToSMSC.Header.Sequence = 0;

            SubmitSmResp respFromSMSC = await _proxyClient.Submit(pduToSMSC);

            _storage.SubmitForwarded(receivedPdu, respFromSMSC);

            if (receivedPdu.SMSCReceipt == SMSCDeliveryReceipt.NotRequested)
            {
                _storage.DeliveryReceiptNotRequested(receivedPdu.Response.MessageId);
            }
        }
Esempio n. 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            SMPPEncodingUtil.UCS2Encoding = Encoding.BigEndianUnicode;

            mmSessionBindInfo                  = new SessionBindInfo();
            mmSessionBindInfo.SystemID         = "********";
            mmSessionBindInfo.Password         = "******";
            mmSessionBindInfo.ServerName       = "*******";
            mmSessionBindInfo.Port             = 1234;
            mmSessionBindInfo.InterfaceVersion = InterfaceVersion.v34;
            mmSessionBindInfo.SystemType       = "SMPP";
            mmSessionBindInfo.AllowTransmit    = true;
            mmSessionBindInfo.AllowReceive     = true;
            mmSessionBindInfo.AddressNpi       = NumberingPlanIndicator.Unknown;
            mmSessionBindInfo.AddressTon       = TypeOfNumber.Unknown;
            mmSession              = SmppClientSession.Bind(mmSessionBindInfo, 0);
            mmSession.PduReceived += new EventHandler <PduReceivedEventArgs>(PduReceivedEventHander);


            mmSubmitSm = new SubmitSm();

            mmSubmitSm.DataCoding                 = DataCoding.UCS2;
            mmSubmitSm.ServiceType                = "CMT";      // cellular  messaging
            mmSubmitSm.RegisteredDelivery         = RegisteredDelivery.DeliveryReceipt;
            mmSubmitSm.DestinationAddress.Address = "********"; // destination
            mmSubmitSm.DestinationAddress.Npi     = NumberingPlanIndicator.ISDN;
            mmSubmitSm.DestinationAddress.Ton     = TypeOfNumber.International;
            mmSubmitSm.SourceAddress.Npi          = NumberingPlanIndicator.Unknown;
            mmSubmitSm.SourceAddress.Ton          = TypeOfNumber.Aphanumeric;
            mmSubmitSm.SourceAddress.Address      = "*********";

            try
            {
                mmSubmitSm.SetMessageText(Encoding.UTF8.GetString(Encoding.UTF8.GetBytes("Текст")), DataCoding.UCS2);
                mmSubmitSmResp = mmSession.SendPdu(mmSubmitSm) as SubmitSmResp;
                MessageBox.Show(DateTime.Now.ToString());
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }

            MessageBox.Show(mmSubmitSmResp.MessageID + " , " + mmSubmitSmResp.Header.ErrorCode.ToString() + " , " + mmSubmitSm.GetMessageText());
        }
Esempio n. 5
0
        private static void SendMessage(string command)
        {
            string[] parts       = command.Split(' ');
            string   phoneNumber = parts[1];
            string   message     = string.Join(" ", parts, 2, parts.Length - 2);

            // This is set in the Submit PDU to the SMSC
            // If you are responding to a received message, make this the same as the received message
            DataCodings submitDataCoding = DataCodings.Default;

            // Use this to encode the message
            // We need to know the actual encoding.
            DataCodings encodeDataCoding = DataCodings.ASCII;

            // There is a default encoding set for each connection. This is used if the encodeDataCoding is Default

            SubmitSm     submitSm     = null;
            SubmitSmResp submitSmResp = null;

            connectionManager.SendMessage(phoneNumber, null, Ton.National, Npi.ISDN, submitDataCoding, encodeDataCoding, message, out submitSm, out submitSmResp);
            Console.Write("submitSm:{0}, submitSmResp:{1}, messageId:{2}", submitSm.DestAddr, submitSmResp.Status, submitSmResp.MessageId);
        }
Esempio n. 6
0
        public void Add(AnMessage message, SubmitSmResp smResp)
        {
            var builder = AnResponse.Bulder().Message(message);

            if (smResp != null)
            {
                builder.SubmitSmResp(smResp);
                var res = builder.ToAnResponse();
                if (res.IsSuccessful)
                {
                    SuccessResponses.Add(res);
                }
                else
                {
                    ErrorResponse = res;
                }
            }
            else
            {
                var res = builder.StatusCode(StatusCode.SmppClient_UnknownError).ToAnResponse();
                ErrorResponse = res;
            }
        }
Esempio n. 7
0
        private void Bw_DoWork(object sender, DoWorkEventArgs e)
        {
            SubmitSm            submitSm         = null;
            SubmitSmResp        submitSmResp     = null;
            List <SubmitSm>     submitSmList     = null;
            List <SubmitSmResp> submitSmRespList = null;
            var QMessages = new OutSMSRepo(db).GetPendingSMSQueue();

            //AddLog("dd", "worker work", "OUT", "4003", Color.Black);
            if (!object.ReferenceEquals(QMessages, null) && (QMessages.Count > 0))
            {
                while (QMessages.Count > 0)
                {
                    if (ContinueSending)
                    {
                        var OutMsg   = QMessages.Dequeue();
                        int retvalue = -1;
                        if (!string.IsNullOrEmpty(OutMsg.Receiver) && !string.IsNullOrEmpty(OutMsg.Message))
                        {
                            if (OutMsg.Message.Length <= 70)
                            {
                                retvalue = connectionManager.SendMessage(OutMsg.Receiver, null, Ton.Unknown, Npi.Unknown, DataCodings.UCS2
                                                                         , DataCodings.UCS2, OutMsg.Message, out submitSm, out submitSmResp);
                            }
                            else
                            {
                                retvalue = connectionManager.SendMessageLarge(OutMsg.Receiver, null, Ton.Unknown, Npi.Unknown, DataCodings.UCS2
                                                                              , DataCodings.UCS2, OutMsg.Message, out submitSmList, out submitSmRespList);
                            }
                            AddLog(OutMsg.Receiver, OutMsg.Message, "OUT", OutMsg.Sender, "Bw_DoWork", Color.Black);
                            new OutSMSRepo(db).RemoveMessage(OutMsg.Id);
                            //Thread.Sleep(100);
                        }
                    }
                }
            }
        }
        public void SubmitForwarded(SubmitSm req, SubmitSmResp remoteResp)
        {
            MessageEntry entry;

            if (!_localSequences.TryGetValue(req.Header.Sequence, out entry))
            {
                throw new Exception("Cannot find message with local sequence " + req.Header.Sequence);
            }

            entry.RemoteSequence  = remoteResp.Header.Sequence;
            entry.RemoteMessageId = remoteResp.MessageId;

            MessageEntry remoteEntry;

            if (_remoteMessage.TryRemove(remoteResp.MessageId, out remoteEntry))
            {
                entry.Receipt = remoteEntry.Receipt;
                OnReceiptReadyForForward(entry);
            }
            else
            {
                _remoteMessage.TryAdd(remoteResp.MessageId, entry);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Gets PDU from stream, parses
        /// </summary>
        /// <param name="pdu">PDU to handle</param>
        private void PduHandler(string pdu)
        {
            string response = string.Empty;

            Events.LogChannelEvent(channel_name, "Receiving [" + Common.command_id.Values[Common.command_id.IndexOfKey(uint.Parse(pdu.Substring(8, 8), System.Globalization.NumberStyles.HexNumber))] + "]", debug ? pdu : "");

            switch (Common.command_id.Values[Common.command_id.IndexOfKey(uint.Parse(pdu.Substring(8, 8), System.Globalization.NumberStyles.HexNumber))])
            {
            case "generic_nack":
                // they do not understand my command
                // may be a bug in my pdu
                break;

            case "bind_transceiver_resp":
                var bind_transceiver = new BindTransceiverResp(pdu);
                commands_queue.Remove(bind_transceiver.sequence_number);
                if (bind_transceiver.command_status != 0)
                {
                    Events.LogChannelEvent(channel_name, "Error: " + Common.command_status[bind_transceiver.command_status].description);
                    if (!is_server)
                    {
                        // try to reconnect
                        Thread.Sleep(reconnectDelay);
                        Task.Run(() => { Gate.Clients[channel_name].Connect(); });
                    }
                }
                break;

            case "bind_transmitter_resp":
                var bind_transmitter = new BindTransmitterResp(pdu);
                commands_queue.Remove(bind_transmitter.sequence_number);
                if (bind_transmitter.command_status != 0)
                {
                    Events.LogChannelEvent(channel_name, "Error: " + Common.command_id[bind_transmitter.command_status]);

                    if (!is_server)
                    {
                        Thread.Sleep(reconnectDelay);
                        Task.Run(() => { Gate.Clients[channel_name].Connect(); });
                    }
                }

                break;

            case "bind_receiver_resp":
                var bind_receiver = new BindReceiverResp(pdu);
                commands_queue.Remove(bind_receiver.sequence_number);
                if (bind_receiver.command_status != 0)
                {
                    Events.LogChannelEvent(channel_name, "Error: " + Common.command_id[bind_receiver.command_status]);
                    Quit();

                    if (!is_server)
                    {
                        Thread.Sleep(reconnectDelay);
                        Task.Run(() => { Gate.Clients[channel_name].Connect(); });
                    }
                }

                break;

            case "submit_sm":
                var submit_sm_s      = new SubmitSm(pdu);
                var submit_sm_resp_s = new SubmitSmResp();

                submit_sm_resp_s.MessageID       = Guid.NewGuid().ToString("n");
                submit_sm_resp_s.sequence_number = submit_sm_s.sequence_number;
                response = submit_sm_resp_s.Encode();

                Events.LogChannelEvent(channel_name, "Message received from " + submit_sm_s.Sender + " to " + submit_sm_s.Recipient);
                Events.LogChannelEvent(channel_name, "Sending [submit_sm_resp]");
                SendPDU(response);

                if (submit_sm_s.isMultipart)
                {
                    int parts = 0;
                    lock (multipart_messages)
                    {
                        multipart_messages.Add(submit_sm_s.MultipartMessage);

                        foreach (Common.MultipartMessage mm in multipart_messages)
                        {
                            if (mm.reference == submit_sm_s.MultipartMessage.reference)
                            {
                                parts++;
                            }
                        }
                    }
                    if (parts == submit_sm_s.MultipartMessage.num_of_parts)
                    {
                        var for_remove    = new List <Common.MultipartMessage>();
                        var short_message = new StringBuilder();
                        var str           = new string[parts];
                        lock (multipart_messages)
                        {
                            foreach (Common.MultipartMessage mm in multipart_messages)
                            {
                                if (mm.reference == submit_sm_s.MultipartMessage.reference)
                                {
                                    for_remove.Add(mm);
                                    try
                                    {
                                        str[mm.part_num - 1] = mm.short_message;
                                    }
                                    catch (Exception e1)
                                    {
                                        Events.LogEvent(LogEvent.Level.Error, channel_name + " - " + e1 + "  " + pdu);
                                    }
                                }
                            }

                            foreach (Common.MultipartMessage k in for_remove)
                            {
                                multipart_messages.Remove(k);
                            }
                        }
                        // can be required
                        // short_message.Append("(" + submit_sm_s.MultipartMessage.reference.ToString() + ") ");
                        try
                        {
                            for (int k = 0; k < parts; k++)
                            {
                                short_message.Append(str[k]);
                            }
                            submit_sm_s.Body = short_message.ToString();
                        }
                        catch (Exception e1)
                        {
                            Events.LogEvent(LogEvent.Level.Error, channel_name + " - " + e1 + "  " + pdu);
                        }

                        Events.LogNewMessageEvent(channel_name, submit_sm_resp_s.MessageID, submit_sm_s.Sender, submit_sm_s.Recipient, submit_sm_s.Body, submit_sm_s.BodyFormat, submit_sm_s.RegisteredDelivery);
                    }
                }
                else
                {
                    Events.LogNewMessageEvent(channel_name, submit_sm_resp_s.MessageID, submit_sm_s.Sender, submit_sm_s.Recipient, submit_sm_s.Body, submit_sm_s.BodyFormat, submit_sm_s.RegisteredDelivery);
                }
                break;

            case "submit_sm_resp":
                try
                {
                    var submit_sm_resp = new SubmitSmResp(pdu);
                    if (submitted_messages.ContainsKey(submit_sm_resp.sequence_number))
                    {
                        var submitSmRespMessageId = "";
                        if (!string.IsNullOrEmpty(submit_sm_resp.MessageID))
                        {
                            submitSmRespMessageId = submit_sm_resp.MessageID;
                        }

                        if (submit_sm_resp.command_status == 0)
                        {
                            Events.LogMessageChangeStatusEvent(
                                submitted_messages[submit_sm_resp.sequence_number].message_id, Common.MessageStatus.sent, submitSmRespMessageId);
                        }
                        else
                        {
                            if (Common.command_status.ContainsKey(submit_sm_resp.command_status))
                            {
                                Events.LogMessageChangeStatusEvent(
                                    submitted_messages[submit_sm_resp.sequence_number].message_id,
                                    Common.MessageStatus.rejected, submitSmRespMessageId);
                            }
                            else
                            {
                                Events.LogMessageChangeStatusEvent(
                                    submitted_messages[submit_sm_resp.sequence_number].message_id,
                                    Common.MessageStatus.sent);
                            }
                        }
                        submitted_messages.Remove(submit_sm_resp.sequence_number);
                    }

                    if (submit_sm_resp.command_status != 0)
                    {
                        Events.LogChannelEvent(channel_name, "Error sending: " + submit_sm_resp.command_status);
                    }
                    else
                    {
                        Events.LogChannelEvent(channel_name, "Message reference: " + submit_sm_resp.MessageID);
                    }
                }
                catch (Exception e1)
                {
                    Events.LogEvent(LogEvent.Level.Error, channel_name + " - " + e1.ToString());
                }
                break;

            case "enquire_link":
                var enquire_link      = new EnquireLink(pdu);
                var enquire_link_resp = new EnquireLinkResp();

                enquire_link_resp.sequence_number = enquire_link.sequence_number;
                response = enquire_link_resp.Encode();
                SendPDU(response);
                Events.LogChannelEvent(channel_name, "Sending [enquire_link_resp]", debug ? response : "");
                break;

            case "enquire_link_resp":
                var enquire_link_resp_o = new EnquireLinkResp(pdu);
                commands_queue.Remove(enquire_link_resp_o.sequence_number);
                break;

            case "deliver_sm":
                DeliverSm deliver_sm;
                try
                {
                    deliver_sm        = new DeliverSm(pdu);
                    deliver_sm.Is8bit = use8bit;
                    deliver_sm.Decode();
                }
                catch (CommandLengthException)
                {
                    Events.LogEvent(LogEvent.Level.Error, channel_name + ". Command length error.");
                    break;
                }
                catch (Exception e1)
                {
                    Events.LogEvent(LogEvent.Level.Error, channel_name + ". Error: " + e1.Message);
                    break;
                }

                // Send Resp
                var deliver_sm_resp = new DeliverSmResp();
                deliver_sm_resp.MessageID       = Guid.NewGuid().ToString("n");
                deliver_sm_resp.sequence_number = deliver_sm.sequence_number;
                response = deliver_sm_resp.Encode();

                Events.LogChannelEvent(channel_name, "Sending [deliver_sm_resp]", debug ? response : "");
                SendPDU(response);

                // Multipart message
                if (deliver_sm.isMultipart)
                {
                    int parts = 0;
                    lock (multipart_messages)
                    {
                        multipart_messages.Add(deliver_sm.MultipartMessage);


                        foreach (Common.MultipartMessage mm in multipart_messages)
                        {
                            if (mm.reference == deliver_sm.MultipartMessage.reference)
                            {
                                parts++;
                            }
                        }
                    }
                    if (parts == deliver_sm.MultipartMessage.num_of_parts)
                    {
                        List <Common.MultipartMessage> for_remove = new List <Common.MultipartMessage>();
                        StringBuilder short_message = new StringBuilder();
                        string[]      str           = new string[parts];

                        lock (multipart_messages)
                        {
                            foreach (Common.MultipartMessage mm in multipart_messages)
                            {
                                if (mm.reference == deliver_sm.MultipartMessage.reference)
                                {
                                    for_remove.Add(mm);
                                    try
                                    {
                                        str[mm.part_num - 1] = mm.short_message;
                                    }
                                    catch (Exception e1)
                                    {
                                        Events.LogEvent(LogEvent.Level.Error, channel_name + " - " + e1.ToString() + "  " + pdu);
                                    }
                                }
                            }

                            foreach (Common.MultipartMessage k in for_remove)
                            {
                                multipart_messages.Remove(k);
                            }
                        }

                        try
                        {
                            for (int k = 0; k < parts; k++)
                            {
                                short_message.Append(str[k]);
                            }
                            deliver_sm.Body = short_message.ToString();
                        }
                        catch (Exception e1)
                        {
                            Events.LogEvent(LogEvent.Level.Error, channel_name + " - " + e1.ToString() + "  " + pdu);
                        }
                    }
                    else
                    {
                        // Multipart message is not built yet, wait for the rest
                        break;
                    }
                }

                // Delivery report
                if (deliver_sm.ESMClass == 4)
                {
                    Events.LogChannelEvent(channel_name, "Message ref: " + deliver_sm.Reference + " " + deliver_sm.DeliveryStatus, debug ? pdu : "");
                    if (deliver_sm.DeliveryStatus.ToUpper() == "DELIVR")
                    {
                        Events.LogMessageDeliverReportEvent(deliver_sm.Reference, Common.MessageStatus.delivered_ACK_received);
                    }
                    if (deliver_sm.DeliveryStatus.ToUpper() == "EXPIRE")
                    {
                        Events.LogMessageDeliverReportEvent(deliver_sm.Reference, Common.MessageStatus.ACK_expired);
                    }
                    if (deliver_sm.DeliveryStatus.ToUpper() == "UNKNOW")
                    {
                        Events.LogMessageDeliverReportEvent(deliver_sm.Reference, Common.MessageStatus.unknown_recipient);
                    }
                    if (deliver_sm.DeliveryStatus.ToUpper() == "ACCEPT")
                    {
                        Events.LogMessageDeliverReportEvent(deliver_sm.Reference, Common.MessageStatus.received_routed);
                    }
                    if (deliver_sm.DeliveryStatus.ToUpper() == "REJECT")
                    {
                        Events.LogMessageDeliverReportEvent(deliver_sm.Reference, Common.MessageStatus.rejected);
                    }
                    if (deliver_sm.DeliveryStatus.ToUpper() == "UNDELI")
                    {
                        Events.LogMessageDeliverReportEvent(deliver_sm.Reference, Common.MessageStatus.message_undeliverable);
                    }

                    break;
                }

                // Log message
                Events.LogChannelEvent(channel_name, "Message received from " + deliver_sm.Sender + " to " + deliver_sm.Recipient, debug ? pdu : "");
                Events.LogNewMessageEvent(channel_name, deliver_sm_resp.MessageID, deliver_sm.Sender, deliver_sm.Recipient, deliver_sm.Body, deliver_sm.BodyFormat, deliver_sm.RegisteredDelivery);

                break;

            case "deliver_sm_resp":
                try
                {
                    var deliver_sm_resp2 = new DeliverSmResp(pdu);
                    if (submitted_messages.ContainsKey(deliver_sm_resp2.sequence_number))
                    {
                        var deliverSmRespMessageId = "";
                        if (!string.IsNullOrEmpty(deliver_sm_resp2.MessageID))
                        {
                            deliverSmRespMessageId = deliver_sm_resp2.MessageID;
                        }

                        if (deliver_sm_resp2.command_status == 0)
                        {
                            if (registered_delivery != 1 && submitted_messages[deliver_sm_resp2.sequence_number].registered_delivery)
                            {
                                Events.LogMessageChangeStatusEvent(submitted_messages[deliver_sm_resp2.sequence_number].message_id, Common.MessageStatus.sent, deliverSmRespMessageId);
                            }
                        }
                        else
                        {
                            if (Common.command_status.ContainsKey(deliver_sm_resp2.command_status))
                            {
                                Events.LogMessageChangeStatusEvent(
                                    submitted_messages[deliver_sm_resp2.sequence_number].message_id,
                                    Common.MessageStatus.rejected, deliverSmRespMessageId);
                            }
                            else
                            {
                                Events.LogMessageChangeStatusEvent(
                                    submitted_messages[deliver_sm_resp2.sequence_number].message_id,
                                    Common.MessageStatus.sent, deliverSmRespMessageId);
                            }
                        }
                        submitted_messages.Remove(deliver_sm_resp2.sequence_number);
                    }

                    if (deliver_sm_resp2.command_status != 0)
                    {
                        Events.LogChannelEvent(channel_name, "Error sending: " + deliver_sm_resp2.command_status);
                    }
                    else
                    {
                        Events.LogChannelEvent(channel_name, "Message reference: " + deliver_sm_resp2.MessageID);
                    }
                }
                catch (Exception e1)
                {
                    Events.LogEvent(LogEvent.Level.Error, channel_name + " - " + e1);
                }
                break;

            case "data_sm":
                var data_sm_s      = new DataSm(pdu);
                var data_sm_resp_s = new DataSmResp();

                data_sm_resp_s.MessageID       = Guid.NewGuid().ToString("n");
                data_sm_resp_s.sequence_number = data_sm_s.sequence_number;
                response = data_sm_resp_s.Encode();

                Events.LogChannelEvent(channel_name, "Message received from " + data_sm_s.Sender + " to " + data_sm_s.Recipient, debug ? pdu : "");
                Events.LogChannelEvent(channel_name, "Sending [data_sm_resp]");
                SendPDU(response);

                Events.LogNewMessageEvent(channel_name, data_sm_resp_s.MessageID, data_sm_s.Sender, data_sm_s.Recipient, data_sm_s.Body, data_sm_s.BodyFormat, data_sm_s.RegisteredDelivery);

                break;

            case "data_sm_resp":
                try
                {
                    var data_sm_resp = new DataSmResp(pdu);
                    if (submitted_messages.ContainsKey(data_sm_resp.sequence_number))
                    {
                        var dataSmRespMessageId = "";
                        if (!string.IsNullOrEmpty(data_sm_resp.MessageID))
                        {
                            dataSmRespMessageId = data_sm_resp.MessageID;
                        }

                        if (data_sm_resp.command_status == 0)
                        {
                            if (registered_delivery != 1 && submitted_messages[data_sm_resp.sequence_number].registered_delivery)
                            {
                                Events.LogMessageChangeStatusEvent(submitted_messages[data_sm_resp.sequence_number].message_id, Common.MessageStatus.sent, dataSmRespMessageId);
                            }
                        }
                        else
                        {
                            if (Common.command_status.ContainsKey(data_sm_resp.command_status))
                            {
                                Events.LogMessageChangeStatusEvent(submitted_messages[data_sm_resp.sequence_number].message_id, Common.MessageStatus.rejected, dataSmRespMessageId);
                            }
                            else
                            {
                                Events.LogMessageChangeStatusEvent(submitted_messages[data_sm_resp.sequence_number].message_id, Common.MessageStatus.sent, dataSmRespMessageId);
                            }
                        }
                        submitted_messages.Remove(data_sm_resp.sequence_number);
                    }

                    if (data_sm_resp.command_status != 0)
                    {
                        Events.LogChannelEvent(channel_name, "Error sending: " + data_sm_resp.command_status);
                    }
                    else
                    {
                        Events.LogChannelEvent(channel_name, "Message reference: " + data_sm_resp.MessageID);
                    }
                }
                catch (Exception e1)
                {
                    Events.LogEvent(LogEvent.Level.Error, channel_name + ". error: " + e1);
                }
                break;

            case "unbind":
                var unbind      = new Unbind(pdu);
                var unbind_resp = new UnbindResp();
                unbind_resp.sequence_number = unbind.sequence_number;
                response = unbind_resp.Encode();
                SendPDU(response);

                Events.LogChannelEvent(channel_name, "Sending [unbind_resp]", debug ? response : "");

                enquire_link_timer.Stop();
                timeout_timer.Stop();

                tcp_stream.Close();
                tcp_client.Close();

                Gate.Clients.Remove(channel_name);
                Gate.Servers.Remove(channel_name);

                Events.LogChannelEvent(channel_name, "Disconnected");

                // should reconnect if it was a client
                if (!is_server)
                {
                    Thread.Sleep(10000);
                    Task.Run(() => { Gate.Clients[channel_name].Connect(); });
                }
                break;

            case "unbind_resp":
                ;
                break;

            default:
                Events.LogChannelEvent(channel_name, "Receiving unknown command", pdu);
                break;
            }
        }