public class SentClientThread extends Thread { private PrintWriter printWriter; public SentClientThread(PrintWriter printWriter){ this.printWriter=printWriter; } public void run(){ try{ Scanner scanner = new Scanner(System.in); while (true){ String message=scanner.nextLine(); sentMessage(printWriter,message); } }catch (Exception e){ e.printStackTrace(); } } /** * 发送信息 * @param printWriter * @param message */ public void sentMessage(PrintWriter printWriter,String message){ printWriter.println(message); printWriter.flush(); } }
参考链接:https://blog.csdn.net/BlueSky_USC/article/details/54414860