IPEndPoint serverIPE = new IPEndPoint(IPAddress.Parse("server ip"), 80); IPEndPoint localIPE = new IPEndPoint(IPAddress.Parse("192.168.1.2"), 6639); Socket socket = new Socket(serverIPE.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socket.Bind(localIPE);//就是这句了 socket.Connect(serverIPE);
其实就是开始连接前多Bind一下,C++下也有类似绑定。