Пример #1
0
        internal void Start()
        {
            try
            {
                _serverSocket.Start();
                IsRunning = true;

                Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.NetworkServerStarted, _listenPort);
            }
            catch (SocketException ex)
            {
                Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.NetworkSocketError, ex);
                Logger.Instance.LogException(this, ex);
            }

            if (IsRunning)
            {
                try
                {
                    while (true)
                    {
                        _clientSocket = _serverSocket.AcceptTcpClient();
                        HandleAlarmClient.StartClient(_clientSocket, _parent);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.NetworkError, ex);
                    Logger.Instance.LogException(this, ex);
                }
            }
        }
Пример #2
0
        internal static void StartClient(TcpClient clientSocket, NetworkAlarmSource parent)
        {
            if (clientSocket == null)
            {
                throw new ArgumentNullException("clientSocket");
            }
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            HandleAlarmClient handleAlarmClient = new HandleAlarmClient
            {
                _clientSocket = clientSocket,
                _parent       = parent
            };

            Thread ctThread = new Thread(handleAlarmClient.ReceiveThread)
            {
                Name         = Properties.Resources.NetworkAlarmClientThreadName,
                Priority     = ThreadPriority.BelowNormal,
                IsBackground = true
            };

            ctThread.Start();
        }