socket

   //发送信息

   @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);

       }

原文地址:https://www.cnblogs.com/jincieryi/p/9630051.html