serverthread.java
资源名称:QQ.rar [点击查看]
上传用户:hongdaled
上传日期:2007-10-03
资源大小:680k
文件大小:1k
源码类别:
ICQ/即时通讯
开发平台:
Java
- package server;
- 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 int clientnum = 0;
- public void run() {
- try {
- System.out.println("hhhhhhhhhhh");
- ServerSocket s = new ServerSocket(9999);
- while (true) {
- Socket s1 = s.accept();
- // 等待客户连接
- ObjectOutputStream oos = new ObjectOutputStream(s1
- .getOutputStream());
- // DataOutputStream dos = new
- // DataOutputStream(s1.getOutputStream());
- ObjectInputStream din = new ObjectInputStream(s1
- .getInputStream());
- System.out.println("nnnnnnnnnnnnnnsddddddd");
- client c = new client(clientnum, oos, din, s1);
- l.add(c);
- // 创建与客户对应的通信线程
- clientnum++;
- c.start();
- // client_thread a = new client_thread(oos,ois);
- // a.start();
- }
- } catch (IOException e) {
- }
- System.out.println("over");
- }
- }