예제 #1
0
 public void Stop()
 {
     if (pSockObj != null)
     {
         pSockObj.Stop();
         pSockObj = null;
         _running = false;
     }
 }
예제 #2
0
        protected void StartSocket(ISocketListener pSock, int nPort)
        {
            // start an instance of socket server locally
            Thread t = new Thread(() => pSock.Start(nPort));

            t.IsBackground = true;
            t.Start();

            Thread.Sleep(200);  // add some lead time to let socket server started
        }
예제 #3
0
        private void Start()
        {
            int nPort = 0;

            try
            {
                string sModel = ConfigurationManager.AppSettings["model"];
                string sPort  = ConfigurationManager.AppSettings["port"];

                if (Int32.TryParse(sPort, out nPort))
                {
                    // Socket factory to determine which listener we want to open/read
                    switch (sModel)
                    {
                    case DeviceModels.Device:
                        pSockObj = Listener_Device.Instance;
                        break;

                    default:
                        pSockObj = null;
                        break;
                    }

                    // start listening service on the particular device models
                    if (pSockObj != null)
                    {
                        _running = true;
                        pSockObj.Start(nPort);      // blocking call!
                    }
                    else
                    {
                        LogManager.LogErrorLine("Unable to find Socket Instance");
                    }
                }
                else
                {
                    LogManager.LogErrorLine("Unable to read port number");
                }
            }
            catch (Exception ex)
            {
                LogManager.LogErrorLine("SocketEngine.Start - Exception: {0}", ex.Message);
            }
        }
예제 #4
0
 protected void StopSocket(ISocketListener pSock)
 {
     pSock.Stop();
     Thread.Sleep(800);  // add some lead time to let socket server stopped
 }