Пример #1
0
        protected override void OnStart(string[] args)
        {
            log.Info("Starting...");
            for (int i = 0; i < MAX_THREADS; i++)
            {
                string parms = "";
                switch (i)
                {
                case 0: parms = Properties.Settings.Default.Binding1; break;

                case 1: parms = Properties.Settings.Default.Binding2; break;

                case 2: parms = Properties.Settings.Default.Binding3; break;

                case 3: parms = Properties.Settings.Default.Binding4; break;

                case 4: parms = Properties.Settings.Default.Binding5; break;
                }
                if (!String.IsNullOrEmpty(parms))
                {
                    ServiceMapping sm = ParseParameters(parms.Split(new char[] { ' ' }));
                    log.Info("Found service map: " + sm);
                    handlers[i] = new Comm2IP.Comm2IP(sm.ipAddress, sm.ipPort, sm.commPort, sm.commRate);
                    threads[i]  = new Thread(new ThreadStart(handlers[i].Run));
                    threads[i].Start();
                }
                else
                {
                    handlers[i] = null;
                    threads[i]  = null;
                }
            }
        }
Пример #2
0
 public static void Main(string[] args)
 {
     Comm2IPService service = new Comm2IPService();
     if (!Environment.UserInteractive)
     {
         ServiceBase.Run(service);
     }
     else
     {
         try
         {
             if (args.Length == 1)
             {
                 if (args[0] == "--install") ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
                 else if (args[0] == "--uninstall") ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
             }
             else
             {
                 ServiceMapping sm = service.ParseParameters(args);
                 if (service.CheckParameters(sm))
                 {
                     Console.WriteLine("Running in interactive mode, press Ctrl-C to abort...");
                     Comm2IP.Comm2IP com = new Comm2IP.Comm2IP(sm.ipAddress, sm.ipPort, sm.commPort, sm.commRate);
                     Thread listener = new Thread(new ThreadStart(com.Run));
                     listener.Start();
                     listener.Join();
                 }
             }
         }
         catch (Exception e)
         {
             log.Fatal(e);
         }
     }
 }
Пример #3
0
        private void PreparePort()
        {
            Output("Persiapan port untuk membaca sms.");
            Output(Library.getLibraryDescription());
            Output("Version: " + Library.getLibraryVersion());

            // *** The tricky part ***
            // *** Comm2IP Driver ***
            // Create (and start!) as many Comm2IP threads as the modems you are using.
            // Be careful about the mappings - use the same mapping in the Gateway definition.
            com1 = new Comm2IP.Comm2IP(new byte[] { 127, 0, 0, 1 }, 12000, ModemPort, ModemBaudRate);

            // Start the COM listening thread.
            new Thread(new ThreadStart(com1.Run)).Start();

            // Create the Gateway representing the serial GSM modem.
            // Due to the Comm2IP bridge, in SMSLib for .NET all modems are considered IP modems.
            gateway = new IPModemGateway("modem." + ModemPort, "127.0.0.1", 12000, "Wavecom", "M1306B");
            gateway.setIpProtocol(ModemGateway.IPProtocols.BINARY);

            // Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
            gateway.setProtocol(AGateway.Protocols.PDU);

            // Do we want the Gateway to be used for Inbound messages?
            gateway.setInbound(true);

            // Do we want the Gateway to be used for Outbound messages?
            gateway.setOutbound(true);

            // Add the Gateway to the Service object.
            srv.addGateway(gateway);

            // Start! (i.e. connect to all defined Gateways)
            srv.startService();
        }
Пример #4
0
        private void PreparePort()
        {
            try
            {
                Output("Persiapan port untuk kirim sms.");
                Output("loading ...........");
                //Output(Library.getLibraryDescription());
                //Output("Version: " + Library.getLibraryVersion());

                // *** The tricky part ***
                // *** Comm2IP Driver ***
                // Create (and start!) as many Comm2IP threads as the modems you are using.
                // Be careful about the mappings - use the same mapping in the Gateway definition.
                com1 = new Comm2IP.Comm2IP(new byte[] { 127, 0, 0, 1 }, 12000, ModemPort, ModemBaudRate);

                // Start the COM listening thread.
                new Thread(new ThreadStart(com1.Run)).Start();

                // Create the Gateway representing the serial GSM modem.
                // Due to the Comm2IP bridge, in SMSLib for .NET all modems are considered IP modems.
                gateway = new IPModemGateway("modem." + ModemPort, "127.0.0.1", 12000, "Wavecom", "M1306B");
                gateway.setIpProtocol(ModemGateway.IPProtocols.BINARY);

                // Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
                gateway.setProtocol(AGateway.Protocols.PDU);

                // Do we want the Gateway to be used for Inbound messages?
                gateway.setInbound(true);

                // Do we want the Gateway to be used for Outbound messages?
                gateway.setOutbound(true);

                // Add the Gateway to the Service object.
                srv.addGateway(gateway);

                // Start! (i.e. connect to all defined Gateways)
                srv.startService();

                Output("Persiapan port sukses.");

                btnDisconnect.Enabled = true;
                btnOK.Enabled         = false;
                gbSMS.Enabled         = true;
            }
            catch (Exception ex)
            {
                Output("Persiapan port error : " + ex.GetBaseException().Message);
                Output("Langkah penanggulangan : ");
                Output("1. Cek koneksi modem anda, pastikan port yang dipilih benar.");
                Output("2. restart program ini dan pasang ulang modem anda");
                Output("3. Jika masih error, coba restart komputer ini");
            }
        }
        public void set(string gateway_name,int port,byte[] b_ip,string s_ip)
        {     
            srv = Service.getInstance();
            com1 = new Comm2IP.Comm2IP(b_ip, port, modem.AttachedTo , 115200); //modem comport

            try
            {
                new Thread(new ThreadStart(com1.Run)).Start();

                IPModemGateway gateway = new IPModemGateway(gateway_name, s_ip, port, "Huawei", "");

                gateway.setIpProtocol(ModemGateway.IPProtocols.BINARY);
                gateway.setProtocol(AGateway.Protocols.PDU);
                gateway.setInbound(true);
                gateway.setOutbound(true);
                gateway.setSimPin("0000");

                srv.addGateway(gateway);

                // Start! (i.e. connect to all defined Gateways)
                srv.startService();

                // Send more than one message at once.
                OutboundMessage[] msgArray = new OutboundMessage[contact_list.Count];
                int count = 0;

                foreach (int number in contact_list)
                {
                    msgArray[count++] = new OutboundMessage(number.ToString(), sms.Content);
                }

                srv.sendMessages(msgArray);

                //Console.WriteLine(msgArray[0]);
                //Console.WriteLine(msgArray[1]);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Console.Read();
            }
            finally
            {
                com1.Stop();
                srv.stopService();
            }
        }
Пример #6
0
        public void set(string gateway_name, int port, byte[] b_ip, string s_ip)
        {
            srv  = Service.getInstance();
            com1 = new Comm2IP.Comm2IP(b_ip, port, modem.AttachedTo, 115200);  //modem comport

            try
            {
                new Thread(new ThreadStart(com1.Run)).Start();

                IPModemGateway gateway = new IPModemGateway(gateway_name, s_ip, port, "Huawei", "");

                gateway.setIpProtocol(ModemGateway.IPProtocols.BINARY);
                gateway.setProtocol(AGateway.Protocols.PDU);
                gateway.setInbound(true);
                gateway.setOutbound(true);
                gateway.setSimPin("0000");

                srv.addGateway(gateway);

                // Start! (i.e. connect to all defined Gateways)
                srv.startService();

                // Send more than one message at once.
                OutboundMessage[] msgArray = new OutboundMessage[contact_list.Count];
                int count = 0;

                foreach (int number in contact_list)
                {
                    msgArray[count++] = new OutboundMessage(number.ToString(), sms.Content);
                }

                srv.sendMessages(msgArray);

                //Console.WriteLine(msgArray[0]);
                //Console.WriteLine(msgArray[1]);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Console.Read();
            }
            finally
            {
                com1.Stop();
                srv.stopService();
            }
        }
Пример #7
0
        public static void Main(string[] args)
        {
            Comm2IPService service = new Comm2IPService();

            if (!Environment.UserInteractive)
            {
                ServiceBase.Run(service);
            }
            else
            {
                try
                {
                    if (args.Length == 1)
                    {
                        if (args[0] == "--install")
                        {
                            ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
                        }
                        else if (args[0] == "--uninstall")
                        {
                            ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
                        }
                    }
                    else
                    {
                        ServiceMapping sm = service.ParseParameters(args);
                        if (service.CheckParameters(sm))
                        {
                            Console.WriteLine("Running in interactive mode, press Ctrl-C to abort...");
                            Comm2IP.Comm2IP com      = new Comm2IP.Comm2IP(sm.ipAddress, sm.ipPort, sm.commPort, sm.commRate);
                            Thread          listener = new Thread(new ThreadStart(com.Run));
                            listener.Start();
                            listener.Join();
                        }
                    }
                }
                catch (Exception e)
                {
                    log.Fatal(e);
                }
            }
        }
Пример #8
0
        public void DoIt()
        {
            // Create new Service object - the parent of all and the main interface to you.
            Service srv;

            srv = Service.getInstance();

            // *** The tricky part ***
            // *** Comm2IP Driver ***
            // Create (and start!) as many Comm2IP threads as the modems you are using.
            // Be careful about the mappings - use the same mapping in the Gateway definition.
            Comm2IP.Comm2IP com4 = new Comm2IP.Comm2IP(new byte[] { 127, 0, 0, 1 }, 12000, "com4", 115200);

            try
            {
                Console.WriteLine("Example: Read messages from a serial gsm modem.");
                Console.WriteLine(Library.getLibraryDescription());
                Console.WriteLine("Version: " + Library.getLibraryVersion());

                // Start the COM listening thread.
                new Thread(new ThreadStart(com4.Run)).Start();

                // Lets set some callbacks.
                srv.setInboundMessageNotification(new InboundNotification());
                srv.setCallNotification(new CallNotification());
                srv.setGatewayStatusNotification(new GatewayStatusNotification());

                // Create the Gateway representing the serial GSM modem.
                // Due to the Comm2IP bridge, in SMSLib for .NET all modems are considered IP modems.
                IPModemGateway gateway = new IPModemGateway("modem.com4", "127.0.0.1", 12000, "Huawei", "E220");
                gateway.setIpProtocol(ModemGateway.IPProtocols.BINARY);

                // Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
                gateway.setProtocol(AGateway.Protocols.PDU);

                // Do we want the Gateway to be used for Inbound messages?
                gateway.setInbound(true);

                // Do we want the Gateway to be used for Outbound messages?
                gateway.setOutbound(true);

                // Let SMSLib know which is the SIM PIN.
                gateway.setSimPin("0000");

                // Add the Gateway to the Service object.
                srv.addGateway(gateway);

                // Similarly, you may define as many Gateway objects, representing
                // various GSM modems, add them in the Service object and control all of them.

                // Start! (i.e. connect to all defined Gateways)
                srv.startService();

                // Printout some general information about the modem.
                Console.WriteLine();
                Console.WriteLine("Modem Information:");
                Console.WriteLine("  Manufacturer: " + gateway.getManufacturer());
                Console.WriteLine("  Model: " + gateway.getModel());
                Console.WriteLine("  Serial No: " + gateway.getSerialNo());
                Console.WriteLine("  SIM IMSI: " + gateway.getImsi());
                Console.WriteLine("  Signal Level: " + gateway.getSignalLevel() + "dBm");
                Console.WriteLine("  Battery Level: " + gateway.getBatteryLevel() + "%");
                Console.WriteLine();

                // Read Messages. The reading is done via the Service object and
                // affects all Gateway objects defined. This can also be more directed to a specific
                // Gateway - look the JavaDocs for information on the Service method calls.
                InboundMessage[] msgList = srv.readMessages(org.smslib.InboundMessage.MessageClasses.ALL);
                foreach (InboundMessage msg in msgList)
                {
                    Console.WriteLine(msg);
                }

                Console.WriteLine("Press <ENTER> to terminate...");
                Console.In.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                srv.stopService();
                com4.Stop();
            }
        }
Пример #9
0
 protected override void OnStart(string[] args)
 {
     log.Info("Starting...");
     for (int i = 0; i < MAX_THREADS; i++)
     {
         string parms = "";
         switch (i)
         {
             case 0: parms = Properties.Settings.Default.Binding1; break;
             case 1: parms = Properties.Settings.Default.Binding2; break;
             case 2: parms = Properties.Settings.Default.Binding3; break;
             case 3: parms = Properties.Settings.Default.Binding4; break;
             case 4: parms = Properties.Settings.Default.Binding5; break;
         }
         if (!String.IsNullOrEmpty(parms))
         {
             ServiceMapping sm = ParseParameters(parms.Split(new char[] { ' ' }));
             log.Info("Found service map: " + sm);
             handlers[i] = new Comm2IP.Comm2IP(sm.ipAddress, sm.ipPort, sm.commPort, sm.commRate);
             threads[i] = new Thread(new ThreadStart(handlers[i].Run));
             threads[i].Start();
         }
         else
         {
             handlers[i] = null;
             threads[i] = null;
         }
     }
 }
Пример #10
0
		public void DoIt()
		{
			// Create new Service object - the parent of all and the main interface to you.
			Service srv;
			srv = Service.getInstance();

			// *** The tricky part ***
			// *** Comm2IP Driver ***
			// Create (and start!) as many Comm2IP threads as the modems you are using.
			// Be careful about the mappings - use the same mapping in the Gateway definition.
			Comm2IP.Comm2IP com4 = new Comm2IP.Comm2IP(new byte[] { 127, 0, 0, 1 }, 12000, "com4", 115200);

			try
			{
				Console.WriteLine("Example: Read messages from a serial gsm modem.");
				Console.WriteLine(Library.getLibraryDescription());
				Console.WriteLine("Version: " + Library.getLibraryVersion());

				// Start the COM listening thread.
				new Thread(new ThreadStart(com4.Run)).Start();

				// Lets set some callbacks.
				srv.setInboundMessageNotification(new InboundNotification());
				srv.setCallNotification(new CallNotification());
				srv.setGatewayStatusNotification(new GatewayStatusNotification());

				// Create the Gateway representing the serial GSM modem.
				// Due to the Comm2IP bridge, in SMSLib for .NET all modems are considered IP modems.
				IPModemGateway gateway = new IPModemGateway("modem.com4", "127.0.0.1", 12000, "Huawei", "E220");
				gateway.setIpProtocol(ModemGateway.IPProtocols.BINARY);

				// Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
				gateway.setProtocol(AGateway.Protocols.PDU);

				// Do we want the Gateway to be used for Inbound messages?
				gateway.setInbound(true);

				// Do we want the Gateway to be used for Outbound messages?
				gateway.setOutbound(true);

				// Let SMSLib know which is the SIM PIN.
				gateway.setSimPin("0000");

				// Add the Gateway to the Service object.
				srv.addGateway(gateway);

				// Similarly, you may define as many Gateway objects, representing
				// various GSM modems, add them in the Service object and control all of them.

				// Start! (i.e. connect to all defined Gateways)
				srv.startService();

				// Printout some general information about the modem.
				Console.WriteLine();
				Console.WriteLine("Modem Information:");
				Console.WriteLine("  Manufacturer: " + gateway.getManufacturer());
				Console.WriteLine("  Model: " + gateway.getModel());
				Console.WriteLine("  Serial No: " + gateway.getSerialNo());
				Console.WriteLine("  SIM IMSI: " + gateway.getImsi());
				Console.WriteLine("  Signal Level: " + gateway.getSignalLevel() + "dBm");
				Console.WriteLine("  Battery Level: " + gateway.getBatteryLevel() + "%");
				Console.WriteLine();

				// Read Messages. The reading is done via the Service object and
				// affects all Gateway objects defined. This can also be more directed to a specific
				// Gateway - look the JavaDocs for information on the Service method calls.
				InboundMessage[] msgList = srv.readMessages(org.smslib.InboundMessage.MessageClasses.ALL);
				foreach (InboundMessage msg in msgList)
					Console.WriteLine(msg);

				Console.WriteLine("Press <ENTER> to terminate...");
				Console.In.ReadLine();
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				Console.WriteLine(e.StackTrace);
			}
			finally
			{
				srv.stopService();
				com4.Stop();
			}
		}
Пример #11
0
        static void Main(string[] args)
        {
            // Create new Service object - the parent of all and the main interface to you.
            Service srv;

            srv = Service.getInstance();

            // *** The tricky part ***
            // *** Comm2IP Driver ***
            // Create (and start!) as many Comm2IP threads as the modems you are using.
            // Be careful about the mappings - use the same mapping in the Gateway definition.
            Comm2IP.Comm2IP com1 = new Comm2IP.Comm2IP(new byte[] { 127, 0, 0, 1 }, 12000, "com4", 115200);

            try
            {
                Console.WriteLine("Example: Read messages from a serial gsm modem.");
                Console.WriteLine(Library.getLibraryDescription());
                Console.WriteLine("Version: " + Library.getLibraryVersion());

                // Start the COM listening thread.
                new Thread(new ThreadStart(com1.Run)).Start();

                // Lets set some callbacks.
                srv.setInboundMessageNotification(new InboundNotification());
                srv.setCallNotification(new CallNotification());
                srv.setGatewayStatusNotification(new GatewayStatusNotification());

                // Create the Gateway representing the serial GSM modem.
                // Due to the Comm2IP bridge, in SMSLib for .NET all modems are considered IP modems.
                IPModemGateway gateway = new IPModemGateway("modem.com4", "127.0.0.1", 12000, "Huawei", "E220");
                gateway.setIpProtocol(ModemGateway.IPProtocols.BINARY);

                // Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
                gateway.setProtocol(AGateway.Protocols.PDU);

                // Do we want the Gateway to be used for Inbound messages?
                gateway.setInbound(true);

                // Do we want the Gateway to be used for Outbound messages?
                gateway.setOutbound(true);

                // Let SMSLib know which is the SIM PIN.
                gateway.setSimPin("0000");

                // Explicit SMSC address set is required for some modems.
                // Below is for VODAFONE GREECE - be sure to set your own!
                gateway.setSmscNumber("+306942190000");

                // Add the Gateway to the Service object.
                srv.addGateway(gateway);

                // Similarly, you may define as many Gateway objects, representing
                // various GSM modems, add them in the Service object and control all of them.

                // Start! (i.e. connect to all defined Gateways)
                srv.startService();

                // Printout some general information about the modem.
                Console.WriteLine();
                Console.WriteLine("Modem Information:");
                Console.WriteLine("  Manufacturer: " + gateway.getManufacturer());
                Console.WriteLine("  Model: " + gateway.getModel());
                Console.WriteLine("  Serial No: " + gateway.getSerialNo());
                Console.WriteLine("  SIM IMSI: " + gateway.getImsi());
                Console.WriteLine("  Signal Level: " + gateway.getSignalLevel() + "dBm");
                Console.WriteLine("  Battery Level: " + gateway.getBatteryLevel() + "%");
                Console.WriteLine();

                // Send one message.
                // Remember to change the recipient!
                OutboundMessage msg = new OutboundMessage("+3069...", "Hello from SMSLib for .NET");
                srv.sendMessage(msg);
                Console.WriteLine(msg);

                // Send more than one message at once.
                //OutboundMessage[] msgArray = new OutboundMessage[2];
                //msgArray[0] = new OutboundMessage("+306948494037", "Hello from SMSLib for .NET (#1)");
                //msgArray[1] = new OutboundMessage("+306948494037", "Hello from SMSLib for .NET (#2)");
                //srv.sendMessages(msgArray);
                //Console.WriteLine(msgArray[0]);
                //Console.WriteLine(msgArray[1]);

                Console.WriteLine("Press <ENTER> to terminate...");
                Console.In.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                com1.Stop();
                srv.stopService();
            }
        }
Пример #12
0
        public void DoIt()
        {
            // Create new Service object - the parent of all and the main interface to you.

            srv = Service.getInstance();

            // *** The tricky part ***
            // *** Comm2IP Driver ***
            // Create (and start!) as many Comm2IP threads as the modems you are using.
            // Be careful about the mappings - use the same mapping in the Gateway definition.
            Comm2IP.Comm2IP com1 = new Comm2IP.Comm2IP(new byte[] { 127, 0, 0, 1 }, 12000, "com20", 115200);

            try
            {
                //Console.WriteLine("");
                Console.WriteLine("Library Version: " + Library.getLibraryVersion());
                Console.WriteLine("Please wait while server is initialising...");
                // Start the COM listening thread.
                new Thread(new ThreadStart(com1.Run)).Start();
                Console.Write("||");
                // Lets set some callbacks.
                srv.setInboundMessageNotification(new InboundNotification());
                Console.Write("||");
                //srv.setOutboundMessageNotification(new OutboundNotfication());
                Console.Write("||");
                //srv.setCallNotification(new CallNotification());
                srv.setGatewayStatusNotification(new GatewayStatusNotification());
                Console.Write("||");

                // Create the Gateway representing the serial GSM modem.
                // Due to the Comm2IP bridge, in SMSLib for .NET all modems are considered IP modems.
                IPModemGateway gateway = new IPModemGateway("modem.com20", "127.0.0.1", 12000, "Huawei", "E220");
                Console.Write("||");
                gateway.setIpProtocol(ModemGateway.IPProtocols.BINARY);
                Console.Write("||");
                // Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
                gateway.setProtocol(AGateway.Protocols.PDU);
                Console.Write("||");
                // Do we want the Gateway to be used for Inbound messages?
                gateway.setInbound(true);
                Console.Write("||");
                // Do we want the Gateway to be used for Outbound messages?
                gateway.setOutbound(true);

                Console.Write("||");
                // Let SMSLib know which is the SIM PIN.
                gateway.setSimPin("0000");
                Console.Write("||");
                //This Smsc number is of warid. Adjust accordingly
                //only use for sms sending pourose.
                gateway.setSmscNumber("+923210006001");
                Console.Write("||");
                // Add the Gateway to the Service object.
                srv.addGateway(gateway);
                Console.Write("||");
                // Similarly, you may define as many Gateway objects, representing
                // various GSM modems, add them in the Service object and control all of them.
                Console.Write("||");
                // Start! (i.e. connect to all defined Gateways)
                srv.startService();
                Console.WriteLine();
                Console.WriteLine("Modem Information:");
                Console.WriteLine("  Manufacturer: " + gateway.getManufacturer());
                Console.WriteLine("  Model: " + gateway.getModel());
                Console.WriteLine("  Serial No: " + gateway.getSerialNo());
                Console.WriteLine("  SIM IMSI: " + gateway.getImsi());
                Console.WriteLine("  Signal Level: " + gateway.getSignalLevel() + "dBm");
                Console.WriteLine("  Battery Level: " + gateway.getBatteryLevel() + "%");

                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate...");
                Console.In.ReadLine();
            }
            catch (Exception e)
            {
            Console.WriteLine("Some thing went wrong here");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                com1.Stop();
                srv.stopService();
            }
        }
