package tcp.cj;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
public class CustomCoding {
public static void main(String[] args) throws UnknownHostException, IOException{
//1.创建与服务端的连接,
Socket sc=new Socket("www.baidu.com", 8080);
InetAddress IP=InetAddress.getByName("www.baidu.com");
System.out.println("这是客户端要连接的服务端地址:"+IP);
//2数据交换
OutputStream bufout=sc.getOutputStream();
InputStream bufin=sc.getInputStream();
byte[] b=new byte[1024];
String str=new String("how do you do");
bufout.write(str.getBytes());
//读取服务端发过来的信息
int len=bufin.read(b);
System.out.println("这是来自服务端的反馈:"+new String(b,0,len));
sc.close();
}
}
用之前能不能看一下文档。
百度为什么躺枪。