client_zhuce.java.svn-base
资源名称:QQ.rar [点击查看]
上传用户:hongdaled
上传日期:2007-10-03
资源大小:680k
文件大小:2k
源码类别:
ICQ/即时通讯
开发平台:
Java
- package server;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.util.HashMap;
- public class client_zhuce extends Thread{
- ObjectInputStream dos;
- //去往客户的输出流
- ObjectInputStream din;
- ServerSocket ss;
- //来自客户的输入流
- ObjectOutputStream oos;
- HashMap set=new HashMap();
- public client_zhuce()
- {
- }
- public void run() {
- //循环读取客户数据转发给其他客户
- ObjectInputStream ois;
- Socket s2;
- try {
- this.din = new ObjectInputStream(new FileInputStream("c:\user_info.txt"));
- this.oos=new ObjectOutputStream(new FileOutputStream("c:\user_info.txt"));
- this.ss=new ServerSocket(8888);
- s2=ss.accept();
- this.dos =new ObjectInputStream(s2.getInputStream());
- } catch (FileNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- while(true) {
- try{
- Object message=din.readObject();
- qq_user user;
- while(message!=null){
- user =(qq_user)message;
- set.put(user.name, user);
- message=din.readObject();
- //读客户数据,无数据时线程将挂起
- }
- Object oo=dos.readObject();
- user=(qq_user)oo;
- set.put(user.name, user);
- Object[] arr=set.keySet().toArray();
- for(int j=0;j<arr.length;j++){
- oos.writeObject(set.get(arr[j]));
- }
- }
- catch(IOException e)
- {
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }