当前位置:文档之家› 基于Socket的局域网通信工具的设计与实现的方法

基于Socket的局域网通信工具的设计与实现的方法

摘要随着计算机科学和Internet的飞速发展,网上聊天已成为人们相互交流的一中方式,与E-mail、电话相比,聊天服务更具有实时性和有效性。

网络版的聊天软件种类繁多,如QQ、OICQ、MSN等,实现随时随地上网聊天,给人们带来了很大的方便。

但是这些聊天软件也存在以下不足:用户必须连接Internet;用户在工作时容易沉迷于网络聊天。

为了方便单位企业内部的信息交流,避免企业内部员工使用类似QQ等软件泄露内部信息,减少不必要的财力和人力资源浪费,开发一个局域网聊天软件是非常必要的。

通过对局域网络通信的学习研究,本文介绍了局域网通信和实现聊天器基本通信功能的流程,并编写了一个基于Winsock的局域网络聊天器系统。

本系统是运行于MFC 平台上的Winsock局域网聊天软件,该聊天软件采用C/S结构,包括服务器和客户端两个模块,客户端通过服务端进行通信。

服务器模块主要实现了服务器的配置和数据的传递;客户端模块主要实现了用户注册、登录、文字聊天和文件传送等功能。

该软件采用多线程技术支持多用户操作,并采用相关技术进行了优化,加快了文字传递速度。

主要用到了Winsock编程技术、TCP/IP协议、多线程技术、数据库存取技术和各种控件编程技术。

本文主要分为六个章节,第一章概括的说明聊天器的背景及应用。

第二章阐述实现局域网络聊天器系统所用到的主要技术。

第三章根据聊天器的设计实现进行需求分析。

第四章详细描述了本系统各个模块的设计。

第五章重点介绍各个模块的实现和测试。

第六章是结束语,总结毕业设计中遇到的问题和自己的收获,感谢给予指导和帮组的老师和同学。

关键词:局域网;TCP/IP协议;Winsock;多线程AbstractWith the computer science and the rapid development of Internet, online chat has become a way of mutual exchange of one, and E-mail, phone calls with real-time chat services and more effective. Online chat software, a wide variety, such as QQ, OICQ, MSN and so on, to achieve anytime, anywhere access to chat, to bring a great convenience. But the lack of chat software, there are the following: the user must be connected to Internet; users to work easily addicted to online chat. T o facilitate the exchange of information within business units to avoid the use of internal staff and other software like QQ leaked internal information to reduce unnecessary waste of financial and human resources to develop a LAN chat software is very necessary.Through the study of local area network communication, this article describes the communication and implementation of local area network chat basic communication process device, and write a Winsock-based local area network chat control system. The system is running on the platform at the MFC Winsock LAN chat software, chat software with the C / S structure, including both server and client modules, the client side to communicate through the service. Server module main achievement of the server's configuration and data transfer; client module main achievement of the user registration, login, text chat and other functions. The software supports multi-threading multi-user operation, and optimized use of relevanttechnologies, accelerate the transmission speed of text. Mainly used the Winsock programming, TCP / IP protocol, multi-threading, database access technology, and various control programming.This paper is divided into six chapters, the first chapter general description of the background of chat devices and applications. The second chapter to achieve local area network chat system used in the main control technology. Chapter III device under the design and implementation needs analysis chat. The fourth chapter describes in detail the design of the various modules of the system. Chapter V focuses on the implementation and testing of each module. Chapter VI is the Conclusion, summarizes the problems encountered in the design school and their own harvest for guidance and help teachers and students groups.Key words: LAN;TCP / IP protocol;Winsock;multi-threaded目录摘要 (I)Abstract ........................................................................................................................... I II 1绪论 (1)1.1背景知识 (1)1.2国内外聊天器系统研究现状 (1)1.3选题的目的及意义 (3)1.4本课题研究内容 (3)1.5本章小结 (4)2 实现原理及开发环境 (5)2.1M ICROSOFT O FFICE A CCESS (5)2.2套接字(S OCKET) (6)2.2.1 Windows Socket介绍(Winsock) (8)2.2.2 Socket的同步和异步方式 (9)2.2.3 用Socket 开发一个Server-Client模型的程序 (10)2.3多线程技术 (11)2.4TCP/IP协议、UDP协议 (12)2.4.1 面向连接的TCP (13)2.4.2 面向非连接的UDP协议 (15)2.5C LIENT/S ERVER结构(客户机/服务器模式) (15)2.6编程环境 (17)2.6.1 硬件环境 (17)2.6.2 软件环境 (17)2.6.3 开发工具介绍 (17)2.7本章小结 (18)3 需求分析 (19)3.1需求分析 (20)3.1.1 可行性分析 (20)3.2.2 系统性能需求 (20)3.1.3 系统运行需求 (21)3.2数据流图 (21)3.2.2 一层数据流图 (21)3.2.3 二层数据流图 (22)3.3本章小结 (21)4 系统设计 (23)4.1系统实现原理 (23)4.2C/S架构设计 (24)4.3模块设计 (26)4.3.1 系统流程图 (26)4.3.1.1 系统总体流程图 (26)4.3.1.2系统客户端流程图 (27)4.3.2 数据库设计 (27)4.4界面效果 (28)4.5本章小结 (29)5 系统实现及测试 (30)5.1服务端 (30)5.1.1 自动配置数据源 (30)5.1.2 定义服务端的关键结构体 (31)5.1.2.1 用户信息的结构体 (31)5.1.2.2 在线用户结构体 (31)5.1.2.3 Socket信息结构体 (32)5.1.3 启动winsocket2 (32)5.1.4 调用两个WINAPI函数 (33)5.1.4.1 接收client 连接的WINAPI 函数 (33)5.1.4.2 线程操作处理WINAPI 函数 (36)5.1.5 模块功能实现(代码略) (39)5.1.6 模块界面 (39)5.2客户端 (40)5.2.1 登录模块 (40)5.2.2 注册模块 (42)5.2.3 文字聊天模块 (44)5.2.3.1 发送消息: (44)5.2.3.2 连接信息服务器 (45)5.2.4 文件传送 (48)5.2.4.1 发送文件 (48)5.2.4.2 接收文件 (49)5.3系统测试 (51)5.3.1 测试环境 (51)5.3.2 测试原则 (52)5.3.3 测试方法及结果 (52)5.4本章小结 (56)结论 (57)致谢 (59)参考文献 (60)1绪论1.1背景知识近年来,随着全球信息化进程的不断发展,网络也在飞速发展。

相关主题