描述记录当前系统日志的目标Cat服务器
Ejemplo n.º 1
0
        private IEnumerable<Server> BuildServers(XmlNodeList nodes)
        {
            List<Server> servers = new List<Server>();

            if (nodes != null && nodes.Count > 0)
            {
                XmlElement first = (XmlElement)nodes[0];
                XmlNodeList serverNodes = first.GetElementsByTagName("server");

                foreach (XmlNode node in serverNodes)
                {
                    XmlElement serverNode = (XmlElement)node;
                    var ip = GetStringProperty(serverNode, "ip", "localhost");
                    var port = GetIntProperty(serverNode, "port", 2280);
                    var httpport = GetIntProperty(serverNode, "http-port", 8080);
                    var enabled = GetBooleanProperty(serverNode, "enabled", true);

                    var server = new Server(ip, port, httpport, enabled);

                    servers.Add(server);
                }
            }

            if (servers.Count == 0)
            {
                Logger.Warn("No server configured, use localhost:2280 instead.");
                servers.Add(new Server("localhost", 2280));
            }

            return servers;
        }
Ejemplo n.º 2
0
        private TcpClient CreateChannel(Server server)
        {
            if (!server.Enabled)
            {
                return null;
            }

            var socket = new TcpClient() { NoDelay = true, ReceiveTimeout = 2000 };

            var ip = server.Ip;
            var port = server.Port;

            Logger.Info("Connecting to server({0}:{1}) ...", ip, port);

            try
            {
                socket.Connect(ip, port);

                if (socket.Connected)
                {
                    Logger.Info("Connected to server({0}:{1}).", ip, port);

                    return socket;
                }
                Logger.Error("Failed to connect to server({0}:{1}).", ip, port);
            }
            catch (Exception e)
            {
                Logger.Error("Failed to connect to server({0}:{1}). Error: {2}.", ip, port, e.Message);
            }

            return null;
        }