java socket小白问题

2025-05-14 14:54:54
推荐回答(3个)
回答1:

String line;
BufferedReader is = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
PrintWriter os = new PrintWriter(socket.getOutputStream());
BufferedReader sin = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Client:" + is.readLine());
line = sin.readLine();
while (!line.equals("bye"))
{
os.println(line);
os.flush();
System.out.println("Server:" + line);
System.out.println("Client:" + is.readLine());
line = sin.readLine();
}

用 System.in 创建输入流 new InputStreamReader(System.in)

回答2:

有什么问题说一下

回答3:

具体是什么问题