public class TcpClientDemo {
public static void main(String[] args) throws IOException {
InetAddress inetAddress = InetAddress.getByName("127.0.0.1");
int port = 88;
Socket socket = new Socket(inetAddress,port);
OutputStream outputStream = socket.getOutputStream();
outputStream.write("你好哈哈哈".getBytes());
}
}
public class TcpServerDemo {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(88);
Socket socket = serverSocket.accept();
InputStream inputStream = socket.getInputStream();
byte[] bytes = new byte[1024];
int len;
while ((len=inputStream.read(bytes))!=-1){
System.out.println(new String(bytes,0,len));
}
}
}