serverthread.java.svn-base
上传用户:hongdaled
上传日期:2007-10-03
资源大小:680k
文件大小:2k
源码类别:

ICQ/即时通讯

开发平台:

Java

  1. package server;
  2. import java.io.BufferedReader;
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.File;
  6. import java.io.FileInputStream;
  7. import java.io.FileOutputStream;
  8. import java.io.IOException;
  9. import java.io.InputStreamReader;
  10. import java.io.ObjectInputStream;
  11. import java.io.ObjectOutputStream;
  12. import java.io.PrintStream;
  13. import java.net.ServerSocket;
  14. import java.net.Socket;
  15. import java.util.ArrayList;
  16. import java.util.Properties;
  17. public class serverthread extends Thread{
  18.  public static ArrayList l=new ArrayList();
  19. //存放所有通信线程  
  20.  public static int clientnum=0; 
  21.   public void run()
  22.  { 
  23.    try {  
  24.   
  25.    
  26.   ServerSocket s = new ServerSocket(9999);
  27.   System.out.println("nnnnnnnnnnnnnnsddddddd");
  28.  
  29. System.out.println("nnnnnnnnnnnnnnsddddddd");
  30.     while (true) {        
  31.       Socket s1=s.accept(); 
  32.      
  33.   //等待客户连接    
  34.       
  35.       System.out.println("nnnnnnnnnnnnnnsddddddd");
  36.     
  37.       ObjectOutputStream oos=new ObjectOutputStream(s1.getOutputStream());
  38.      
  39.      // ObjectInputStream ois2 =new ObjectInputStream(s3.getInputStream());
  40.       ObjectInputStream ois =new ObjectInputStream(new FileInputStream("d:\user_info.txt"));
  41.           ObjectOutputStream oos1=new ObjectOutputStream(new FileOutputStream("d:\user_info.txt"));
  42.        DataOutputStream dos = new DataOutputStream(s1.getOutputStream());   
  43.        DataInputStream din = new DataInputStream(s1.getInputStream());
  44.     //  ObjectOutputStream oos1=new ObjectOutputStream(s1.getOutputStream());
  45.        System.out.println("nnnnnnnnnnnnnnsddddddd");
  46.  
  47.          client c=new client(clientnum,dos,din);
  48.      l.add(c);      
  49.            //创建与客户对应的通信线程    
  50.           c.start();   
  51.           
  52.           clientnum++; 
  53.         client_thread a = new client_thread(oos,ois);
  54.         a.start();
  55.         
  56.           
  57.        
  58.       
  59.  }    
  60. }  
  61. catch (IOException e) 
  62.  }
  63. }