serverthread.java
资源名称:QQ.rar [点击查看]
上传用户:hongdaled
上传日期:2007-10-03
资源大小:680k
文件大小:1k
源码类别:
ICQ/即时通讯
开发平台:
Java
- package client;
- import java.io.BufferedReader;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.PrintStream;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Properties;
- public class serverthread extends Thread{
- public static ArrayList l=new ArrayList();
- //存放所有通信线程
- public static HashMap map=new HashMap();
- public static int port;
- public static int clientnum=0;
- public static String name;
- public void run()
- {
- try {
- System.out.println(port+"dddddddddddddd");
- ServerSocket s = new ServerSocket(port);
- while (true) {
- Socket s1=s.accept();
- //等待客户连接
- ObjectOutputStream oos=new ObjectOutputStream(s1.getOutputStream());
- ObjectInputStream din = new ObjectInputStream(s1.getInputStream());
- client c=new client(clientnum,oos,din);
- l.add(c);
- clientnum++;
- //创建与客户对应的通信线程
- c.start();
- }
- }
- catch (IOException e)
- {
- }
- }
- }