資源簡介
本文討論了如何利用java技術(shù)開發(fā)聊天室系統(tǒng),基本滿足了結(jié)構(gòu)化、界面友好、速度快、安全性以及穩(wěn)定性等特點(diǎn)。
系統(tǒng)著重研究并實(shí)現(xiàn)了網(wǎng)絡(luò)應(yīng)用的部分。根據(jù)實(shí)現(xiàn)的情況看,具有較友好的聊天界面生成效果,以及流暢的網(wǎng)絡(luò)通信效果。生成的聊天室可以達(dá)到基本的聊天要求,具有較高的研究價(jià)值。
系統(tǒng)具有目前聊天室的基本功能:包括支持多種頭像,字色,語氣選擇,支持emote,支持私聊,支持在線聊友查找,支持分屏顯示,支持用戶定制自己的私人頭像,支持臟話過濾,支持嘉賓聊天。屏蔽掉自己討厭的人物,可以給所有聊友發(fā)公共信息。具有速度快,高穩(wěn)定性,占用系統(tǒng)資源少,用戶界面友好等特點(diǎn)。

代碼片段和文件信息
import?java.awt.*;
import?java.awt.event.*;
import?java.io.*;
import?java.net.*;
import?java.util.*;
import?javax.swing.*;
import?java.util.*;
/**
?*?title:?HappyChat聊天系統(tǒng)服務(wù)器程序
?*?Description:?聊天服務(wù)器
?*?Copyright:?Copyright?(c)?2006
?*?友情下載:http://www.codefans.net
?*?Filename:?AppServer.java
?*?@author?劉志成
?*?@version?1.0
?*/
//封裝登錄信息
class?Customer?implements?Serializable
{
String?custName;
String?custPassword;
}
//封裝注冊(cè)信息
class?Register_Customer?extends?object?implements?java.io.Serializable
{
?????String?custName;
?????String?custPassword;
?????String?age;
?????String?sex;
?????String?email;
}
//用于發(fā)送聊天和在線用戶的信息??
class?Message?implements?Serializable
{
?? Vector?userOnLine;
?? Vector?chat;
}
//聊天信息序列化
class?Chat?implements?Serializable
{
String??chatUser;
String??chatMessage;
String??chatToUser;
boolean?whisper;
}??
//退出信息序列化
class?Exit1?implements?Serializable
{
????String?exitname;
}
//////////*創(chuàng)建服務(wù)器*//////////
public?class?AppServer?extends?Thread
{
ServerSocket?serverSocket;
Serverframe?sframe;
static?Vector?u=new?Vector(11);
static?Vector?v=new?Vector(11);
public?AppServer()
{
? sframe=new?Serverframe();
? try
? {
serverSocket?=?new?ServerSocket(1001);
//獲取服務(wù)器的主機(jī)名和IP地址
InetAddress?address?=?InetAddress.getLocalHost();??????
??? sframe.txtServerName.setText(address.getHostName());
??? sframe.txtIP.setText(address.getHostAddress());
??? sframe.txtPort.setText(“1001“);
}
catch(IOException?e)
{
fail(e“不能啟動(dòng)服務(wù)!“);
}
sframe.txtStatus.setText(“已啟動(dòng)...“);
this.start();????//啟動(dòng)線程
}
public?static?void?fail(Exception?eString?str)
{
System.out.println(str+“?。“+e);
}
//////////*監(jiān)聽客戶的請(qǐng)求*//////////
public?void?run()
{
try
{
while(true)
{
//監(jiān)聽并接受客戶的請(qǐng)求
Socket?client?=?serverSocket.accept();
????Connection?con?=?new?Connection(clientuv);???//支持多線程
}
}
catch(IOException?e)
{
fail(e“不能監(jiān)聽!“);
}
????}
????
????
????//////////*啟動(dòng)服務(wù)器*//////////
????public?static?void?main(String?args[])
????{
???? new?AppServer();
????}
}
//////////*處理線程*//////////
class?Connection?extends?Thread
{
protected?Socket?netClient;
Vector?userOnline;
Vector?userChat;
protected?objectInputStream?fromClient;??//從客戶到服務(wù)器
protected?PrintStream?toClient;?//傳導(dǎo)客戶端
static?Vector??vList?=?new?Vector();
object?obj;
public?Connection(Socket?clientVector?uVector?c)
{
netClient?=?client;
userOnline=u;
userChat=c;
try
{
//發(fā)生雙向通信
???????????????????????????????????//檢索客戶輸入
fromClient?=?new?objectInputStream(netClient.getInputStream());
???????????????????????????????????//服務(wù)器寫到客戶
toClient?=?new?PrintStream(netClient.getOutputStream());
}
catch(IOException?e)
{
try
{
netClient.close();
}
catch(IOException?e1)
{
System.out.println(“不能建立流“+
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????1915??2007-06-05?10:21??Java聊天室程序\API_doc\private\allclasses-fr
?????文件???????1635??2007-06-05?10:21??Java聊天室程序\API_doc\private\allclasses-nofr
?????文件??????15692??2007-06-05?10:21??Java聊天室程序\API_doc\private\AppServer.html
?????文件??????12142??2007-06-05?10:21??Java聊天室程序\API_doc\private\Chat.html
?????文件???????8956??2007-06-05?10:21??Java聊天室程序\API_doc\private\ChatClient.html
?????文件??????36131??2007-06-05?10:21??Java聊天室程序\API_doc\private\ChatRoom.html
?????文件??????10345??2007-06-05?10:21??Java聊天室程序\API_doc\private\ChatRoom.Windowclose.html
?????文件???????5116??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\AppServer.html
?????文件???????6935??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\Chat.html
?????文件???????5126??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\ChatClient.html
?????文件???????5106??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\ChatRoom.html
?????文件???????5226??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\ChatRoom.Windowclose.html
?????文件???????5076??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\Clock.html
?????文件???????5126??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\Connection.html
?????文件???????6241??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\Customer.html
?????文件???????6185??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\Exit.html
?????文件???????5106??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\HeadFile.html
?????文件???????5166??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\HeadJfr
?????文件???????5076??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\Login.html
?????文件???????6185??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\Message.html
?????文件???????5106??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\Register.html
?????文件???????5196??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\Register_Customer.html
?????文件???????7488??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\Serverfr
?????文件???????5126??2007-06-05?10:21??Java聊天室程序\API_doc\private\class-use\WordFilter.html
?????文件??????33088??2007-06-05?10:21??Java聊天室程序\API_doc\private\Clock.html
?????文件??????22487??2007-06-05?10:21??Java聊天室程序\API_doc\private\Connection.html
?????文件??????11153??2007-06-05?10:21??Java聊天室程序\API_doc\private\constant-values.html
?????文件??????11040??2007-06-05?10:21??Java聊天室程序\API_doc\private\Customer.html
?????文件???????4848??2007-06-05?10:21??Java聊天室程序\API_doc\private\deprecated-list.html
?????文件??????10004??2007-06-05?10:21??Java聊天室程序\API_doc\private\Exit.html
............此處省略236個(gè)文件信息
評(píng)論
共有 條評(píng)論