Beispiel #1
0
        private bool WaitForResponse(int seq, out PDU pdu, int timeOut = 0)
        {
            var result = false;

            pdu = null;
            while (true)
            {
                //TODO: here check if connection is disconnected
                if (!this.IsConnected)
                {
                    break;
                }

                System.Threading.Thread.Sleep(20);
                var p = outputQueue.AsEnumerable().Where(x => x.sequence_number == seq).FirstOrDefault();
                if (p == null)
                {
                    continue;
                }
                outputQueue.Remove(p);
                pdu    = p;
                result = p.command_status.Equals(CommandStatus.ESME_ROK);
                break;
            }
            return(result);
        }
Beispiel #2
0
        public bool UnBind()
        {
            if (!this._SystemSocket.IsConnected)
            {
                return(true);
            }

            //here get bind PUD
            var seq       = seqProvider.GetNumber();
            var sendBytes = GetUnbindPDU(seq);
            var i         = _SystemSocket.Write(sendBytes.ToArray());

            if (i == -1)
            {
                IsServiceConnected = false;
                return(true);
            }


            PDU p      = null;
            var result = WaitForResponse(seq, out p);

            if (result)
            {
                IsServiceConnected = false;
                _SystemSocket.Disconnect();
            }

            return(result);
        }
Beispiel #3
0
        //data msg
        public bool DataSm(string sourceAddr, string distinationAddr, string msg)
        {
            //here form PDU
            var seq = seqProvider.GetNumber();

            var sendBytes = new List <byte>();

            sendBytes.AddRange(Utility.ConvertIntToBytes((int)CommanadType.data_sm));
            sendBytes.AddRange(Utility.ConvertIntToBytes(0));
            sendBytes.AddRange(Utility.ConvertIntToBytes(seq));

            //
            sendBytes.Add(service_type);
            sendBytes.Add(source_ton);
            sendBytes.Add(source_npi);

            sendBytes.AddRange(Utility.ConvertStringToBytes(string.IsNullOrEmpty(sourceAddr) ? source_addr : sourceAddr));
            sendBytes.Add(Utility.NullByte);

            sendBytes.Add(destination_ton);
            sendBytes.Add(destination_npi);
            sendBytes.AddRange(Utility.ConvertStringToBytes(distinationAddr));
            sendBytes.Add(Utility.NullByte);

            sendBytes.Add(esm_class);
            sendBytes.Add(receipt);
            sendBytes.Add(data_coding);



            //here add msg
            var msgBytes = Utility.ConvertStringToBytes(msg);

            //add tlv
            sendBytes.AddRange(Utility.ConvertIntToBytes((ushort)TLVTag.message_payload));
            sendBytes.AddRange(Utility.ConvertIntToBytes((ushort)msgBytes.Length));
            sendBytes.AddRange(msgBytes);


            sendBytes.InsertRange(0, Utility.ConvertIntToBytes(sendBytes.Count + 4));
            _SystemSocket.Write(sendBytes.ToArray());

            PDU p = null;
            var r = WaitForResponse(seq, out p);

            if (p == null)
            {
                Console.WriteLine(((SubmitSMRespPDU)p).message_id);
            }
            return(r);
        }
Beispiel #4
0
        public bool Bind()
        {
            _SystemSocket = new SystemSocket(this.Host, this.Port);
            _SystemSocket.packetRecieved += new SystemSocket.PacketRecieved(OnPacketRecived);
            var connected = _SystemSocket.Connect();

            if (!connected)
            {
                //safe side
                _SystemSocket.Disconnect();
                throw new Exception("Failed to connect");
            }

            // here actually service is not connected , but we are setting this to true
            // because our wait for Response method uses this :)
            IsServiceConnected = true;

            this.seqProvider.Reset();

            var seq       = this.seqProvider.GetNumber();
            var sendBytes = GetBindRequestPDU(seq);

            _SystemSocket.Write(sendBytes.ToArray());

            //here wait for response
            PDU p      = null;
            var result = WaitForResponse(seq, out p);

            if (p != null && result)
            {
                //here we need to add one more thread to Ensure Link
                var ensureLink = new EnsureLink(CheckLink);
                ensureLink.BeginInvoke(this, CheckLinkResult, this);
            }
            else
            {
                IsServiceConnected = false;
            }

            return(result);
        }
