Windows service for SMPP Server

Post Reply
ammar
Posts: 2
Joined: Thu Jan 02, 2020 4:08 pm

Windows service for SMPP Server

Post by ammar » Thu Jan 02, 2020 4:12 pm

Hi,
I want create windows service for Smpp server. How I can do it? Do you have sample code for develop it?
alt
Site Admin
Posts: 843
Joined: Tue Apr 25, 2006 9:45 am

Re: Windows service for SMPP Server

Post by alt » Tue Jan 07, 2020 1:43 pm

Hi ammar,

You can start with following example:

Code: Select all

 static void Main()
 {
            //Fix Current dir for windows service
            System.IO.Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);


            var servicesToRun = new ServiceBase[]
            {
                new SmppServerWindowsService(), 
            };

            ServiceBase.Run(servicesToRun);
}

Code: Select all

public class SmppServerWindowsService : ServiceBase
{
        private readonly SmppServer _server;
        private readonly ILog _log;
      
        public SmppServerWindowsService()
        {
            ServiceName = "SMPPServer";

          
            LogManager.SetLoggerFactory( new FileLogFactory(ServiceName+".log", LogLevel.Info));

            _log = LogManager.GetLogger(GetType().Name);

             _server = new SmppServer(new IPEndPoint(IPAddress.Any, 7777));
             _server.evClientConnected += server_evClientConnected;
             _server.evClientDisconnected += server_evClientDisconnected;
             _server.evClientBind += server_evClientBind;
             _server.evClientSubmitSm += server_evClientSubmitSm;
        }

        protected override void OnStart(string[] args)
        {
            _server.Start();
        }

        protected override void OnStop()
        {
            _server.Stop();
        }


        void server_evClientConnected(object sender, SmppServerClient client)
        {
            _log.Info("Client {0} connected.", client.RemoteEndPoint);

            //If needed, you can change encoding mapping for the client
            client.EncodingMapper.MapEncoding(DataCodings.OctetUnspecified, new GSMEncoding());
        }

        void server_evClientDisconnected(object sender, SmppServerClient client)
        {
            _log.Info("Client {0} disconnected.", client.RemoteEndPoint);
        }

        private void server_evClientBind(object sender, SmppServerClient client, Inetlab.SMPP.PDU.Bind data)
        {
            _log.Info("Client {0} Binding {1}:{2}", client.RemoteEndPoint, data.SystemId, data.Password);

            //  data.Response.ChangeSystemId("NewServerId");

            //Check SMPP access, and if it is wrong returns non-OK status.
            if (data.SystemId == "")
            {
                data.Response.Header.Status = CommandStatus.ESME_RINVSYSID;
                return;
            }
            if (data.Password == "")
            {
                data.Response.Header.Status = CommandStatus.ESME_RINVPASWD;
                return;
            }

            //  CommandStatus.ESME_RALYBND  - when SMPP account already connected.
            //  CommandStatus.ESME_RBINDFAIL - when Bind Failed. 

        }

        void server_evClientSubmitSm(object sender, SmppServerClient client, Inetlab.SMPP.PDU.SubmitSm data)
        {
            string messageText = data.GetMessageText(client.EncodingMapper);


            _log.Info(string.Format("Client {0} Received message Src:{1}, Dst:{2}, Text: {3}",
                client.RemoteEndPoint, data.SourceAddress, data.DestinationAddress,
                messageText));
            

            // You can set your own MessageId
            // data.Response.MessageId = "11";



        }
}
developerlearn999
Posts: 85
Joined: Thu Jun 20, 2019 9:34 am

Re: Windows service for SMPP Server

Post by developerlearn999 » Fri Jan 17, 2020 11:43 am

you can take from github template for windows service and implemant that inetlab code inside very simple
ammar
Posts: 2
Joined: Thu Jan 02, 2020 4:08 pm

Re: Windows service for SMPP Server

Post by ammar » Sun Jan 19, 2020 7:24 pm

Can you please share me the github link?
Post Reply