/// <summary> /// Sends message to a remote SMMP server /// </summary> /// <param name="message">A message to send</param> /// <param name="timeOut">A value in miliseconds after which the send operation times out</param> public void SendMessage(ShortMessage message, int timeOut) { if (message == null) { throw new ArgumentNullException("message"); } //Check if connection is open if (vState != SmppConnectionState.Connected) { throw new SmppClientException("Sending message operation failed because the SmppClient is not connected"); } string messageId = null; foreach (SendSmPDU pdu in message.GetMessagePDUs(vProperties.DefaultEncoding, vSmppEncodingService)) { if (_Log.IsDebugEnabled) { _Log.DebugFormat("SendMessage SendSmPDU: {0}", LoggingExtensions.DumpStrig(pdu, vSmppEncodingService)); } ResponsePDU resp = vTrans.SendPdu(pdu, timeOut); if (resp.Header.ErrorCode != SmppErrorCode.ESME_ROK) { throw new SmppException(resp.Header.ErrorCode); } var submitSmResp = resp as SubmitSmResp; if (submitSmResp != null) { if (_Log.IsDebugEnabled) { _Log.DebugFormat("SendMessage Response: {0}", LoggingExtensions.DumpStrig(resp, vSmppEncodingService)); } messageId = ((SubmitSmResp)resp).MessageID; } message.ReceiptedMessageId = messageId; RaiseMessageSentEvent(message); } }
/// <summary> /// Sends message to a remote SMMP server /// </summary> /// <param name="message">A message to send</param> /// <param name="timeOut">A value in miliseconds after which the send operation times out</param> public void SendMessage(ShortMessage message, int timeOut) { if (message == null) { throw new ArgumentNullException("message"); } //Check if connection is open if (vState != SmppConnectionState.Connected) { throw new SmppClientException("Sending message operation failed because the SmppClient is not connected"); } foreach (SendSmPDU pdu in message.GetMessagePDUs(vProperties.DefaultEncoding)) { ResponsePDU resp = vTrans.SendPdu(pdu, timeOut); if (resp.Header.ErrorCode != SmppErrorCode.ESME_ROK) { throw new SmppException(resp.Header.ErrorCode); } RaiseMessageSentEvent(message); } }
private void PduReceivedEventHander(object sender, PduReceivedEventArgs e) { //This handler is interested in SingleDestinationPDU only SingleDestinationPDU pdu = e.Request as SingleDestinationPDU; if (pdu == null) { return; } ShortMessage message = null; try { message = MessageFactory.CreateMessage(pdu); } catch (SmppException smppEx) { if (vTraceSwitch.TraceError) { Trace.WriteLine(string.Format( "200019:SMPP message decoding failure - {0} - {1} {2};", smppEx.ErrorCode, new ByteBuffer(pdu.GetBytes()).DumpString(), smppEx.Message)); } //Notify the SMSC that we encountered an error while processing the message e.Response = pdu.CreateDefaultResponce(); e.Response.Header.ErrorCode = smppEx.ErrorCode; return; } catch (Exception ex) { if (vTraceSwitch.TraceError) { Trace.WriteLine(string.Format( "200019:SMPP message decoding failure - {0} {1};", new ByteBuffer(pdu.GetBytes()).DumpString(), ex.Message)); } //Let the receiver know that this message was rejected e.Response = pdu.CreateDefaultResponce(); e.Response.Header.ErrorCode = SmppErrorCode.ESME_RX_P_APPN; //ESME Receiver Reject Message return; } //If we have just a normal message if ((((byte)pdu.EsmClass) | 0xc3) == 0xc3) { RaiseMessageReceivedEvent(message); } //Or if we have received a delivery receipt else if ((pdu.EsmClass & EsmClass.DeliveryReceipt) == EsmClass.DeliveryReceipt) { // Extract receipted message id var receiptedMessageIdTlv = pdu.Tlv.GetTlvByTag(Tag.receipted_message_id); string receiptedMessageId = null; if (receiptedMessageIdTlv != null) { receiptedMessageId = SMPPEncodingUtil.GetCStringFromBytes(receiptedMessageIdTlv.RawValue); } message.ReceiptedMessageId = receiptedMessageId; // Extract user message reference var userMessageReferenceTlv = pdu.Tlv.GetTlvByTag(Tag.user_message_reference); string userMessageReference = null; if (userMessageReferenceTlv != null) { userMessageReference = SMPPEncodingUtil.GetCStringFromBytes(userMessageReferenceTlv.RawValue); } message.UserMessageReference = userMessageReference; RaiseMessageDeliveredEvent(message); } }
/// <summary> /// Sends message asynchronously to a remote SMPP server /// </summary> /// <param name="message">A message to send</param> /// <param name="timeout">A value in miliseconds after which the send operation times out</param> /// <param name="callback">An <see cref="AsyncCallback"/> delegate</param> /// <param name="state">An object that contains state information for this request</param> /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous send message operation</returns> public IAsyncResult BeginSendMessage(ShortMessage message, int timeout, AsyncCallback callback, object state) { return(vSendMessageCallBack.BeginInvoke(message, timeout, callback, state)); }
/// <summary> /// Sends message to a remote SMPP server /// </summary> /// <param name="message">A message to send</param> public void SendMessage(ShortMessage message) { SendMessage(message, vTrans.DefaultResponseTimeout); }
private void PduReceivedEventHander(object sender, PduReceivedEventArgs e) { //This handler is interested in SingleDestinationPDU only SingleDestinationPDU pdu = e.Request as SingleDestinationPDU; if (pdu == null) { return; } if (_Log.IsDebugEnabled) { _Log.DebugFormat("Received PDU: {0}", LoggingExtensions.DumpStrig(pdu, vSmppEncodingService)); } if (vTraceSwitch.TraceVerbose) { Trace.WriteLine(string.Format("PduReceived: RequestType: {0}", e.Request?.GetType()?.Name)); } ShortMessage message = null; try { message = MessageFactory.CreateMessage(pdu); } catch (SmppException smppEx) { _Log.ErrorFormat("200019:SMPP message decoding failure - {0} - {1} {2}", smppEx, smppEx.ErrorCode, new ByteBuffer(pdu.GetBytes()).DumpString(), smppEx.Message); if (vTraceSwitch.TraceError) { Trace.WriteLine(string.Format( "200019:SMPP message decoding failure - {0} - {1} {2};", smppEx.ErrorCode, new ByteBuffer(pdu.GetBytes()).DumpString(), smppEx.Message)); } //Notify the SMSC that we encountered an error while processing the message e.Response = pdu.CreateDefaultResponce(); e.Response.Header.ErrorCode = smppEx.ErrorCode; return; } catch (Exception ex) { _Log.ErrorFormat("200019:SMPP message decoding failure - {0}", ex, new ByteBuffer(pdu.GetBytes()).DumpString()); if (vTraceSwitch.TraceError) { Trace.WriteLine(string.Format( "200019:SMPP message decoding failure - {0} {1};", new ByteBuffer(pdu.GetBytes()).DumpString(), ex.Message)); } //Let the receiver know that this message was rejected e.Response = pdu.CreateDefaultResponce(); e.Response.Header.ErrorCode = SmppErrorCode.ESME_RX_P_APPN; //ESME Receiver Reject Message return; } if (message != null && _Log.IsDebugEnabled) { _Log.DebugFormat("PduReceived: message: {0}", LoggingExtensions.DumpStrig(message, vSmppEncodingService)); } if (vTraceSwitch.TraceVerbose) { #if DEBUG Console.WriteLine(string.Format("PduReceived: pdu: Header:{0}, EsmClass:{1}, ServiceType:{2}, DataCoding:{3}", pdu.Header, pdu.EsmClass, pdu.ServiceType, pdu.DataCoding)); #endif Trace.WriteLine(string.Format("PduReceived: pdu: Header:{0}, EsmClass:{1}, ServiceType:{2}, DataCoding:{3}", pdu.Header, pdu.EsmClass, pdu.ServiceType, pdu.DataCoding)); if (message != null) { Trace.WriteLine(string.Format("PduReceived: message: DestinationAddress:{0}, MessageCount:{1}, ReceiptedMessageId:{2}, RegisterDeliveryNotification:{3}, SegmentID:{4}, SequenceNumber:{5}, SourceAddress:{6}, UserMessageReference:{7}", message.DestinationAddress, message.MessageCount, message.ReceiptedMessageId, message.RegisterDeliveryNotification, message.SegmentID, message.SequenceNumber, message.SourceAddress, message.UserMessageReference)); } } //If we have just a normal message if ((((byte)pdu.EsmClass) | 0xc3) == 0xc3) { RaiseMessageReceivedEvent(message); } //Or if we have received a delivery receipt else if ((pdu.EsmClass & EsmClass.DeliveryReceipt) == EsmClass.DeliveryReceipt) { // Extract receipted message id message.ReceiptedMessageId = pdu.GetOptionalParamString(Tag.receipted_message_id); // Extract user message reference message.UserMessageReference = pdu.GetOptionalParamString(Tag.user_message_reference); RaiseMessageDeliveredEvent(message); } }
/// <summary> /// Creates a new instance of <see cref="MessageEventArgs"/> /// </summary> /// <param name="message">The message associated with the message event</param> public MessageEventArgs(ShortMessage message) { vShortMessage = message; }