client.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.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.util.Date;
- import java.util.Properties;
- class client extends Thread {
- int id;
- DataOutputStream dos;
- //去往客户的输出流
- DataInputStream din;
- //来自客户的输入流
- public client(int id,DataOutputStream dos, DataInputStream din)
- {
- this.id=id;
- this.dos=dos;
- this.din=din;
- }
- public void run() {
- //循环读取客户数据转发给其他客户
- while(true) {
- try{
- String message=din.readUTF();
- //读客户数据,无数据时线程将挂起
- int m=serverthread.clientnum;
- for(int j=0;j<serverthread.l.size();j++) {
- client c=(client)serverthread.l.get(j);
- c.dos.writeUTF("client "+(new Date()).toString()+":"+message);
- //转发给其他客户
- }
- }
- catch(IOException e)
- {
- }
- }
- }
- }