Table of Contents

SSL/TLS Connection

Inetlab.SMPP library supports SSL connection between client and server.

For SmppServer class you can set server certificate and supported SSL/TLS protocols.

For SmppClient class you can specify supported SSL/TLS protocols, and optional client certificate for authentication.

using (SmppServer server = new SmppServer(new IPEndPoint(IPAddress.Any, 7777)))
{
    server.EnabledSslProtocols = SslProtocols.Tls12;
    server.ServerCertificate = new X509Certificate2("server_certificate.p12", "cert_password");

    server.Start();

    server.evClientConnected += (sender, client) =>
    {
        var clientCertificate = client.ClientCertificate;
        //You can validate client certificate and disconnect if it is not valid.
    };

    using (SmppClient client = new SmppClient())
    {
        client.EnabledSslProtocols = SslProtocols.Tls12;
        //if required you can be authenticated with client certificate
        client.ClientCertificates.Add(new X509Certificate2("client_certificate.p12", "cert_password"));

        if (await client.ConnectAsync("localhost", 7777))
        {
            BindResp bindResp = await client.BindAsync("username", "password");

            if (bindResp.Header.Status == CommandStatus.ESME_ROK)
            {
                var submitResp = await client.SubmitAsync(
                    SMS.ForSubmit()
                        .From("111")
                        .To("436641234567")
                        .Coding(DataCodings.UCS2)
                        .Text("Hello World!"));

                if (submitResp.All(x => x.Header.Status == CommandStatus.ESME_ROK))
                {
                    client.Logger.Info("Message has been sent.");
                }
            }

            await client.DisconnectAsync();
        }
    }
}