摘 要
在网络越来越发达的今天,人们对网络的依赖越来越多,越来越离不开网络,由此而产生的聊天工具越来越多,例如,国外的ICQ、国内腾讯公司开发的OICQ。基于Java网络编程的强大功能,本次毕业设计使用Java编写一个聊天系统。
一般来说,聊天工具大多数由客户端程序和服务器程序外加服务器端用于存放客户数据的数据库组成,本系统采用客户机/服务器架构模式通过Java提供的Socket类来连接客户机和服务器并使客户机和服务器之间相互通信,由于聊天是多点对多点的而Java提供的多线程功能用多线程可完成多点对多点的聊天,数据库管理系统用SQL Server2000完成并通过JDBC-ODBC桥访问数据库。
本系统建立在JAVA平台上,系统的设计使用了面向对象技术和面向对象的设计原则。系统采用C/S结构,客户端与客户端以及客户端与服务器端之间通过Socket传送消息。使用JAVA语言编写,开发工具采用Eclipse。服务器端设计与实现过程中,采用了多线程技术,可以在单个程序当中同时运行多个不同的线程,执行不同的任务。大大增强了程序对服务器资源的利用。
聊天系统完成后将可进行多人对多人的聊天,对好友进行添加、删除,对新用户的注册,发送消息、接受消息等等功能。
关键字:多线程 ;客户机/服务器 ;JAVA ; Socket ; Eclipse ; TCP/IP
Abstract
as the network become more and more developed, people become more and more lean to the network, and can not leave with out it. This caused the chat materials become more numerous, as the overseas ICQ system, the OICQ system that invented by Tencent Co., and so on. So we create a network chat medium just like the QQ. Java network programming based on the power, the use of Java designed to prepare graduates a chat system.
In general, the majority of the chat tool for client and server program in addition to server-side storage of customer data for the database, the system uses a client / server architecture model the adoption of Java provided Socket class connect client and server and between the client and server communicate with each other, as the chat is to provide point-to-multipoint and multi-threaded Java function to be completed by using multi-threaded chat and more point-to-multipoint, database management system with SQL Server2000 the completion and adoption of JDBC-ODBC Bridge access the database.
The system built on the JAVA platform, the system design using object-oriented technology and object-oriented design principles. System uses the C / S structure, client and client-side and server-side client and send messages through Socket. The use of JAVA language, development tools using Eclipse. Design and Implementation of server-side process, the use of multi-threading technology, which can process in a single run at the same time a number of different threads, the implementation of different tasks. Procedures greatly enhanced the use of server resources.
Chat system will allow people to complete chat to more friends,and the system can add, delete somebody,can deal with new user registration, send messages, receive messages and so on.
Keywords : Multithreading ; Client/Server ;JAVA ;Socket ;Eclipse ;TCP/IP
目 录
1 绪论1
1.1国内外聊天系统的研究现状1
1.2 JAVA语言2
1.2.1 Java的发展历史2
1.2.2 Java的特点3
1.2.3 Java与Internet4
1.3 SOCKET编程4
1.3.1 关于TCP/IP协议4
1.3.2 服务器和客户机5
1.4本文内容安排6
2 需求分析7
2.1 可行性研究7
2.1.1 可行性分析7
2.1.2系统功能需求7
2.1.3 系统性能需求8
2.1.4 系统运行需求8
2.2 数据流图8
2.2.1 顶层数据流图8
2.2.2 一层数据流图9
2.2.3 二层数据流图9
3 概要设计11
3.1系统实现原理11
3.2 系统实现层次图:12
3.3各模块详细功能12
3.3.2服务器端结构12
3.3.2 客户端结构14
4 详细设计19
4.1 系统流程图19
4.1.1 系统总体流程图19
4.1.2 系统客户端流程图20
4.2 编写服务器端程序20
4.2.1 问题陈述20
4.2.2 解决方案21
4.3客户端程序编写28
4.3.3 聊天室38
参考文献46
致谢45
1 绪论
1.1国内外聊天系统的研究现状
目前国内外做聊天系统的公司很多,产品也琳琅满目,国内有诸如腾讯QQ、新浪UC、网易泡泡等,国外有著名的MSN(新版改名为Live Messenger)以及跨平台Gaim等。本人取最具代表性的QQ和MSN进行了一些研究,作为我开发聊天系统的准备。
腾讯无疑是国内即时通讯市场的霸主,自从99年进入即时通讯领域并迅速占市场之后,其在国内用户数量始终高居榜首,即使近几年面对微软MSN的强大攻势,腾讯QQ的时常占有率依然稳步增长。腾讯的成功与其对QQ的不断创新和完善是分不开的。
参考了许多网络上的资料,以及自己通过观察腾讯QQ运行时的各种细节。可以确定腾讯QQ是以多服务器提供服务、服务器总控客户端、客户端之间UDP直连通信的。并且在两个客户端之间不能建立直连的情况下,才由服务器进行中转通信。
其模型如图1-1
图1-1 腾讯QQ服务器-客户端模型1
与腾讯QQ不同,微软的MSN Messenger只使用了TCP作为传输层通
信协议,所有客户端与服务器进行连接,然后通过与服务器的TCP连接进行中转通信。
其模型如图1-2
图1-2 MSN服务器-客户端模型2
腾讯使用的模型中,服务器主要处理客户端各种状态的控制,可以极大减轻服务器的处理压力,但其内部协议和实现复杂度都较高。而MSN Messenger所有数据都要经过服务器,服务器压力可想而知(难怪平时很少见到使用MSN进行语音视频聊天的)。
综合腾讯QQ和微软MSN Messenger的特点,我打算在我的系统中尝试建立其类似腾讯QQ的服务器-客户端模型,但以单服务器提供服务。
1.2 Java语言
1.2.1 Java的发展历史
Java的发展历史,可以追朔到1990年。当时Sun Microsystem公司为了发展消费类电子产品进行了一个名为Green的项目计划。这个计划的负责任是James Gosling。起初他用具有面向对象特征的C++语言编写嵌入式软件,可以放在面包机或PDA(Personal Digital Assistant,个人数字主力)等小型电子消费这杯里,以使设备变得更为"聪明",更具备人工只能。但后来发现C++并不适合这类任务;因为C++常会使系统失效。尤其在内存管理方面,c++采用直接地址访问方式。需要程序员记录并管理内存资源。这造成程序员编程的极大负担,并可能产生多个Bugs。面包机上的程序错误可能使面包机烧坏甚至爆炸。
为了解决此类问题,Gosling决定开发一种新的语言,并取名为Oak。它采用了大部分与C++类似的语法对可能具备危险性的功能加以改进,例如将内存管理改为由语言自
上一篇:
基于Java_web的邮件管理系统-毕业设计(论文)
下一篇:
高陈基于Java超市账单管理系统