![](https://csdnimg.cn/release/download_crawler_static/89608656/bg1.jpg)
毕 业 论 文
通信软件的设计与实现
论 文 作 者 姓 名 :
申 请 学 位 专 业 :
申 请 学 位 类 别 :
指导教师姓名(职称):
论 文 提 交 日 期 :
![](https://csdnimg.cn/release/download_crawler_static/89608656/bg2.jpg)
摘 要
即时通信(Instant Message),由于其具有实时性、跨平台性、成本低、效率高
等优点而受到广泛的使用。设计并实现一个能够处理多用户进行实时、安全的即时
通信系统具有较强的现实意义。即时通信的底层通信是通过 SOCKET 套接字接口实现
的。当前的主流 UNIX 系统和微软的 WINDOWS 系统都在内核提供了对 SOCKET 字接口
的支持。使用这个统一的接口,可以编写一个可移植的 TCP/IP 通信程序。使信息能
够在 INTERNET 上可靠的传输。
本文设计并实现了基于局域网内的简单即时通信系统,系统采用 C/S 模式,底
层通信通过 SOCKET 套接字接口实现,服务器负责客户端的登录验证,好友信息的保
存和心跳报文的发送。客户端采用 P2P 方式实现消息传递,并能实现文件的传输。
本文首先讨论了同步套接字,异步套接字,多线程并发执行任务等;然后阐述了客
户端、服务器如何使用 XML 序列化的消息进行通信。
关键词:即时通信;文件传输;套接字;TCP 协议
![](https://csdnimg.cn/release/download_crawler_static/89608656/bg3.jpg)
Abstract
Instant messages have several advantages such as real-time, cross-platform, cheap
and efficient. To design a Multi-user IM (instant message) architecture is very important
in both theory and realism. Instant message based on TCP/IP protocol that is realized by
socket interface. Almost all UNIX operation systems and Microsoft's windows operation
systems provide support of socket in the kernel. Using the uniform interface, we can
develop a portable program of TCP/IP, which help us transfer information in Internet
safely and credibly.
The system uses the client/server(C/S) mode. The server takes the responsibility of
the login message of client, the saving of friend message and Message heartbeat. The
transmission of the basic messages of the customer end will be designed on P2P
architecture. This thesis explains how the client and server communicate via serializing
XML message.
Key words: Instant Message; File Transfer; Socket; TCP protocol
![](https://csdnimg.cn/release/download_crawler_static/89608656/bg4.jpg)
目 录
论文总页数:28 页
1 引言..............................................................................................................................................1
1.1 课题背景..................................................................................................................................1
1.2 国内外研究现状......................................................................................................................1
1.2.1 国外研究现状..................................................................................................................1
1.2.2 国内研究现状..................................................................................................................2
1.3 本课题研究的意义..................................................................................................................2
1.4 本课题的研究方法..................................................................................................................2
2 相关技术介绍..............................................................................................................................2
2.1 .NET 开发平台及 C#.NET 开发语言.....................................................................................2
2.2 TCP 协议...................................................................................................................................3
2.2.1 TCP/IP 网络协议.............................................................................................................3
2.2.2 TCP——传输控制协议....................................................................................................3
2.3 套接字......................................................................................................................................4
2.4 流..............................................................................................................................................4
2.4.1 流的基本概念..................................................................................................................4
2.4.2 .NET 中的流.....................................................................................................................4
2.5 同步、异步、阻塞和非阻塞..................................................................................................5
2.6 C/S 模型...................................................................................................................................5
2.7 即时通信协议..........................................................................................................................6
3 系统总体设计..............................................................................................................................7
3.1 需求分析..................................................................................................................................7
3.2 系统基本架构..........................................................................................................................7
3.3 功能模块设计..........................................................................................................................7
3.4 逻辑图......................................................................................................................................9
3.5 数据库设计............................................................................................................................10
3.5.1 实体关系图....................................................................................................................10
3.5.2 详细列表........................................................................................................................10
4 系统实现....................................................................................................................................11
4.1 使用 XML 定义的即时通信协议............................................................................................11
4.1.1 信息结构 MESSAGE.CS&UMESSAGE.CS................................................................11
![](https://csdnimg.cn/release/download_crawler_static/89608656/bg5.jpg)
4.1.2 数据结构 FriendStruct...............................................................................................12
4.2 数据库连接类........................................................................................................................14
4.3 服务器端................................................................................................................................15
4.3.1 同步套接字网络监听....................................................................................................15
4.3.2 多线程............................................................................................................................19
4.3.3 计时器............................................................................................................................19
4.4 客户端....................................................................................................................................20
4.4.1 同步套接字客户端........................................................................................................20
4.4.2 采用异步套接字的文件传输........................................................................................23
结 论................................................................................................................................................25
参考文献................................................................................................................................................26
致 谢................................................................................................................................................27
声 明................................................................................................................................................28