client_thread.java.svn-base
资源名称:QQ.rar [点击查看]
上传用户:hongdaled
上传日期:2007-10-03
资源大小:680k
文件大小:1k
源码类别:
ICQ/即时通讯
开发平台:
Java
- package server;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- public class client_thread extends Thread{
- ObjectOutputStream dos;
- //去往客户的输出流
- ObjectInputStream din;
- //来自客户的输入流
- HashMap set=new HashMap();
- public client_thread(ObjectOutputStream dos, ObjectInputStream din)
- {
- this.dos=dos;
- this.din=din;
- }
- public void run() {
- //循环读取客户数据转发给其他客户
- while(true) {
- try{
- Object message=din.readObject();
- qq_user user =(qq_user)message;
- set.put(user.name, user);
- while(message!=null){
- message=din.readObject();
- //读客户数据,无数据时线程将挂起
- user =(qq_user)message;
- set.put(user.name, user);
- }
- for(int j=0;j<serverthread.l.size();j++) {
- client_thread c=(client_thread)serverthread.l.get(j);
- c.dos.writeObject(set);
- //转发给其他客户
- }
- this.sleep(1000);
- }
- catch(IOException e)
- {
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }