yanzheng_qq.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.FileInputStream;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.io.ObjectInputStream;
  9. import java.io.ObjectOutputStream;
  10. import java.io.PrintStream;
  11. import java.net.ServerSocket;
  12. import java.net.Socket;
  13. import java.util.HashMap;
  14. import client.qq_user;
  15. public class yanzheng_qq extends Thread{
  16. PrintStream  dos; 
  17. //去往客户的输出流   
  18. ObjectInputStream din; 
  19. ServerSocket ss;
  20. //来自客户的输入流   
  21. BufferedReader br;
  22. HashMap set=new HashMap();
  23. public yanzheng_qq()
  24. {   
  25.   
  26.       
  27.       
  28.          
  29.        
  30. }
  31. public void run() {
  32. //循环读取客户数据转发给其他客户  
  33.  try {
  34. ss = new ServerSocket(5555);
  35.  
  36.       
  37.         
  38.       
  39. } catch (IOException e) {
  40. // TODO Auto-generated catch block
  41. e.printStackTrace();
  42. }
  43. while(true) {    
  44. Socket s3;
  45. try{
  46. s3=ss.accept();
  47.      din =new ObjectInputStream(new FileInputStream("c:\user_info.txt"));
  48.         
  49.  dos=new PrintStream(s3.getOutputStream());
  50.       br=new BufferedReader(new InputStreamReader(s3.getInputStream()));
  51. Object message=din.readObject();  
  52. qq_user user =(qq_user)message;
  53. set.put(user.name, user);
  54. while(message!=null){
  55.     message=din.readObject();
  56. //读客户数据,无数据时线程将挂起    
  57.    user =(qq_user)message;
  58. set.put(user.name, user);
  59.    
  60. }
  61. //Object[] arr=set.keySet().toArray();
  62. boolean f;
  63.                  
  64. System.out.println("bing");
  65. String name=br.readLine();
  66. String paw=br.readLine();
  67. if(set.get(name)!=null){
  68. dos.println(9999);
  69. }
  70. else{
  71. dos.println(0000);
  72. }
  73.  br.close();
  74.         }
  75. catch (IOException e) {
  76. // TODO Auto-generated catch block
  77. e.printStackTrace();
  78. } catch (ClassNotFoundException e) {
  79. // TODO Auto-generated catch block
  80. e.printStackTrace();
  81. }
  82. }
  83. }