我使用网络调试助手的服务器端来调试程序,比如我的ip是192.168.1.6吧,我的客户端程序和网络调试助手在同一台电脑上,我用程序请求连接127.0.0.1的1000,奇怪的是,如果网络调试助手监听127.0.0.1:1000就可以连接得上,但是监听192.168.1.6:1000却连接不上

解决方案 »

  1.   


    不是这样。
    同一台机子可以有多个IP地址,程序监听哪个IP就监听哪个IP,不认机子。
      

  2.   

    可以让程序自动获取本机IP地址(不包含回环地址127)using System.Net;        IPAddress[] aryLocalAddr = null;
            string strHostName = "";            try
                {
                    strHostName = Dns.GetHostName();
                    IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
                    aryLocalAddr = ipEntry.AddressList;
                }
                catch { }