Beispiel #5
0
        ///Submit SM Multi
        private SubmitSMRespPDU DataSm_MultiPart(string sourceAddr, string distinationAddr, string msg, int totalParts, int partIndex)
        {
            //here form PDU
            var seq = seqProvider.GetNumber();

            var refNum = refProvider.GetNumber();

            var sendBytes = new List <byte>();

            sendBytes.AddRange(Utility.ConvertIntToBytes((int)CommanadType.data_sm));
            sendBytes.AddRange(Utility.ConvertIntToBytes(0));
            sendBytes.AddRange(Utility.ConvertIntToBytes(seq));

            //
            sendBytes.Add(service_type);
            sendBytes.Add(source_ton);
            sendBytes.Add(source_npi);

            sendBytes.AddRange(Utility.ConvertStringToBytes(string.IsNullOrEmpty(sourceAddr) ? source_addr : sourceAddr));
            sendBytes.Add(Utility.NullByte);

            sendBytes.Add(destination_ton);
            sendBytes.Add(destination_npi);
            sendBytes.AddRange(Utility.ConvertStringToBytes(distinationAddr));
            sendBytes.Add(Utility.NullByte);

            sendBytes.Add(esm_class);

            sendBytes.Add(receipt);

            sendBytes.Add(data_coding);


            //here add msg
            var msgBytes = Utility.ConvertStringToBytes(msg);


            //add tlv
            sendBytes.AddRange(Utility.ConvertIntToBytes((ushort)TLVTag.message_payload));
            sendBytes.AddRange(Utility.ConvertIntToBytes((ushort)msgBytes.Length));
            sendBytes.AddRange(msgBytes);


            sendBytes.AddRange(Utility.ConvertIntToBytes((ushort)TLVTag.sar_msg_ref_num));
            sendBytes.AddRange(Utility.ConvertIntToBytes((ushort)2));
            sendBytes.AddRange(Utility.ConvertIntToBytes((ushort)refNum));

            sendBytes.AddRange(Utility.ConvertIntToBytes((ushort)TLVTag.sar_total_segments));
            sendBytes.AddRange(Utility.ConvertIntToBytes((ushort)1));
            sendBytes.Add((byte)totalParts);

            sendBytes.AddRange(Utility.ConvertIntToBytes((ushort)TLVTag.sar_segment_seqnum));
            sendBytes.AddRange(Utility.ConvertIntToBytes((ushort)1));
            sendBytes.Add((byte)partIndex);



            sendBytes.InsertRange(0, Utility.ConvertIntToBytes(sendBytes.Count + 4));
            _SystemSocket.Write(sendBytes.ToArray());

            PDU p = null;
            var r = WaitForResponse(seq, out p);

            //Console.WriteLine(().message_id);
            return(p != null ? (SubmitSMRespPDU)p : null);
        }
Beispiel #6
0
        ///single msg
        public bool SubmitSm(string sourceAddr, string distinationAddr, string msg)
        {
            //here form PDU
            var seq = seqProvider.GetNumber();

            var sendBytes = new List <byte>();

            sendBytes.AddRange(Utility.ConvertIntToBytes((int)CommanadType.submit_sm));
            sendBytes.AddRange(Utility.ConvertIntToBytes(0));
            sendBytes.AddRange(Utility.ConvertIntToBytes(seq));

            //
            sendBytes.Add(service_type);
            sendBytes.Add(source_ton);
            sendBytes.Add(source_npi);

            sendBytes.AddRange(Utility.ConvertStringToBytes(string.IsNullOrEmpty(sourceAddr) ? source_addr : sourceAddr));
            sendBytes.Add(Utility.NullByte);

            sendBytes.Add(destination_ton);
            sendBytes.Add(destination_npi);
            sendBytes.AddRange(Utility.ConvertStringToBytes(distinationAddr));
            sendBytes.Add(Utility.NullByte);

            sendBytes.Add(esm_class);
            sendBytes.Add(protocol_id);
            sendBytes.Add(priority_flag);

            sendBytes.Add(schedule_delivery_time_r);
            sendBytes.Add(validity_period_r);
            sendBytes.Add(receipt);
            sendBytes.Add(replace_if_present_flag);
            sendBytes.Add(data_coding);
            sendBytes.Add(sm_default_msg_id);


            //here add msg
            var msgBytes = Utility.ConvertStringToBytes(msg);

            //sendBytes.Add((byte)msgBytes.Length);
            //sendBytes.AddRange(msgBytes);

            //msg length
            sendBytes.Add((byte)0);

            //add tlv
            sendBytes.AddRange(Utility.ConvertIntToBytes((ushort)TLVTag.message_payload));
            sendBytes.AddRange(Utility.ConvertIntToBytes((ushort)msgBytes.Length));
            sendBytes.AddRange(msgBytes);


            sendBytes.InsertRange(0, Utility.ConvertIntToBytes(sendBytes.Count + 4));
            _SystemSocket.Write(sendBytes.ToArray());

            PDU p = null;
            var r = WaitForResponse(seq, out p);

            Console.WriteLine(((SubmitSMRespPDU)p).message_id);

            return(r);
        }