摘 要:本軟件的目的是要求解決傳統的基于C/S模式的即時通信軟件過分依賴于中心節點的性能的問題,基于P2P模式的即時通信軟件可以有效地解決這些問題。本軟件采用Java的基于P2P的Jxta網絡框架,軟件用IMbean鏈接GUI圖形界面的開發方式,并實現了多個Peer節點之間的信息收發。
關鍵詞:即時通信軟件; P2P模式; Jxta; Java
中圖分類號:TN87+; TP311 文獻標識碼:A 文章編號:1004-373X(2010)14-0136-04
Java Realization of P2P Instant Messaging Software Based on Jxta
QING Lin
(Hunan Normal University, Changsha 410006,China)
Abstract: The purpose of this software is to figure out the problem that the common instant message software mostly depended on the ability of the centre pole. The software is based on the frame of JXTA of the JAVA, and uses the development method of linking GUI with IMbean, achieves the posting of messages between every Peer.
Keywords: instant messaging software; P2P; Jxta; Java
P2P技術是目前非常流行的一種分布式計算技術,P2P網絡的基礎單位是對等點,每個對等點之間能夠互訪。SUN公司針對P2P技術的特點提出了自己關于P2P網絡的Jxta研究項目,本文設計的即時通信軟件便是基于該技術來開發的。
1 軟件實現
1.1 系統架構
Jxta P2P applications即本文所設計的軟件是建立在JavaBean上的,JavaBean是一種類,它針對特定的用途封裝了屬性和方法[1],實現特定的用途,而下面的JAL是Java的抽象層,它直接隔開了Jxta的平臺,為上層的程序管理Jxta的對等體,廣告,管道以及其他各種底層的實現和細節[2]。
1.2 總體設計步驟和方法
總體設計步驟和方法[3]如下:
(1) 設計JAL;
(2) 設計本軟件的中的JavaBean,即IMbean;
(3) 創建應用程序VSJChat的GUI圖形界面;
(4) 鏈接IMbean和應用程序GUI,以實現功能[4]。
1.3 設計JAL的Peer接口
JAL實際上也是API即引用程序接口,實現以下功能:
(1) 發現Peer同時能被發現;
(2) 搜索其他Peer和Peer群;
(3) 創建和管理Peer群;
(4) 和其他Peer的交流;
(5) 獲得其他Peer或者Peer群的信息[5]。
Peer接口設計程序如下所示:
public interface Peer{ //開始
public void boot(String name)
throws Exception;
public void boot(String name,
String group)throws Exceptio
//申明可用性
public void publish()
throws Exception; //Peer信息
public String getName();
public String[]getPeers()
throws Exception; //發送和接收信息
public boolean sendMessage(
String name,Message msg)
throws Exception;
public boolean broadcast
(Messagemsg)throws Exception
public Message receiveMessage()
throws Exception; //信息處理
public Message newMessage();
public void pushObject(Message m
String tag,Object obj)
throws Exception;
public Object popObject(
Message msg,String tag)
throws Exception; //群處理
public void createGroup(
String name)throws Exceptio
public void joinGroup(String name
throws Exception;
public String[]getGroups()
throws Exception;
public void createAndOrJoinGroup
String name)throws Exceptio
public void leaveGroup(String nam
throws Exception;
//信息效用
public boolean
searchGroupWithName(String name)
throws Exceptio
public boolean
searchPeerWithName(String n
throws Exception;
public void displayPeers()
throws Exception;
public void displayGroups()
throws Exception;
public void displayServices()
throws Exception;
public String getPeerStatistics();
}
1.4 IMbean的設計
IMBean是在JAL基礎上開發的一個應用JavaBean。它的作用是:處理所有的Jxta細節問題(包括初始化Peer,異常處理)[6];處理輸入信息,傳輸到VSJChat;處理輸出信息,通過Jxta網絡發送。……