/// <summary> /// Background thread. /// </summary> public void Run() { try { _running = true; _listenSocket.Listen(5); while (_running) { try { EncogLogging.Log(EncogLogging.LevelDebug, "Begin listen"); Socket connectionSocket = _listenSocket.Accept(); EncogLogging.Log(EncogLogging.LevelDebug, "Connection from: " + connectionSocket.RemoteEndPoint); var link = new IndicatorLink(this, connectionSocket); NotifyListenersConnections(link, true); var hc = new HandleClient(this, link); _connections.Add(hc); var t = new Thread(hc.Run); t.Start(); } catch (SocketException) { // just accept timing out Thread.Sleep(100); } catch (IOException ex) { throw new IndicatorError(ex); } } try { _listenSocket.Close(); } catch (IOException ex) { throw new IndicatorError(ex); } } finally { _running = false; } }
/// <summary> /// Background thread. /// </summary> public void run() { this.running = true; while (this.running) { try { EncogLogging.Log(EncogLogging.LogLevel.Debug, "Begin listen"); Socket connectionSocket = listenSocket.Accept(); EncogLogging.Log(EncogLogging.LogLevel.Debug, "Connection from: " + connectionSocket.RemoteEndPoint.ToString()); IndicatorLink link = new IndicatorLink(this, connectionSocket); NotifyListenersConnections(link, true); HandleClient hc = new HandleClient(this, link); this.connections.Add(hc); Thread t = new Thread(new ThreadStart(hc.run)); t.Start(); } catch (SocketException ex) { // ignore } catch (IOException ex) { throw new IndicatorError(ex); } } try { this.listenSocket.Close(); } catch (IOException ex) { throw new IndicatorError(ex); } }