serverthread.java.svn-base
资源名称:QQ.rar [点击查看]
上传用户:hongdaled
上传日期:2007-10-03
资源大小:680k
文件大小:2k
源码类别:
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.Properties;
- public class serverthread extends Thread{
- public static ArrayList l=new ArrayList();
- //存放所有通信线程
- public static int clientnum=0;
- public void run()
- {
- try {
- ServerSocket s = new ServerSocket(9999);
- System.out.println("nnnnnnnnnnnnnnsddddddd");
- System.out.println("nnnnnnnnnnnnnnsddddddd");
- while (true) {
- Socket s1=s.accept();
- //等待客户连接
- System.out.println("nnnnnnnnnnnnnnsddddddd");
- ObjectOutputStream oos=new ObjectOutputStream(s1.getOutputStream());
- // ObjectInputStream ois2 =new ObjectInputStream(s3.getInputStream());
- ObjectInputStream ois =new ObjectInputStream(new FileInputStream("d:\user_info.txt"));
- ObjectOutputStream oos1=new ObjectOutputStream(new FileOutputStream("d:\user_info.txt"));
- DataOutputStream dos = new DataOutputStream(s1.getOutputStream());
- DataInputStream din = new DataInputStream(s1.getInputStream());
- // ObjectOutputStream oos1=new ObjectOutputStream(s1.getOutputStream());
- System.out.println("nnnnnnnnnnnnnnsddddddd");
- client c=new client(clientnum,dos,din);
- l.add(c);
- //创建与客户对应的通信线程
- c.start();
- clientnum++;
- client_thread a = new client_thread(oos,ois);
- a.start();
- }
- }
- catch (IOException e)
- {
- }
- }
- }