⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serverthread.java~1~

📁 1. 消息即时通信 2. 消息发送实现一对一、一对多等多种发送模式 3. 发送的消息实现多彩文本编辑
💻 JAVA~1~
字号:

import java.io.*;
import java.util.*;
import java.net.*;
public class ServerThread extends Thread{
  DataOutputStream dos;
  DataInputStream dis;
  Socket socket;
  Hashtable peopleList=new Hashtable();
  public ServerThread(Socket socket,Hashtable peopleList){
    this.socket=socket;
    this.peopleList=peopleList;
    try{
      dos=new DataOutputStream(socket.getOutputStream());
      dis=new DataInputStream(socket.getInputStream());
    }catch(IOException e){
      e.printStackTrace();
    }
  }
  public void run(){
    while(true){
      String message = null;
      try {
        message = dis.readUTF();
        if(message.startsWith("LOGIN_NAME:")){
          //调用数据库函数,确认用户
          //存线程

        }
        else if(message.startsWith("PUBLICMESSAGE:")){
          //转发消息
          //String content=message.subSequence(message.indexOf(""))
          Enumeration enum=peopleList.elements();
          while(enum.hasMoreElements()){
            ((ServerThread)enum.nextElement()).dos.writeUTF(message);
          }


        }
        else if(message.startsWith("PRIVATEMESSAGE:")){

        }
        else if(message.startsWith("SEND_FILE:")){

        }
        else if(message.startsWith("AGREE_ACCEPT:")){

        }
        else if(message.startsWith("DISAGREE_ACCEPT:")){

        }
        else if(message.startsWith("PEOPLE_LEAVE:")){

        }
      }
      catch (IOException e) {

      }
    }

  }









  public static void main(String[] args) {
  }
}










⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -