Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1 string serverIp = "59.39.71.94"; int serverProt = 80; string clientIp = "192.168.1.104"; int clientProt = 8012; var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); var ipHostEntry = Dns.GetHostEntry(serverIp); var ipEndPoint = new IPEndPoint(ipHostEntry.AddressList[0], serverProt); var address = IPAddress.Parse(clientIp); if (address != null) { var localEp = new IPEndPoint(address, clientProt); socket.Bind(localEp); } socket.Connect(ipEndPoint); //建立长连接