private PDU WaitPDU() { PDUHeader header = null; PDU pdu = null; byte[] bodyBytes = null; byte[] headerBytes = null; //-- try { headerBytes = ReadHeaderBytes(); } catch (TcpIpException tcpIp_ex_1) { if (vTraceSwitch.TraceInfo) { Trace.WriteLine(string.Format( "200010:TCP/IP Exception encountered while reading pdu header bytes:{0};", tcpIp_ex_1.Message)); } HandleException(tcpIp_ex_1); throw; } //-- header = PDUHeader.Parse(new ByteBuffer(headerBytes)); try { pdu = PDU.CreatePDU(header); } catch (InvalidPDUCommandException inv_ex) { ByteBuffer iBuffer = new ByteBuffer((int)header.CommandLength); iBuffer.Append(header.GetBytes()); if (header.CommandLength > 16) { try { iBuffer.Append(ReadBodyBytes((int)header.CommandLength - 16)); } catch (TcpIpException tcpIp_ex_3) { HandleException(tcpIp_ex_3); } } if (vTraceSwitch.TraceWarning) { Trace.WriteLine(string.Format( "200011:Invalid PDU command type:{0};", iBuffer.DumpString())); } RaisePduErrorEvent(inv_ex, iBuffer.ToBytes(), header, null); throw; } //-- try { bodyBytes = ReadBodyBytes((int)header.CommandLength - 16); } catch (TcpIpException tpcIp_ex_2) { if (vTraceSwitch.TraceInfo) { Trace.WriteLine(string.Format( "200012:TCP/IP Exception encountered while reading pdu body bytes:{0};", tpcIp_ex_2.Message)); } HandleException(tpcIp_ex_2); throw; } //-- try { pdu.SetBodyData(new ByteBuffer(bodyBytes)); } catch (PDUException pdu_ex) { ByteBuffer pBuffer = new ByteBuffer((int)header.CommandLength); pBuffer.Append(headerBytes); pBuffer.Append(bodyBytes); RaisePduErrorEvent(pdu_ex, pBuffer.ToBytes(), header, pdu); if (vTraceSwitch.TraceWarning) { Trace.WriteLine(string.Format( "200013:Malformed PDU body received:{0} {1};", pBuffer.DumpString(), pdu_ex.Message)); } throw; } return(pdu); }
static void Main(string[] args) { //Common.Logging.LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(); var encSrv = new SmppEncodingService(); var hexBytes = "000000dd0000000500000000019182410001013334363439323836383039000501657669636572746961000400000000000000008569643a323533303932393134353232363637333732207375623a30303120646c7672643a303031207375626d697420646174653a3133303932393136353220646f6e6520646174653a3133303932393136353220737461743a44454c49565244206572723a3030303020746578743a1b3c657669534d531b3e0a534d532064652050727565042300030300000427000102001e001332353330393239313435323236363733373200"; var packet = StringToByteArray(hexBytes); var bodyBytes = packet.Skip(16).ToArray(); var pdu = PDU.CreatePDU(PDUHeader.Parse(new ByteBuffer(packet), encSrv), encSrv); pdu.SetBodyData(new ByteBuffer(bodyBytes)); var receiptedMessageId = pdu.GetOptionalParamString(JamaaTech.Smpp.Net.Lib.Protocol.Tlv.Tag.receipted_message_id); //Assert.AreEqual("253092914522667372", pdu.ReceiptedMessageId); Trace.WriteLine("Start"); //Trace.Listeners.Add(new ConsoleTraceListener()); smppConfig = GetSmppConfiguration(); //SMPPEncodingUtil.UCS2Encoding = Encoding.UTF8; var client = CreateSmppClient(smppConfig); client.Start(); // must wait until connected before start sending while (client.ConnectionState != SmppConnectionState.Connected) { Thread.Sleep(100); } var input = ""; do { Console.Write("Enter Dest: "); input = Console.ReadLine(); if ("q".Equals(input, StringComparison.InvariantCultureIgnoreCase)) { break; } var dest = input; Console.Write("Enter Msg: "); var msgTxt = Console.ReadLine(); if (string.IsNullOrEmpty(msgTxt)) { msgTxt = @"السلام عليكم ورحمة الله وبركاته هذه رسالة عربية متعددة الاسطر"; } TextMessage msg = new TextMessage(); msg.DestinationAddress = dest; //Receipient number msg.SourceAddress = smppConfig.SourceAddress; //Originating number //msg.Text = "Hello, this is my test message!"; msg.Text = msgTxt; msg.RegisterDeliveryNotification = true; //I want delivery notification for this message msg.UserMessageReference = Guid.NewGuid().ToString(); Console.WriteLine($"msg.UserMessageReference: {msg.UserMessageReference}"); Trace.WriteLine($"msg.UserMessageReference: {msg.UserMessageReference}"); //client.SendMessage(msg); client.BeginSendMessage(msg, SendMessageCompleteCallback, client); Console.ReadLine(); } while (true); }
static void Main(string[] args) { Common.Logging.LogManager.Adapter = new Common.Logging.Simple.DebugLoggerFactoryAdapter(); var encSrv = new SmppEncodingService(); var hexBytes = "000000dd0000000500000000019182410001013334363439323836383039000501657669636572746961000400000000000000008569643a323533303932393134353232363637333732207375623a30303120646c7672643a303031207375626d697420646174653a3133303932393136353220646f6e6520646174653a3133303932393136353220737461743a44454c49565244206572723a3030303020746578743a1b3c657669534d531b3e0a534d532064652050727565042300030300000427000102001e001332353330393239313435323236363733373200"; var packet = StringToByteArray(hexBytes); var bodyBytes = packet.Skip(16).ToArray(); var pdu = PDU.CreatePDU(PDUHeader.Parse(new ByteBuffer(packet), encSrv), encSrv); pdu.SetBodyData(new ByteBuffer(bodyBytes)); var receiptedMessageId = pdu.GetOptionalParamString(JamaaTech.Smpp.Net.Lib.Protocol.Tlv.Tag.receipted_message_id); //Assert.AreEqual("253092914522667372", pdu.ReceiptedMessageId); _Log.Info("Start"); //Trace.Listeners.Add(new ConsoleTraceListener()); smppConfig = GetSmppConfiguration(); //SMPPEncodingUtil.UCS2Encoding = Encoding.UTF8; client = CreateSmppClient(smppConfig); client.Start(); // must wait until connected before start sending while (client.ConnectionState != SmppConnectionState.Connected) { Thread.Sleep(100); } // Accept command input bool bQuit = false; do { // Hit Enter in the terminal once the binds are up to see this prompt Console.WriteLine("Commands"); Console.WriteLine("send 123456 hello"); Console.WriteLine("quit"); Console.WriteLine(""); Console.Write("\n#>"); string command = Console.ReadLine(); if (command.Length == 0) { continue; } switch (command.Split(' ')[0].ToString()) { case "quit": case "exit": case "q": bQuit = true; break; default: ProcessCommand(command); break; } if (bQuit) { break; } } while (true); if (client != null) { client.Dispose(); } }