局域网即时通信软件的研究与实现

时间:2022-08-16 02:38:06

局域网即时通信软件的研究与实现

摘要:即时通讯软件是在近几年在世界范围内发展起来的,它能实时的将各种形式的信息在网络之间传达。该聊天软件采用Mi- crosoft公司的SQL Server2000作为后台数据库,通过对现在流行的一些Icq的参考,建立数据库,完成信息的通讯。

关键词:网络;通讯;聊天;软件

中图分类号:TP311文献标识码:A文章编号:1009-3044(2012) 03-0579-03

1概述

当今世界正处于信息时代,计算机和通信网络是这一时代所谓“信息基础设施”。在互联网相当普及的今天,在互联网上聊天对很多“网虫”来说已经是家常便饭了。聊天室程序可以说是网上最简单的多点通信程序。一个简单的聊天室,从程序员的观点来看就是在多个I/O端点之间实现多对多的通信。

2具体实现过程分析

本系统的设计核心是Socket底层通信,基于快速稳定的Socket底层通信架构,不可以实现聊天系统,还可以实现其它的如游戏、数据采集等实时性要求较高的系统,甚至可以建立一个快速的平台服务器系统。考虑到系统的可重用性和伸缩性,需要将本系统的网络通信的应用系统分离开。

这样基于可重用的网络通信层,可以实现其他各种实时性较高的应用系统,同时,系统还需要提供一些基本功能支持。

此系统设计分为三个层次最底层是Socket通信层,将负责客户端和服务器之间的数据交换,同时通过接口层和应用层保持实时数据联系。

Socket通信机制提供了两种通讯方式:有联接和无联接方式,分别面向不同的应用需求。使用有联接方式时,通信链路提供了可靠的,全双工的字节流服务。在该方式下,通信双方必须创建一个联接过程并建立一条通讯链路,以后的网络通信操作完全在这一对进程之间进行,通信完毕关闭此联接过程。使用无联接方式时其系统开销比无联接方式小,但通信链路提供了不可靠的数据报服务,不能保证信源所传输的数据一定能够到达信宿。在该方式下,通信双方不必创建一个联接过程和建立一条通讯链路,网络通信操作在不同的主机和进程之间转发进行。

3核心代码

ChatServer.class; ClientProc.class; xccFrame.class; addFrame.class; delFrame.class; expertFram.class; helpFrame.class; aboutFrame. class;

类ChatFrame.class主要代码:

…………………………………………………………………………private JLabel welcomeInfo;

private JTextArea commonArea; //公共发言区private JTextArea myMsgArea;

private JComboBox perponsComboBox;

private JTextField inMsgField; //发言输入框

private JCheckBox privateTalk;

private boolean privateTalkFlag = false; //是否是私聊,默认值为假private JButton sentButton; //发送消息按钮

private JList peopleList;//显示进入聊天室的人名单private JButton refurbishButton;

private JMenuItem menuItem;

private JMenuItem hideMenuItem;

private BufferedReader in;

private PrintWriter out;

private DefaultListModel listModel;

private String myName;

private String withWho = "所有人"; JPanel centerPanel;

JScrollPane commonAreaScroll; JScrollPane myMsgAreaScroll; public ChatFrame(){

super("MSGXCC聊天系统");

//*********************上面进入聊天室房间**************//

JPanel upperPanel = new JPanel();

welcomeInfo = new JLabel();

Icon BordTop = new ImageIcon("images\\BordTop.gif");

welcomeInfo.setIcon(BordTop);

nameLabel = new JLabel(); upperPanel.add(welcomeInfo); upperPanel.add(nameLabel);

//**************中间聊天室两个窗口***********************// centerPanel = new JPanel(new BorderLayout()); //面板

commonArea = new JTextArea(15,40);//公共言论区commonArea.setEditable(false);

commonAreaScroll = new JScrollPane(commonArea); commonAreaScroll.setVerticalScrollBarPolicy(

JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); commonAreaScroll.setHorizontalScrollBarPolicy( ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

commonAreaScroll.setBorder(BorderFactory.createTitledBorder("主聊天频道")); centerPanel.add(commonAreaScroll,BorderLayout.NORTH);

myMsgArea = new JTextArea(10,40);//我的发言区myMsgArea.setEditable(false);

myMsgArea.setForeground(new Color(107,101,29));//设置颜色myMsgAreaScroll = new JScrollPane(myMsgArea); myMsgAreaScroll.setVerticalScrollBarPolicy(

JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); myMsgAreaScroll.setHorizontalScrollBarPolicy( ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

myMsgAreaScroll.setBorder(BorderFactory.createTitledBorder("我的频道")); centerPanel.add(myMsgAreaScroll,BorderLayout.CENTER);

//******************输入发送区*********************** JPanel centerLowerPanel = new JPanel(new BorderLayout());

JPanel tempPanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));

JPanel tempPanel2 = new JPanel(new BorderLayout());

JLabel withWho = new JLabel("对"); perponsComboBox = new JComboBox();

perponsComboBox.addItem("所有人"); privateTalk = new JCheckBox("私聊"); inMsgField = new JTextField(33); sentButton = new JButton();

Icon sentIcon = new ImageIcon("images\\ButtonSenddown.gif"); sentButton.setIcon(sentIcon);

sentButton.setBackground(Color.WHITE);

//JToggleButton toggleButton = new JToggleButton("私聊"); tempPanel1.add(withWho);

tempPanel1.add(perponsComboBox); tempPanel1.add(privateTalk);

//tempPanel1.add(toggleButton);

tempPanel2.add(inMsgField,BorderLayout.CENTER);

tempPanel2.add(sentButton,BorderLayout.EAST); centerLowerPanel.add(tempPanel1,BorderLayout.CENTER); centerLowerPanel.add(tempPanel2,BorderLayout.SOUTH); centerPanel.add(centerLowerPanel,BorderLayout.SOUTH);

//**************East显示进入房间的名单*********************//

JPanel eastPanel = new JPanel(new BorderLayout()); listModel = new DefaultListModel();

peopleList = new JList(listModel);peopleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

JScrollPane ListScrollPane = new JScrollPane(peopleList); ListScrollPane.setPreferredSize(new Dimension(150, 400)); refurbishButton = new JButton("刷新列表");…………………………………………

参考文献:

[1]廖雷.Java程序设计教程[M].北京:中国电力出版社,2003.

[2] Horstman C S,Conell G.Java2核心技术(1、2)[M].陈昊鹏,译.7版.北京:机械工业出版社,2006.

[3]张立.基于Client/Server模式的数据库应用软件的设计与实现[J].计算机应用研究,1999(4).

[4]汪晓平,俞俊,李功,等.精通Java网络编程[M].北京:清华大学出版社,2005.

上一篇:计算机网络入侵检测技术分析 下一篇:无线智能终端对校园WLAN的挑战