//发送信息 @Test public void test_002() throws UnknownHostException, IOException, InterruptedException{ Socket server=new Socket("localhost", 8020); OutputStream out=server.getOutputStream(); PrintWriter writer = new PrintWriter(out); String sendMsg="helloworld"; writer.write(sendMsg ); writer.flush(); Thread.sleep(5000);//报错socket不关闭 } //接收信息 InputStream ins = server2.getInputStream(); String message = SocketHWUtil.readSocket(ins); if (!ValueWidget.isNullOrEmpty(message)) { System.out.println("接收的信息:" + message); } ———————————————— 版权声明:本文为CSDN博主「仅此而已丶」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_32343577/article/details/81632691