【文件属性】:
文件名称:用java.swing实现的聊天系统
文件大小:3KB
文件格式:RAR
更新时间:2014-01-18 08:31:38
java 图形界面 聊天 QQ swing
package com.lary.chatroom;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Collection;
import java.util.Date;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
public class ChatRoomServer {
private ServerSocket ss;
private Map onlineUsers;
public ChatRoomServer(){
try {
ss=new ServerSocket(8090);
onlineUsers=new Hashtable();
} catch (IOException e) {
e.printStackTrace();
}
}
public void startService(){
Socket s=null;
try {
while (true) {
s = ss.accept();
new ChatRoomServerThread(s).start();
}
} catch (IOException e) {
e.printStackTrace();
}
}
class ChatRoomServerThread extends Thread{
private Socket s;
private BufferedReader br;
private PrintWriter pw;
public ChatRoomServerThread(Socket s){
this.s=s;
try {
br=new BufferedReader(new InputStreamReader(s.getInputStream()));
pw=new PrintWriter(s.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
【文件预览】:
chatroom
----ChatRoomServer.java(4KB)
----ChatRoomClient.java(6KB)