Пример #13
0
		static void Main(string[] args)
		{
			// Create new Service object - the parent of all and the main interface to you.
			Service srv;
			srv = Service.getInstance();

			// *** The tricky part ***
			// *** Comm2IP Driver ***
			// Create (and start!) as many Comm2IP threads as the modems you are using.
			// Be careful about the mappings - use the same mapping in the Gateway definition.
			Comm2IP.Comm2IP com1 = new Comm2IP.Comm2IP(new byte[] { 127, 0, 0, 1 }, 12000, "com4", 115200);

			try
			{
				Console.WriteLine("Example: Read messages from a serial gsm modem.");
				Console.WriteLine(Library.getLibraryDescription());
				Console.WriteLine("Version: " + Library.getLibraryVersion());

				// Start the COM listening thread.
				new Thread(new ThreadStart(com1.Run)).Start();

				// Lets set some callbacks.
				srv.setInboundMessageNotification(new InboundNotification());
				srv.setCallNotification(new CallNotification());
				srv.setGatewayStatusNotification(new GatewayStatusNotification());

				// Create the Gateway representing the serial GSM modem.
				// Due to the Comm2IP bridge, in SMSLib for .NET all modems are considered IP modems.
				IPModemGateway gateway = new IPModemGateway("modem.com4", "127.0.0.1", 12000, "Huawei", "E220");
				gateway.setIpProtocol(ModemGateway.IPProtocols.BINARY);

				// Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
				gateway.setProtocol(AGateway.Protocols.PDU);

				// Do we want the Gateway to be used for Inbound messages?
				gateway.setInbound(true);

				// Do we want the Gateway to be used for Outbound messages?
				gateway.setOutbound(true);

				// Let SMSLib know which is the SIM PIN.
				gateway.setSimPin("0000");

				// Explicit SMSC address set is required for some modems.
				// Below is for VODAFONE GREECE - be sure to set your own!
				gateway.setSmscNumber("+306942190000");

				// Add the Gateway to the Service object.
				srv.addGateway(gateway);

				// Similarly, you may define as many Gateway objects, representing
				// various GSM modems, add them in the Service object and control all of them.

				// Start! (i.e. connect to all defined Gateways)
				srv.startService();

				// Printout some general information about the modem.
				Console.WriteLine();
				Console.WriteLine("Modem Information:");
				Console.WriteLine("  Manufacturer: " + gateway.getManufacturer());
				Console.WriteLine("  Model: " + gateway.getModel());
				Console.WriteLine("  Serial No: " + gateway.getSerialNo());
				Console.WriteLine("  SIM IMSI: " + gateway.getImsi());
				Console.WriteLine("  Signal Level: " + gateway.getSignalLevel() + "dBm");
				Console.WriteLine("  Battery Level: " + gateway.getBatteryLevel() + "%");
				Console.WriteLine();

				// Send one message.
				// Remember to change the recipient!
				OutboundMessage msg = new OutboundMessage("+3069...", "Hello from SMSLib for .NET");
				srv.sendMessage(msg);
				Console.WriteLine(msg);

				// Send more than one message at once.
				//OutboundMessage[] msgArray = new OutboundMessage[2];
				//msgArray[0] = new OutboundMessage("+306948494037", "Hello from SMSLib for .NET (#1)");
				//msgArray[1] = new OutboundMessage("+306948494037", "Hello from SMSLib for .NET (#2)");
				//srv.sendMessages(msgArray);
				//Console.WriteLine(msgArray[0]);
				//Console.WriteLine(msgArray[1]);

				Console.WriteLine("Press <ENTER> to terminate...");
				Console.In.ReadLine();
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				Console.WriteLine(e.StackTrace);
			}
			finally
			{
				com1.Stop();
				srv.stopService();
			}
		}