Exemplo n.º 1
0
        /// <summary>
        /// 绑定服务端地址并且监听
        /// </summary>
        /// <param name="port"></param>
        /// <param name="host"></param>
        /// <returns></returns>
        public async Task <bool> BindAsync(int port, string host = null)
        {
            EndPoint endPoint = null;

            if (!string.IsNullOrEmpty(host))
            {
                endPoint = new IPEndPoint(IPAddress.Parse(host), port);
            }
            else
            {
                endPoint = new IPEndPoint(IPAddress.Any, port);
            }
            bool result = await channel.BindAsync(endPoint);

            if (result)
            {
                StartRecvice();//绑定成功就介绍
            }
            return(result);
        }