private void OnNewSession(object sender, SmppEventArgs ea) { SmppConnectEventArgs ce = (SmppConnectEventArgs)ea; // Get the session information. IPAddress ipAddr = ce.Address; AddLogText(StatusCode.Session, string.Format("Connection from {0} accepted.", ipAddr.ToString())); // Get the session and establish our event handlers. SmscSession sess = (SmscSession)ce.Session; sess.OnPreprocessPdu += OnPreprocessPdu; sess.OnPostprocessPdu += OnPostprocessPdu; sess.OnBind += OnBind; sess.OnSubmitSm += OnSubmitSm; sess.OnQuerySm += OnQuerySm; sess.OnCancelSm += OnCancelSm; sess.OnUnbind += OnUnbind; sess.OnError += OnError; sess.OnSessionDisconnect += OnDisconnect; // Add the session to our listview new SessionListViewItem(lvSessions, sess); EnableGenerateSmsButton(true); }
private void OnCancelSm(object sender, SmppEventArgs ea) { query_sm req = (query_sm)ea.PDU; query_sm_resp resp = (query_sm_resp)ea.ResponsePDU; foreach (SmsMessage msg in arrMessages) { if (msg.MessageId == req.MessageID) { if (msg.deliveryTime != DateTime.MinValue) { msg.deliveryResult = DeliveryStatus.DELETED; msg.lvi.UpdateState(); return; } else { resp.ErrorCode = StatusCodes.ESME_RCANCELFAIL; } } } // Could not find message resp.ErrorCode = StatusCodes.ESME_RINVMSGID; }
private void OnDisconnect(object sender, SmppEventArgs ea) { // Assure we are on the UI thread if (InvokeRequired) { BeginInvoke((OnDisconnectHandler)OnDisconnect, sender, ea); return; } AddLogText(StatusCode.Session, string.Format("Connection from {0} dropped.", ea.Session.IPAddress.ToString())); SessionListViewItem lvi = (SessionListViewItem)ea.Session.Tag; if (lvi != null) { lvi.Remove(); } // Turn off the generate if no sessions. if (server_.CurrentSessions.Count == 1) { btnGenerateSms.Enabled = false; } SmppDisconnectEventArgs dea = (SmppDisconnectEventArgs)ea; if (dea.Exception != null) { AddLogText(StatusCode.Error, dea.Exception.ToString()); } }
/// <summary> /// This method processes the bind_transceiver PDU and performs the bind to the session. /// </summary> /// <param name="pdu">Protocol Data Unit being processed</param> public override void Process(bind_transceiver pdu) { // Build our response PDU bind_transceiver_resp pduOut = new bind_transceiver_resp(pdu.SequenceNumber, session_.LocalSystemID); // Assign the peer id and version session_.PeerSystemID = pdu.SystemID; session_.SmppVersion = pdu.InterfaceVersion; // Fire the bind event to the session owner SmppEventArgs ea = new SmppEventArgs(session_, pdu, pduOut); if (session_.FireEvent(EventType.Bind, ea)) { // If the session owner indicated it's ok to bind, then perform the binding. if (pduOut.Status == StatusCodes.ESME_ROK) { session_.CurrentState = new SmscBoundTRXSessionState(session_); } else { session_.PeerSystemID = ""; session_.SmppVersion = 0; } session_.SendPdu(pduOut); } }
/// <summary> /// This processes the data_sm event. /// </summary> /// <param name="pdu">Protocol Data Unit</param> public override void Process(data_sm pdu) { SmppEventArgs ea = new SmppEventArgs(session_, pdu, new data_sm_resp(pdu.SequenceNumber)); if (!session_.FireEvent(EventType.DataSm, ea)) { ea.ResponsePDU.Status = StatusCodes.ESME_RDELIVERYFAILURE; } session_.SendPdu(ea.ResponsePDU); }
/// <summary> /// This processes the alert_notification PDU /// </summary> /// <param name="pdu">Protocol Data Unit being processed</param> public override void Process(alert_notification pdu) { SmppEventArgs ea = new SmppEventArgs(session_, pdu, null); if (!session_.FireEvent(EventType.AlertNotification, ea)) { ea.ResponsePDU.Status = StatusCodes.ESME_RSUBMITFAIL; } session_.SendPdu(ea.ResponsePDU); }
/// <summary> /// This processes the deliver_sm PDU /// </summary> /// <param name="pdu">Protocol Data Unit being processed</param> public override void Process(deliver_sm pdu) { SmppEventArgs ea = new SmppEventArgs(session_, pdu, new deliver_sm_resp(pdu.SequenceNumber)); if (!session_.FireEvent(EventType.DeliverSm, ea)) { ea.ResponsePDU.Status = StatusCodes.ESME_RSUBMITFAIL; } session_.SendPdu(ea.ResponsePDU); }
/// <summary> /// This processes the data_sm event. /// </summary> /// <param name="pdu">Protocol Data Unit</param> public override void Process(replace_sm pdu) { SmppEventArgs ea = new SmppEventArgs(session_, pdu, new replace_sm_resp(pdu.SequenceNumber)); if (!session_.FireEvent(EventType.ReplaceSm, ea)) { ea.ResponsePDU.Status = StatusCodes.ESME_RREPLACEFAIL; } session_.SendPdu(ea.ResponsePDU); }
/// <summary> /// This processes the cancel_sm event. /// </summary> /// <param name="pdu">Protocol Data Unit</param> public override void Process(cancel_sm pdu) { SmppEventArgs ea = new SmppEventArgs(session_, pdu, new cancel_sm_resp(pdu.SequenceNumber)); if (!session_.FireEvent(EventType.CancelSm, ea)) { ea.ResponsePDU.Status = StatusCodes.ESME_RCANCELFAIL; } session_.SendPdu(ea.ResponsePDU); }
/// <summary> /// This processes the submit_multi event. /// </summary> /// <param name="pdu">Protocol Data Unit</param> public override void Process(submit_multi pdu) { SmppEventArgs ea = new SmppEventArgs(session_, pdu, new submit_multi_resp(pdu.SequenceNumber)); if (!session_.FireEvent(EventType.SubmitSmMulti, ea)) { ea.ResponsePDU.Status = StatusCodes.ESME_RSUBMITFAIL; } session_.SendPdu(ea.ResponsePDU); }
/// <summary> /// This processes the list_dls event. /// </summary> /// <param name="pdu">Protocol Data Unit</param> public override void Process(list_dls pdu) { SmppEventArgs ea = new SmppEventArgs(session_, pdu, new list_dls_resp(pdu.SequenceNumber)); if (!session_.FireEvent(EventType.ListDls, ea)) { ea.ResponsePDU.Status = StatusCodes.ESME_RLISTDLSFAIL; } session_.SendPdu(ea.ResponsePDU); }
/// <summary> /// This processes the view_dl event. /// </summary> /// <param name="pdu">Protocol Data Unit</param> public override void Process(view_dl pdu) { SmppEventArgs ea = new SmppEventArgs(session_, pdu, new view_dl_resp(pdu.SequenceNumber)); if (!session_.FireEvent(EventType.ViewDl, ea)) { ea.ResponsePDU.Status = StatusCodes.ESME_RVIEWDLFAIL; } session_.SendPdu(ea.ResponsePDU); }
/// <summary> /// This processes the query_broadcast_sm event. /// </summary> /// <param name="pdu">Protocol Data Unit</param> public override void Process(query_broadcast_sm pdu) { SmppEventArgs ea = new SmppEventArgs(session_, pdu, new query_broadcast_sm_resp(pdu.SequenceNumber)); if (!session_.FireEvent(EventType.QueryBroadcastSm, ea)) { ea.ResponsePDU.Status = StatusCodes.ESME_RBCASTQUERYFAIL; } session_.SendPdu(ea.ResponsePDU); }
/// <summary> /// This processes the enquire_sub event. /// </summary> /// <param name="pdu">Protocol Data Unit</param> public override void Process(enquire_sub pdu) { SmppEventArgs ea = new SmppEventArgs(session_, pdu, new enquire_sub_resp(pdu.SequenceNumber)); if (!session_.FireEvent(EventType.EnquireSub, ea)) { ea.ResponsePDU.Status = StatusCodes.ESME_RENQCUSTFAIL; } session_.SendPdu(ea.ResponsePDU); }
/// <summary> /// This method fires an event to all listeners /// </summary> /// <param name="eventType">Event being fired</param> /// <param name="ea">Arguments for event</param> /// <returns></returns> internal override bool FireEvent(object eventType, SmppEventArgs ea) { bool rc = base.FireEvent(eventType, ea); if (eventType == EventType.SessionDisconnected) { server_.EndSession(this); } return(rc); }
private static void OnSessionConnected(object sender, SmppEventArgs args) { // Test bind status? // Send Bind PDU to SMSC asynchronously Console.WriteLine("Successfully connected to SMSC. Now binding..."); bind_transceiver bindPdu = new bind_transceiver("RON-HAY-LAP", "test", "", new interface_version(), // Default is version 3.4 new address_range()); _smppSession.BeginBindTransceiver(bindPdu, new AsyncCallback(BindTransceiverCallback)); }
private void OnSessionBound(object sender, SmppEventArgs args) { // Set the session to bound // If the enquireLinkSeconds_ is non-zero then create a timer to send enquire link PDU's SetSmscConnectionStatus(SmscConnectionStatus.Bound); if (enquireLinkSeconds_ != 0) { enquireLinkTimer = new System.Timers.Timer((double)enquireLinkSeconds_ * 1000); enquireLinkTimer.Elapsed += new ElapsedEventHandler(OnEnquireLinkElapsedTimer); enquireLinkTimer.Enabled = true; } }
private void OnQuerySm(object sender, SmppEventArgs ea) { query_sm req = (query_sm)ea.PDU; query_sm_resp resp = (query_sm_resp)ea.ResponsePDU; foreach (SmsMessage msg in arrMessages) { if (msg.MessageId == req.MessageID) { if (msg.deliveryTime != DateTime.MinValue) { resp.FinalDate = new SmppTime(msg.deliveryTime, true); } switch (msg.deliveryResult) { case DeliveryStatus.ACCEPTED: resp.MessageStatus = MessageStatus.ACCEPTED; break; case DeliveryStatus.DELETED: resp.MessageStatus = MessageStatus.DELETED; break; case DeliveryStatus.DELIVERED: resp.MessageStatus = MessageStatus.DELIVERED; break; case DeliveryStatus.EXPIRED: resp.MessageStatus = MessageStatus.EXPIRED; break; case DeliveryStatus.REJECTED: resp.MessageStatus = MessageStatus.REJECTED; break; case DeliveryStatus.UNDELIVERABLE: resp.MessageStatus = MessageStatus.UNDELIVERABLE; break; default: resp.MessageStatus = MessageStatus.ENROUTE; break; } return; } } // Could not find message resp.ErrorCode = StatusCodes.ESME_RINVMSGID; }
// Called when the connection to SMSC is established private void OnSessionConnected(object sender, SmppEventArgs args) { // Update the SMSC connection status and related controls SetSmscConnectionStatus(SmscConnectionStatus.Connected); // Send Bind PDU to SMSC asynchronously bind_transceiver bindPdu = new bind_transceiver(smscSystemId_, smscPassword_, "", new interface_version(), // Default is version 3.4 new address_range()); bindPdu.SystemType = smscSystemType_; smppSession_.BeginBindTransceiver(bindPdu, new AsyncCallback(BindTransceiverCallback)); SetSmscConnectionStatus(SmscConnectionStatus.Bound); }
private void OnSessionDisconnected(object sender, SmppEventArgs args) { SmppDisconnectEventArgs dea = (SmppDisconnectEventArgs)args; if (dea.Exception != null) { MessageBox.Show("Socket error: " + ((dea.Exception.Message != null) ? dea.Exception.Message : dea.Exception.ToString())); } else { MessageBox.Show("Smsc Session/Connection was dropped"); } SetSmscConnectionStatus(SmscConnectionStatus.Disconnected); }
private static void OnSessionBound(object sender, SmppEventArgs args) { // Session is now bound Console.WriteLine("Session is successfully bound to the SMSC"); // Try sending a single message submit_sm submitPdu = new submit_sm(); submitPdu.SourceAddress = new address(TypeOfNumber.NATIONAL, NumericPlanIndicator.E164, "9727321655"); submitPdu.DestinationAddress = new address(TypeOfNumber.NATIONAL, NumericPlanIndicator.E164, "9724151634"); submitPdu.RegisteredDelivery = new registered_delivery(DeliveryReceiptType.FINAL_DELIVERY_RECEIPT, AcknowledgementType.DELIVERY_USER_ACK_REQUEST, true); mBloxOperatorId operatorId = new mBloxOperatorId("12345"); submitPdu.AddVendorSpecificElements(operatorId); submitPdu.Message = "This is a test"; // TlvParameter test = submitPdu.GetOptionalElement(operatorId.Tag); _smppSession.BeginSubmitSm(submitPdu, new AsyncCallback(SubmitSmCallback)); }
private void OnError(object sender, SmppEventArgs ea) { SmppErrorEventArgs eea = (SmppErrorEventArgs)ea; SmppPdu pdu = eea.PDU; if (pdu != null) { AddLogText(StatusCode.Error, string.Format("{0} PDU: {1}", eea.Session, pdu.CommandId)); } else { AddLogText(StatusCode.Error, string.Format("{0}", eea.Session)); } Exception ex = eea.Exception; while (ex != null) { AddLogText(StatusCode.Error, ex.ToString()); ex = ex.InnerException; } }
private void OnSubmitSm(object sender, SmppEventArgs ea) { submit_sm req = (submit_sm)ea.PDU; AddLogText(StatusCode.Normal, string.Format("SendSms: {0}", req.Message)); submit_sm_resp resp = (submit_sm_resp)ea.ResponsePDU; resp.MessageID = Interlocked.Increment(ref nxtMid_).ToString(); // Create our tracking message and insert it into the list. SmsMessage message = new SmsMessage(ea.Session, req, resp.MessageID, req.RegisteredDelivery.DeliveryReceipt); new MessageListViewItem(lvMessages, message); arrMessages.Add(message); // If we need a delivery receipt, then generate a callback to provide it. if (respType_ != MessageResponse.Manual_Response) { new System.Threading.Timer(new TimerCallback(SendAck), message, randGen_.Next(10000), Timeout.Infinite); } }
// Used to get delivery ack.'s and MO messages from SMSC private void OnDeliverSm(object sender, SmppEventArgs args) { deliver_sm req = (deliver_sm)args.PDU; deliver_sm_resp resp = (deliver_sm_resp)args.ResponsePDU; esm_class esm = req.EsmClass; switch (esm.MessageType) { case MessageType.SMSC_DELIVERY_RCPT: // Delivery receipt for previously sent short message smsc_delivery_receipt receipt = new smsc_delivery_receipt(req.Message); // Update the final deleivery status for the sent message using the message Id to locate UpdateSentMessageFinalStatus(receipt); break; case MessageType.DEFAULT_MSG_TYPE: // Mobile originated message AddNewMessage("Mobile Orig.", req.SourceAddress.Address, req.Message, "DELIVRD", DateTime.Now.ToString("d"), 0); break; default: AddNewMessage("Error", req.SourceAddress.Address, "Unknown message type - " + esm.MessageType, "n/a", "n/a", 0); break; } }
private void OnBind(object sender, SmppEventArgs ea) { SmppPdu pdu = ea.PDU; if ((pdu as bind_receiver) != null || (pdu as bind_transmitter) != null) { ea.ResponsePDU.Status = StatusCodes.ESME_RINVCMDID; } else { bind_transceiver btpdu = (bind_transceiver)pdu; if (btpdu.Password != password_) { ea.ResponsePDU.Status = StatusCodes.ESME_RINVPASWD; return; } bind_transceiver_resp resp = (bind_transceiver_resp)ea.ResponsePDU; resp.InterfaceVersion = (byte)supportedVersion_; } // Update the listview. new System.Threading.Timer(new TimerCallback(UpdateListItem), ea.Session.Tag, 100, Timeout.Infinite); }
// Used to get delivery ack.'s and MO messages from SMSC private static void OnDeliverSm(object sender, SmppEventArgs args) { deliver_sm req = (deliver_sm)args.PDU; deliver_sm_resp resp = (deliver_sm_resp)args.ResponsePDU; esm_class esm = req.EsmClass; switch (esm.MessageType) { case MessageType.SMSC_DELIVERY_RCPT: // Delivery receipt for previously sent short message smsc_delivery_receipt receipt = new smsc_delivery_receipt(req.Message); Console.WriteLine(string.Format("Delivery receipt for message {0}: Type: {1}", receipt.OriginalMessageId, receipt.FinalMessageStatus)); break; case MessageType.DEFAULT_MSG_TYPE: // Mobile originated message Console.WriteLine(string.Format("Mobile originated message from {0}: {1}", req.SourceAddress, req.Message)); break; default: Console.WriteLine("Unexpected deliver_sm message type: " + esm.MessageType.ToString()); break; } }
private void OnUnbind(object sender, SmppEventArgs ea) { new System.Threading.Timer(new TimerCallback(UpdateListItem), ea.Session.Tag, 100, Timeout.Infinite); }
public static void OnPostprocessPdu(object sender, SmppEventArgs ea) { Console.WriteLine(string.Format("SEND: {0}\r\n{1}\r\n", ea.PDU.ToString(), ea.PDU.ToString("b"))); }
public static void OnPreprocessPdu(object sender, SmppEventArgs ea) { Console.WriteLine(string.Format("RCV: {0}\r\n", ea.PDU.ToString())); }
private static void OnSessionDisconnected(object sender, SmppEventArgs args) { // If we are not shutting down then attempt to reconnect using a timer Console.WriteLine("Sesssion disconnected..."); }