1.导入包
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
2.ping IP
ping book.zongheng.com
3.使用ping到的IP建立Socket链接,端口默认80(百度网站一般都是80端口)
public class SocketL {
private Socket socket;
public void start() {
try {
Socket socket = new Socket("book.zongheng.com", 80);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new SocketL().start();
}
}
4.获取输出流发送请求
public void start(