首页新闻招聘找找看知识库

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

0
[已解决问题]

完整代码:

    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 | 菜鸟二级 | 园豆:233
提问于:2017-11-13 18:26
< >
分享
最佳答案
0

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

奖励园豆:5
Daniel Cai | 大侠五级 |园豆:8308 | 2017-11-13 18:48
   您需要登录以后才能回答,未注册用户请先注册