Exemplo n.º 1
0
        public UdpRealize()
        {
            string configPath = AppDomain.CurrentDomain.BaseDirectory + "Config.xml";

            if (!File.Exists(configPath))
            {
                throw new Exception("未找到配置文件!");
            }
            Config config = XmlSerializeHelper.LoadXmlToObject <Config>(configPath);

            if (config == null)
            {
                throw new Exception("配置文件格式不正确!");
            }
            clients = new List <UdpClientInfo>();
            server  = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            server.Bind(new IPEndPoint(IPAddress.Parse(config.UdpServer.Ip), config.UdpServer.Port));//绑定端口号和IP
        }
Exemplo n.º 2
0
        public LogOutPut()
        {
            string configPath = AppDomain.CurrentDomain.BaseDirectory + "LogConfig.xml";

            if (!File.Exists(configPath))
            {
                throw new Exception("未找到配置文件!");
            }
            Config config = XmlSerializeHelper.LoadXmlToObject <Config>(configPath);

            if (config == null)
            {
                throw new Exception("配置文件格式不正确!");
            }
            CanWriteLog = config.CanWriteLog;
            CanSendLog  = config.CanSendLog;
            if (client == null)
            {
                client = new UdpClient();
            }
            serverPoint = new IPEndPoint(IPAddress.Parse(config.UdpServer.Ip), config.UdpServer.Port);
        }