/// <summary> /// Background thread. /// </summary> public void Run() { EncogLogging.Log(EncogLogging.LevelDebug, "Waiting for packets"); try { while (!_done) { IndicatorPacket packet = Link.ReadPacket(); // really do not care if we timeout, just keep listening if (packet == null) { continue; } if (string.Compare(packet.Command, IndicatorLink.PacketHello, true) == 0) { RemoteType = packet.Args[0]; IndicatorName = packet.Args[1]; _listener = _server .ResolveIndicator(IndicatorName); _listener.NotifyConnect(Link); } else if (string.Compare(packet.Command, IndicatorLink.PacketGoodbye, true) == 0) { _done = true; } else { _listener.NotifyPacket(packet); } } } catch (IndicatorError ex) { EncogLogging.Log(EncogLogging.LevelDebug, "Client ended connection:" + ex.Message); _done = true; } catch (Exception t) { EncogLogging.Log(EncogLogging.LevelCritical, t); } finally { _done = true; _server.Connections.Remove(this); if (_listener != null) { _listener.NotifyTermination(); } _server.NotifyListenersConnections(Link, false); EncogLogging.Log(EncogLogging.LevelDebug, "Shutting down client handler"); Link.Close(); } }
/// <summary> /// Background thread. /// </summary> public void run() { EncogLogging.Log(EncogLogging.LogLevel.Debug, "Waiting for packets"); try { while (!done) { IndicatorPacket packet = Link.ReadPacket(); // really do not care if we timeout, just keep listening if (packet == null) { continue; } else { if (string.Compare(packet.Command, IndicatorLink.PACKET_HELLO, true) == 0) { RemoteType = packet.Args[0]; IndicatorName = packet.Args[1]; this.listener = this.server .ResolveIndicator(IndicatorName); this.listener.NotifyConnect(Link); } else if (string.Compare(packet.Command, IndicatorLink.PACKET_GOODBYE, true) == 0) { this.done = true; } else { this.listener.NotifyPacket(packet); } } } } catch (IndicatorError ex) { if (ex.GetBaseException() == null) { EncogLogging.Log(EncogLogging.LogLevel.Debug, "Error, ending connection:" + ex.Message); String[] args = { ex.Message }; Link.WritePacket("error", args); } else { EncogLogging.Log(EncogLogging.LogLevel.Debug, "Client ended connection:" + ex.Message); } this.done = true; } catch (Exception t) { EncogLogging.Log(EncogLogging.LogLevel.Critical, t); } finally { this.done = true; this.server.Connections.Remove(this); if (this.listener != null) { this.listener.NotifyTermination(); } this.server.NotifyListenersConnections(Link, false); EncogLogging.Log(EncogLogging.LogLevel.Debug, "Shutting down client handler"); Link.Close(); } }