import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class TcpInput {
public static void main(String[] args) throws IOException {
ServerSocket socket = new ServerSocket(10086);
Socket accept = socket.accept();
InputStream input = accept.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line = reader.readLine();
System.out.println(line);
OutputStream out = accept.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
writer.write("敢骂我,你死定了,我是服务器");
writer.close();
out.close();
reader.close();
input.close();
accept.close();
socket.close();
}
}
import java.io.*;
import java.net.Socket;
public class TcpOut {
public static void main(String[] args) throws IOException {
Socket socket = new Socket("127.0.0.1", 10086);
OutputStream out = socket.getOutputStream();
byte[] bytes = "你好啊,我是服务器,大傻逼".getBytes();
out.write(bytes);
socket.shutdownOutput();
InputStream input = socket.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line = reader.readLine();
System.out.println(line);
reader.close();
input.close();
out.close();
socket.close();
}
}