Пример #1
0
        /// <summary>
        /// 读取服务端地址配置
        /// 默认空值:Path.Combine("Config", "Server.cfg")
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static List <NettyAddress> ReaderSrvFile(string path = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = Path.Combine("Config", "Server.cfg");
            }
            List <NettyAddress> LstAddres = new List <NettyAddress>();

            if (!File.Exists(path))
            {
                return(LstAddres);
            }
            using (StreamReader rd = new StreamReader(path))
            {
                string line = rd.ReadLine();
                if (!string.IsNullOrEmpty(line))
                {
                    try
                    {
                        //处理地址格式;默认只能是端口
                        string[]     info    = line.Split('=', ':');
                        NettyAddress address = new NettyAddress();
                        if (info.Length == 1)
                        {
                            address.Port = int.Parse(info[0].Trim());
                        }
                        else if (info.Length == 2)
                        {
                            //2类
                            if (line.Contains(":"))
                            {
                                //说明是IP+端口
                                address.Host = info[0].Trim();
                                address.Port = int.Parse(info[1].Trim());
                            }
                            else
                            {
                                address.Flage = info[0].Trim();
                                address.Port  = int.Parse(info[1].Trim());
                            }
                        }
                        else if (info.Length == 3)
                        {
                            address.Flage = info[0].Trim();
                            address.Host  = info[1].Trim();
                            address.Port  = int.Parse(info[2].Trim());
                        }

                        LstAddres.Add(address);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            return(LstAddres);
        }
Пример #2
0
        public NettySrvManager()
        {
            NettyAddress address = new NettyAddress()
            {
                Port = 7777
            };

            SrvAddress.Add(address);
        }
Пример #3
0
        /// <summary>
        /// 获取服务端地址
        /// </summary>
        /// <param name="lst"></param>
        /// <returns></returns>
        public static List <NettyAddress> ReaderSrv(List <string> lst)
        {
            List <NettyAddress> LstAddres = new List <NettyAddress>();

            if (lst == null || lst.Count == 0)
            {
                return(LstAddres);
            }
            foreach (var item in lst)
            {
                if (!string.IsNullOrEmpty(item))
                {
                    try
                    {
                        //处理地址格式;默认只能是端口
                        string[]     info    = item.Split('=', ':');
                        NettyAddress address = new NettyAddress();
                        if (info.Length == 1)
                        {
                            address.Port = int.Parse(info[0].Trim());
                        }
                        else if (info.Length == 2)
                        {
                            //2类
                            if (item.Contains(":"))
                            {
                                //说明是IP+端口
                                address.Host = info[0].Trim();
                                address.Port = int.Parse(info[1].Trim());
                            }
                            else
                            {
                                address.Host = info[0].Trim();
                                address.Port = int.Parse(info[1].Trim());
                            }
                        }
                        else if (info.Length == 3)
                        {
                            address.Flage = info[0].Trim();
                            address.Host  = info[1].Trim();
                            address.Port  = int.Parse(info[2].Trim());
                        }

                        LstAddres.Add(address);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            return(LstAddres);
        }