首页 新闻 会员 周边 捐助

c#socket连接报错:内容中所要求的地址不正确

0
[已解决问题] 解决于 2017-11-13 20:05

完整代码:

    public class SocketTest
    {
        private static byte[] result = new byte[1024];
        private static int myProt = 443;   //端口  443
        static Socket serverSocket;
        public string url = "www.paypal.com"; //www.paypal.com
        public void Start()
        {
            //服务器IP地址  
            serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPHostEntry hostInfo = Dns.GetHostEntry(url);
            IPAddress ipAddress = hostInfo.AddressList[0];
            IPEndPoint ippoint = new IPEndPoint(ipAddress, myProt);
            serverSocket.Bind(ippoint);


            Console.Write("Beginning Asynchronous call");
            IAsyncResult asyncConnect = serverSocket.BeginConnect(
                                            ippoint,
                                            new AsyncCallback(connectCallback),
                                            serverSocket);
            Console.Write("Connection in progress.");
            Console.ReadLine();
        }

        private void connectCallback(IAsyncResult ar)
        {
            Console.Write("Connection Callback.");
        }
    }
View Code

错误行:

serverSocket.Bind(ippoint);

错误提示:

Error:-2147467259-内容中所要求的地址不正确。
HotSky的主页 HotSky | 菜鸟二级 | 园豆:223
提问于:2017-11-13 18:26
< >
分享
最佳答案
0

你bind是bind本地ip和port,你bind别人家的ip算什么事?

奖励园豆:5
Daniel Cai | 专家六级 |园豆:10424 | 2017-11-13 18:48
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册