创建客户端套接字
import java.io.IOException;//来自 时 代 J a v a - N o w J a v a . c o m import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; public class Main { public static void main(String[] args) { // Create a socket without a timeout try { InetAddress addr = InetAddress.getByName("java.sun.com"); int port = 80; // This constructor will block until the connection succeeds Socket socket = new Socket(addr, port); }