Tcp模拟服务端通信
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(8888);
Socket s = ss.accept();
BufferedReader bd = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter pw = new PrintWriter(s.getOutputStream());
BufferedReader bdKeybd = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Client: " + bd.readLine());
String content = bdKeybd.readLine();
while (content !="bye") {
pw.println("");
pw.flush();
System.out.println("Server: " + content);
System.out.println("--------------------------------");
System.out.println("Client: " + bd.readLine());
content = bdKeybd.readLine();
}
bd.close();
pw.close();
bdKeybd.close();
s.close();
ss.close();
}