成 都 信 息 工 程 学 院
学 位 论 文
基于网络的虚拟实验平台
—VLP2P 通信库的设计与实现
论 文 作 者 姓 名 :
申 请 学 位 专 业 :
申 请 学 位 类 别 :
指导教师姓名(职称):
论 文 提 交 日 期 :
基于网络的虚拟实验平台
—VLP2P 通信库的设计与实现
摘 要
随着信息技术的发展,网络无疑为我们带了更多的便利,因此一个好的系统
要具有网络功能。针对虚拟实验台系统的实际功能,采用 P2P 技术作为其网络通
讯基础具有很大的优势:降低服务器资源占用,提高通讯传输效率。但由于 NAT
的广泛使用,使得不同的内网间系统通讯比较困难。希望 P2P 通讯具有实用价值,
穿透 NAT 实现不同内网间的系统通讯是一个需要解决的重要问题。
在基于网络的虚拟实验平台中,有很多功能涉及到网络通讯,为了提高系统
的模块化程度,减少系统重复开发量,将网络通信部分独立出来,设计实现名为
VLP2P 的 P2P 通讯库。设计中,也设计了通讯库的测试程序。经实际测试,基本
达到预期设计目标。
关键词:虚拟实验平台;P2P 技术;UDP;穿透 NAT;Scoket 编程
Network-based Virtual Experimental Platform——
Design and Implementation of VLP2P Communication Library
Abstract
With the development of information technology, networks will provide us with
more convenience undoubtedly. Therefore, a good system must have network
functions. According to real functions of the virtual experiment platform, P2P
technology has powerful benefits to decrease probability of using server resources and
upgrade the transmission efficiency, as a base of networking communication. While,
because of the existence of NAT issues, it is difficult to communicate among different
local networks. To make P2P communication get values in real application, an
important problem required to solve is the system communication among different
networks by penetrating NAT.
There are many functions related to network communication in the virtual
experiment platform based on network. For improve modularization of the system and
decrease repetitive developing work, the network communication is extracted as an
independent part to design and implement P2P communication library named VLP2P.
In the thesis, the testing program for communication library is also designed. With
real testament, it has proven that the communication library has achieved the initial
purpose..
Key words: Virtual Experiment Platform; P2P Technology; UDP;
Penetrating NAT; Socket programming
目 录
论文总页数:20 页
1 引言............................................................................................................................................1
1.1. 项目背景........................................................................................................................1
1.2. 项目介绍........................................................................................................................1
1.2.1 虚拟实验平台............................................................................................................1
1.2.2 平台网络通信............................................................................................................1
1.3. 项目要求........................................................................................................................1
1.3.1 功能要求....................................................................................................................1
1.3.2 B/S 与 C/S.................................................................................................................2
1.3.3 通信协议的选择........................................................................................................2
1.4. 项目难点及解决方法....................................................................................................2
1.4.1 IP 处理问题...............................................................................................................2
1.4.2 Client 之间的通信问题...........................................................................................2
2. 网络基础知识介绍....................................................................................................................2
2.1. SOCKET 编程...................................................................................................................2
2.2. P2P 网络简介(INTRODUCTION) .........................................................................................3
3. 项目网络通信的实现过程........................................................................................................4
3.1. NAT 的一些基本概念.....................................................................................................4
3.2. 通信过程........................................................................................................................4
3.3. 通信过程总结................................................................................................................7
4. 实现代码及其效果简介............................................................................................................8
4.1. 程序主要功能介绍........................................................................................................8
4.2. 主要代码介绍................................................................................................................8
4.3.1 服务器监听过程主要代码........................................................................................8
4.3.2 客户端连接过程主要代码........................................................................................8
4.3.3 下载实验文本(客户端主要代码)........................................................................9
4.3.4 下载实验文本(服务器端主要代码)....................................................................9
4.3.5 P2P 下载实验文本(客户端主要代码)...............................................................10
4.3.6 客户端 P2P 下载实验文本(服务器端主要代码)..............................................11
4.3. 效果演示......................................................................................................................12
4.3.1 开启服务及客户端登陆..........................................................................................12
4.3.2 通过服务器下载实验文本......................................................................................13
4.3.3 退出连接..................................................................................................................14
结 论..........................................................................................................................................14
参考文献..........................................................................................................................................14
附 录..........................................................................................................................................16
致 谢..........................................................................................................................................19