• 聊天室实现--客户端发送信息线程实现


    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

  • 相关阅读:
    开启Spring Boot 之旅
    Java笔试面试练习题---集合
    Python
    Python
    Redis -下载与基本使用
    Git
    Vue全家桶-Vue-router&Vuex
    Es6
    Vue-前端
    Django基础及实战
  • 原文地址:https://www.cnblogs.com/czgxxwz/p/10290913.html
Copyright © 2020-2023  润新知