void server_evClientConnected(object sender, SmppServerClient client) { //Change number of threads that process received messages. Dafault is 3 //client.WorkerThreads = 10; //Change receive buffer size for client socket // client.ReceiveBufferSize = 30 * 1024 * 1024; //Change send buffer size for client socket // client.SendBufferSize = 30 * 1024 * 1024; //Don't allow this client to send more than one message per second //client.ReceiveSpeedLimit = 1; //Set maximum number of unhandled messages in the receive queue for this client //client.ReceiveQueueLimit = 2; client.EncodingMapper.MapEncoding(DataCodings.Class1, new Inetlab.SMPP.Encodings.GSMPackedEncoding()); _log.Info("Client {0} connected.", client.RemoteEndPoint); if (client.ClientCertificate != null) { _log.Info("Client Certificate {0}, Expire Date: {1}", client.ClientCertificate.Subject, client.ClientCertificate.GetExpirationDateString()); } Sync(lbClients, () => { lbClients.Items.Add(client); }); }
private void ServerOnClientSubmitSm(object sender, SmppServerClient client, SubmitSm pdu) { Console.WriteLine($"Inbound message from {client.SystemID}"); //Set server message id for the pdu; pdu.Response.MessageId = Guid.NewGuid().ToString().Substring(0, 8); }
void server_evClientSubmitMulti(object sender, SmppServerClient client, SubmitMulti data) { _log.Info("Client {0} sends message From:{1} to multiple destinations:{2}, Text: {3}", client.RemoteEndPoint, data.SourceAddress, data.DestinationAddresses.Count, data.GetMessageText(client.EncodingMapper)); _messageComposer.AddMessage(data); if (data.RegisteredDelivery == 1) { SmeAddress destinationAddress = data.DestinationAddresses[0] as SmeAddress; string messageText = data.GetMessageText(client.EncodingMapper); //Send Delivery Receipt when required Task.Run(() => client.Deliver( SMS.ForDeliver() .From(data.SourceAddress) .To(destinationAddress) .Coding(data.DataCoding) .Receipt(new Receipt { DoneDate = DateTime.Now, State = MessageState.Delivered, MessageId = data.Response.MessageId, ErrorCode = "0", SubmitDate = DateTime.Now, Text = messageText.Substring(0, Math.Max(20, messageText.Length)) } ) )); } }
//<DeliverMessagesOnBind> private void OnClientBind(object sender, SmppServerClient client, Bind pdu) { if (client.BindingMode == ConnectionMode.Transceiver || client.BindingMode == ConnectionMode.Receiver) { //Start messages delivery Task messagesTask = DeliverMessagesAsync(client, pdu); } }
private void server_evClientDisconnected(object sender, SmppServerClient client) { _log.Info("Client {0} disconnected.", client.RemoteEndPoint); Sync(lbClients, () => { lbClients.Items.Remove(client); }); }
private void bSendMessage_Click(object sender, EventArgs e) { SmppServerClient client = lbClients.SelectedItem as SmppServerClient; if (client != null) { SendMessage form = new SendMessage(client); form.ShowDialog(); } }
public SendMessage(SmppServerClient client) { InitializeComponent(); _client = client; if (_client != null) { lClient.Text = _client.ToString(); } }
//</DeliverMessagesOnBind> //How to send message to connected client // //<DeliverToClient> public async Task DeliverToClient(SmppServerSample.TextMessage message) { string systemId = GetSystemIdByServiceAddress(message.ServiceAddress); SmppServerClient client = FindClient(systemId); await client.Deliver(SMS.ForDeliver() .From(message.PhoneNumber) .To(message.ServiceAddress) .Text(message.Text) ); }
private void server_evClientSubmitSm(object sender, SmppServerClient client, SubmitSm data) { long messageId = Interlocked.Increment(ref messageIdCounter); // You can set your own MessageId data.Response.MessageId = messageId.ToString(); _log.Info("Client {0} sends message From:{1}, To:{2}, Text: {3}", client.RemoteEndPoint, data.SourceAddress, data.DestinationAddress, data.GetMessageText(client.EncodingMapper)); _messageComposer.AddMessage(data); // Set unsuccess response status //data.Response.Status = CommandStatus.ESME_RSUBMITFAIL; if (data.SMSCReceipt != SMSCDeliveryReceipt.NotRequested) { //Send Delivery Receipt when required string messageText = data.GetMessageText(client.EncodingMapper); var dlrBuilder = SMS.ForDeliver() .From(data.DestinationAddress) .To(data.SourceAddress) .Receipt(new Receipt { DoneDate = DateTime.Now, State = MessageState.Delivered, MessageId = data.Response.MessageId, ErrorCode = "0", SubmitDate = DateTime.Now, Text = messageText.Substring(0, Math.Min(20, messageText.Length)) }); if (data.DataCoding == DataCodings.UCS2) { //short_message field cannot contain user data longer than 255 octets, //therefore for UCS2 encoding we are sending DLR in message_payload parameter dlrBuilder.MessageInPayload(); } client.Deliver(dlrBuilder).ConfigureAwait(false); } }
private async Task DeliverMessagesAsync(SmppServerClient client, Bind pdu) { var messages = _messageStore.GetMessagesForClient(pdu.SystemId, pdu.SystemType); foreach (TextMessage message in messages) { var pduBuilder = SMS.ForDeliver() .From(message.PhoneNumber) .To(message.ServiceAddress) .Text(message.Text); var responses = await client.Deliver(pduBuilder); _messageStore.UpdateMessageState(message.Id, responses); } }
private async void bDisconnect_Click(object sender, EventArgs e) { SmppServerClient client = lbClients.SelectedItem as SmppServerClient; if (client != null) { if (client.Status == ConnectionStatus.Bound) { await client.UnBind(); } if (client.Status == ConnectionStatus.Open) { await client.Disconnect(); } } }
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); } }
private async Task DeliverMessagesAsync(SmppServerClient client, Bind pdu) { var messages = _messageStore.GetMessagesForClient(pdu.SystemId, pdu.SystemType); foreach (TextMessage message in messages) { var pduBuilder = SMS.ForDeliver() .From(message.PhoneNumber) .To(message.ServiceAddress) .Text(message.Text); var responses = await client.Deliver(pduBuilder); if (responses.All(x => x.Header.Status == CommandStatus.ESME_ROK)) { _messageStore.MessageWasDelivered(message.Id); } } Console.WriteLine($"Dummy messages have been sent to the client with systemId {pdu.SystemId}."); }
private async void WhenServerReceivesPDU(object sender, SmppServerClient serverClient, SubmitSm data) { if (data.RegisteredDelivery == 1) { //Send Delivery Receipt when required await serverClient.Deliver( SMS.ForDeliver() .From(data.SourceAddress) .To(data.DestinationAddress) .Coding(data.DataCoding) .Receipt(new Receipt { DoneDate = DateTime.Now, State = MessageState.Delivered, MessageId = data.Response.MessageId, ErrorCode = "0", SubmitDate = DateTime.Now } ) ) .ConfigureAwait(false); } }
private void server_evClientBind(object sender, SmppServerClient client, Bind data) { _log.Info("Client {0} bind as {1}:{2}", client.RemoteEndPoint, data.SystemId, data.Password); // data.Response.ChangeSystemId("NewServerId"); //Check SMPP access, and if it is wrong retund non-OK status. if (data.SystemId == "") { data.Response.Header.Status = CommandStatus.ESME_RINVSYSID; _log.Info("Client {0} tries to bind with invalid SystemId: {1}", client.RemoteEndPoint, data.SystemId); return; } if (data.Password == "") { _log.Info(string.Format("Client {0} tries to bind with invalid Password.", client.RemoteEndPoint)); data.Response.Header.Status = CommandStatus.ESME_RINVPASWD; return; } //deny multiple connection with same smpp system id. foreach (var connectedClient in _server.ConnectedClients) { if (connectedClient.SystemID == client.SystemID && connectedClient.Status == ConnectionStatus.Bound) { data.Response.Header.Status = CommandStatus.ESME_RALYBND; _log.Warn("Client {0} tries to establish multiple sessions with the same SystemId", client.RemoteEndPoint); return; } } _log.Info("Client {0} has been bound.", client.RemoteEndPoint); // CommandStatus.ESME_RBINDFAIL - when Bind Failed. UpdateClient(client); }
private void UpdateClient(SmppServerClient client) { Sync(this, () => { int index = -1; for (int i = 0; i < lbClients.Items.Count; i++) { SmppServerClient item = lbClients.Items[i] as SmppServerClient; if (item != null && item.RemoteEndPoint.Equals(client.RemoteEndPoint)) { index = i; break; } } if (index >= 0) { lbClients.Items[index] = client; } else { lbClients.Items.Add(client); } }); }
private void ServerOnClientBind(object sender, SmppServerClient client, Bind pdu) { //Set server name. pdu.Response.SystemId = "MySMPPServer"; //check if client is allowed to create SMPP session. //if (IsClientAllowed(pdu)) //{ Console.WriteLine($"Client {client.SystemID} has bound"); //Check if bound client can receive messages if (client.BindingMode == ConnectionMode.Transceiver || client.BindingMode == ConnectionMode.Receiver) { //Start messages delivery Task messagesTask = DeliverMessagesAsync(client, pdu); } //} //else //{ // Console.WriteLine($"New session from client {client.SystemID} is denied."); // pdu.Response.Header.Status = CommandStatus.ESME_RBINDFAIL; //} }
private void ServerOnClientEnquireLink(object sender, SmppServerClient client, EnquireLink data) { _log.Info($"EnquireLink received from {client}"); }
//How to set MessageId // //<SetMessageIdForSubmitSm> private void ServerOnClientSubmitSm(object sender, SmppServerClient client, SubmitSm data) { data.Response.MessageId = Guid.NewGuid().ToString().Substring(0, 8); }