完整代码:
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."); } }
错误行:
serverSocket.Bind(ippoint);
错误提示:
你bind是bind本地ip和port,你bind别人家的ip算什么事?