yanzheng_qq.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.FileInputStream;
- 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.HashMap;
- import client.qq_user;
- public class yanzheng_qq extends Thread{
- PrintStream dos;
- //去往客户的输出流
- ObjectInputStream din;
- ServerSocket ss;
- //来自客户的输入流
- BufferedReader br;
- HashMap set=new HashMap();
- public yanzheng_qq()
- {
- }
- public void run() {
- //循环读取客户数据转发给其他客户
- try {
- ss = new ServerSocket(5555);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- while(true) {
- Socket s3;
- try{
- s3=ss.accept();
- din =new ObjectInputStream(new FileInputStream("c:\user_info.txt"));
- dos=new PrintStream(s3.getOutputStream());
- br=new BufferedReader(new InputStreamReader(s3.getInputStream()));
- Object message=din.readObject();
- qq_user user =(qq_user)message;
- set.put(user.name, user);
- while(message!=null){
- message=din.readObject();
- //读客户数据,无数据时线程将挂起
- user =(qq_user)message;
- set.put(user.name, user);
- }
- //Object[] arr=set.keySet().toArray();
- boolean f;
- System.out.println("bing");
- String name=br.readLine();
- String paw=br.readLine();
- if(set.get(name)!=null){
- dos.println(9999);
- }
- else{
- dos.println(0000);
- }
- br.close();
- }
- catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }