java IOUtils复制和写入问题
我试图从客户端向服务器发送字符串,但它似乎没有从输入流中读取
客户
Scanner scanner = new Scanner(System.in);
Socket connection = new Socket("localhost", 13)
OutputStream out = connection.getOutputStream();
while(true) {
String message = scanner.nextLine();
IOUtils.write(message, out, "UTF-8");
out.flush();
}
服务器
ServerSocket server = new ServerSocket(localhost,13);~
Socket connection = server.accept();
InputStream in = connection.getInputStream();
StringWriter writer = new StringWriter();
while(true) {
try {
IOUtils.copy(in, writer);
System.out.println(writer.toString());
} catch(IOException io) {}
}
如果我从客户机的outputstream关闭流,但我试图从客户机向服务器发送多条消息,它就会读取。有人能帮忙吗
共 (0) 个答案