资源描述
一、目标和任务
1.目标
(1)加深对计算机网络基础概念和原理,和网络编程接口Socket概念及编程原理了解;
(2)提升学生网络应用和编程、分析和处理实际问题能力,为大型网络编程打下坚实基础;
(3)经过撰写课程设计汇报,锻炼学生逻辑组织和语言表示能力;
(4)培养学生理论利用于实践综合应用和设计创新能力。
经过此次课程设计,使学生深入了解、领会C#语言和网络编程技术,把所学知识利用到具体程序设计当中去,编写一个靠近实际应用程序。
本课程设计是一门综合性试验。
经过此次课程设计,掌握.net应用程序设计;加深对TCP/IP协议了解;掌握C/S编程模式;掌握Socket机制、传输控制协议;用户数据报协议;掌握网络抓包原理;掌握网络编程应用程序分析、设计、编程和调试整个过程。
2.任务
(1)设计完成和网络应用相关题目标网络应用软件;
(2)调试运行以后,要求边演示边解释设计思想、过程及采取方法;
(3)完成课程设计汇报。
二、基础要求
1.熟练掌握网络基础概念和原理;
2.熟练掌握网络编程接口Socket概念及编程原理;
3.掌握基于TCP/IPInternet编程技术;
4.掌握多种软件开发工具使用过程及方法。
三、设备及工具
硬件:微机120台以上,I3以上处理器,1024M以上内存、Ethernet网卡,交换机
软件:Windows/XP操作系统,VS编程环境。
摘 要
伴随计算机技术和网络技术发展,基于网络开发也越来越多。C#是微软开发一个简单易懂、面向对象、类型安全编程语言。随.NET技术不停发展,C#在各个方面编程优势全部已经显现出来。此次课程设计关键是利用C#进行网络和通信编程,完成简单Web浏览器。
在此次设计中,我完成Web浏览器关键是经过HTTP协议来实现。HTTP协议,即超文本传输协议。它是一个应用层面向对象协议,因为其简捷、快速方法,很使用于分布式超媒体信息系统。用户使用大部分浏览器全部是经过HTTP协议对网站中内容进行浏览,在用户浏览网页时,在浏览器地址中首先输入就是HTTP,以告诉浏览器是经过HTTP协议来访问网页。
在此系统应用中,关键内容是对收藏夹应用,其中包含对注册表使用。在C#中,Registry类、RegistryKey类能够实现对注册表操作。Registry类中封装了注册表中7个基础主键,经过这类能够在注册表中找到标准根项集。RegistryKey类封装了对注册表基础操作,包含读取、写入、删除等。
经过具体设计,我完成Web浏览器关键能实现功效为:主界面、浏览网页、网页设置、浏览器设置等多个部分。
关键词 网络技术,C#,浏览器,HTTP协议
目 录
第1章 绪 论 1
第2章 系统功效介绍 2
2.1系统模型 2
2.2 系统功效设计 2
2.3 系统模块 3
2.3.1 主界面功效介绍 3
2.3.2 具体模块功效介绍 3
2.3.3 相关ActiveX控件axWebBrowser添加 3
第3章 系统功效实现 4
3.1 浏览功效实现 4
3.1.1 主菜单实现基础操作 4
3.1.2 用“转到”按钮实现浏览 8
3.1.3“帮助”功效实现 8
3.2 浏览控制按钮功效实现 9
3.3 历史统计功效实现 11
第4章 系统测试 12
4.1测试用例 12
4.1.1 测试用例1 12
4.1.2 测试用例2 12
4.1.3 测试用例3 12
4.1.4 测试用例4 12
4.1.5 测试用例5 12
4.2系统测试 12
4.2.1 系统测试1 13
4.2.2 系统测试2 14
4.2.3 系统测试3 14
4.2.4 系统测试4 15
结 论 16
致 谢 16
参考文件 17
第1章 绪 论
C#(C Sharp)是微软(Microsoft)为.NET Framework量身订做程序语言,C#拥有C/C++强大功效和Visual Basic简易使用特征,是第一个组件导向(Component-oriented)程序语言,和C++和Java一样亦为对象导向(object-oriented)程序语言。
此次程序设计关键任务是利用C#实现一个自制简单Web浏览器。浏览器是个显示网页伺服器或档案系统内HTML文件,并让用户和此些文件互动一个软件。个人电脑上常见网页浏览器包含微软Internet Explorer、MozillaFirefox、Opera和Safari。浏览器是最常常使用到用户端程序。
伴随网络技术发展,网络给大家带来了多种多样信息,而浏览器是大家获取信息路径。网页浏览器关键经过HTTP协议连接网页伺服器而取得网页,HTTP许可网页浏览器送交资料到网页伺服器而且获取网页。HTTP协议关键特点可概括以下:
l 支持客服端/服务器模式。
l 客服端向服务器请求服务时,只需传送请求方法和路径。请求方法要求了用户和服务器联络类型,常见有GET、HEAD、POST等。
l HTTP协议是无状态协议。无状态含义是指协议对于事务处理没有记忆能力,当事务处理结束后,HTTP协议随之结束。此时在默认状态下,假如后续处理需要前面信息,则它必需重传,这将会造成每次连接传送数据量增大。假如服务器不需要先前信息时,它应答就较快。
在此次设计中,我完成简单Web浏览器就是基于HTTP协议应用,它能实现在地址栏中输入地址后,能连接网站,并显示网页内容;能实现简单设置、文件、帮助、后退、前进、刷新、首页等功效;另外,还能实现历史统计。使用这么自制浏览器能够带来部分好处,比如它无需安装,无需升级,没有版权限制,还能够随时增加或降低自己需要或不需要功效。
第2章 系统功效介绍
2.1系统模型
本系统关键完成简单Web服务器,实现在地址栏中输入地址,能够连接到网站,并显示网页内容。在此基础之上,还能够实现简单设置、文件、刷新、首页等功效。整个系统功效模块图图2.1所表示。
图2.1 系统功效模块图
2.2 系统功效设计
一个浏览器关键有功效:主界面、浏览网页、浏览设置、浏览器设置等多个部分。本系统是基于HTTP实现浏览器,在浏览器创建过程中,应用到一个ActiveX控件,这个控件能够完成浏览器大部分功效,能够经过此控件浏览到网页内容。
在系统中还创建了主菜单栏,并在主菜单栏中创建了对浏览器进行设置“设为空白页”、“设为首页”等功效。同时,在“浏览控制按钮”栏中,创建了浏览器部分基础功效,“后退”、“前进”、“刷新”、“首页”等。另外,用ComboBox控件制作了网页地址栏输入,能够在此输入需要浏览网站地址,而且能实现历史统计。此系统设计步骤,图2.2所表示。
图2.2 系统设计步骤图
2.3 系统模块
2.3.1 主界面功效介绍
主界面是浏览器主体,运行程序,首先看到是主界面,图2.3所表示。
图2.3 主界面
在主界面最上边是一个menuStrip组件,列出浏览器“文件”、“编辑”、“查看”“工具”“帮助”等选项。主菜单栏下是一个toolStrip控件,用于显示浏览控制按钮。在浏览控制按钮下是一个Pannel控件,在此控件上,添加一个Lable控件用于显示文字信息“地址”,添加一个ComboBox控件用于输入网页地址信息,添加一个Button控件用于发送HTTP协议。
2.3.2 具体模块功效介绍
在主菜单中,能实现功效关键有“设置”、“文件”、“工具”和“帮助”。其中,“设置”能实现设为空白页、设为首页和动感效果;“文件”能实现新建、打开和推出;“工具”能实现发送邮件;“帮助”能实现“相关”,它弹出一个对话,显示相关浏览器简单说明。
在浏览控制按钮栏中,能实现基础浏览控制:新建、后退、前进、停止、刷新、主页。
在地址栏中输入地址,按回车键或“转到”按钮全部可连接到网站并显示网页内容。另外,点击地址栏下拉列表可查看历史统计。
2.3.3 相关ActiveX控件axWebBrowser添加
1.在C# Windows应用程序新建项目中,选择“工具”,打开“选择工具箱项”对话框。
2.在此对话框中打开“COM组件”选项卡,在列表框中选中“Microsoft Web浏览器”复选框。
3.单击“确定”按钮,在集成开发环境“工具箱”便会出现“Microsoft Web浏览器”控件,将此控件拖曳到Form窗口上。
根据以上步骤操作,就完成了axWebBrowser控件添加。
第3章 系统功效实现
3.1 浏览功效实现
3.1.1 主菜单实现基础操作
//
// menu_File
//
this.menu_File.Index = 0;
this.menu_File.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menu_FileNew,
this.menu_FileOpen,
this.menu_FileSave,
this.menu_FileSaveAs,
this.menuItem5,
this.menu_FileProperty,
this.menu_FileExit});
this.menu_File.Text = "文件(&F)";
//
// menu_FileNew
//
this.menu_FileNew.Index = 0;
this.menu_FileNew.Text = "新建";
this.menu_FileNew.Click += new System.EventHandler(this.menu_FileNew_Click);
//
// menu_FileOpen
//
this.menu_FileOpen.Index = 1;
this.menu_FileOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
this.menu_FileOpen.Text = "打开";
this.menu_FileOpen.Click += new System.EventHandler(this.menu_FileOpen_Click);
//
// menu_FileSave
//
this.menu_FileSave.Index = 2;
this.menu_FileSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
this.menu_FileSave.Text = "保留";
this.menu_FileSave.Click += new System.EventHandler(this.menu_FileSave_Click);
//
// menu_FileSaveAs
//
this.menu_FileSaveAs.Index = 3;
this.menu_FileSaveAs.Text = "另存为";
this.menu_FileSaveAs.Click += new System.EventHandler(this.menu_FileSaveAs_Click);
//
// menuItem5
//
this.menuItem5.Index = 4;
this.menuItem5.Text = "-";
//
// menu_FileProperty
//
this.menu_FileProperty.Index = 5;
this.menu_FileProperty.Text = "属性(&R)";
this.menu_FileProperty.Click += new System.EventHandler(this.menu_FileProperty_Click);
//
// menu_FileExit
//
this.menu_FileExit.Index = 6;
this.menu_FileExit.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
this.menu_FileExit.Text = "退出(&C)";
this.menu_FileExit.Click += new System.EventHandler(this.menu_FileExit_Click);
//
// menu_Edit
//
this.menu_Edit.Index = 1;
this.menu_Edit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menu_EditCut,
this.menu_EditCopy,
this.menuEditPaste,
this.menuItem16,
this.menu_EditSelAll,
this.menu_EditFind});
this.menu_Edit.Text = "编辑(&E)";
//
// menu_EditCut
//
this.menu_EditCut.Index = 0;
this.menu_EditCut.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
this.menu_EditCut.Text = "剪切";
this.menu_EditCut.Click += new System.EventHandler(this.menu_EditCut_Click);
//
// menu_EditCopy
//
this.menu_EditCopy.Index = 1;
this.menu_EditCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
this.menu_EditCopy.Text = "复制";
this.menu_EditCopy.Click += new System.EventHandler(this.menu_EditCopy_Click);
//
// menuEditPaste
//
this.menuEditPaste.Index = 2;
this.menuEditPaste.Shortcut = System.Windows.Forms.Shortcut.CtrlV;
this.menuEditPaste.Text = "粘贴";
this.menuEditPaste.Click += new System.EventHandler(this.menuEditPaste_Click);
//
// menuItem16
//
this.menuItem16.Index = 3;
this.menuItem16.Text = "-";
//
// menu_EditSelAll
//
this.menu_EditSelAll.Index = 4;
this.menu_EditSelAll.Shortcut = System.Windows.Forms.Shortcut.CtrlA;
this.menu_EditSelAll.Text = "全选";
this.menu_EditSelAll.Click += new System.EventHandler(this.menu_EditSelAll_Click);
//
// menu_EditFind
//
this.menu_EditFind.Index = 5;
this.menu_EditFind.Shortcut = System.Windows.Forms.Shortcut.CtrlF;
this.menu_EditFind.Text = "查找";
this.menu_EditFind.Click += new System.EventHandler(this.menu_EditFind_Click);
//
// menu_View
//
this.menu_View.Index = 2;
this.menu_View.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menu_ViewSource});
this.menu_View.Text = "查看(&V)";
//
// menu_ViewSource
//
this.menu_ViewSource.Index = 0;
this.menu_ViewSource.Text = "源文件";
this.menu_ViewSource.Click += new System.EventHandler(this.menu_ViewSource_Click);
//
// menu_Tool
//
this.menu_Tool.Index = 3;
this.menu_Tool.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menu_ToolInternet,
this.menuItem1,
this.menuItem3,
this.menuItem6});
this.menu_Tool.Text = "工具(&T)";
//
// menu_ToolInternet
//
this.menu_ToolInternet.Index = 0;
this.menu_ToolInternet.Text = "Internet选项";
this.menu_ToolInternet.Click += new System.EventHandler(this.menu_ToolInternet_Click);
//
// menuItem1
//
this.menuItem1.Index = 1;
this.menuItem1.Text = "收藏夹";
//
// menuItem3
//
this.menuItem3.Index = 2;
this.menuItem3.Text = "设置";
//
// menuItem6
//
this.menuItem6.Index = 3;
this.menuItem6.Text = "下载内容";
//
// menu_Help
//
this.menu_Help.Index = 4;
this.menu_Help.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menu_HelpAbout,
this.menuItem2});
this.menu_Help.Text = "帮助(&H)";
this.menu_Help.Click += new System.EventHandler(this.menu_Help_Click);
//
// menu_HelpAbout
//
this.menu_HelpAbout.Index = 0;
this.menu_HelpAbout.Text = "相关";
this.menu_HelpAbout.Click += new System.EventHandler(this.menu_HelpAbout_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "检验更新";
//
// menuItem4
//
this.menuItem4.Index = 5;
this.menuItem4.Text = "添加到收藏";
3.1.2 用“转到”按钮实现浏览
在地址栏中输入网址,除了按回车键能够连接到网站外,还能够单击地址栏后“转到”按钮连接到网站。双击设计窗体中“转到”按钮,在此按钮Click事件中添加代码实现用“转到”按钮浏览。
程序代码以下:
this.btnGo.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnGo.Font = new System.Drawing.Font("华文彩云", 8.999999F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnGo.Location = new System.Drawing.Point(318, 36);
this.btnGo.Name = "btnGo";
this.btnGo.Size = new System.Drawing.Size(63, 22);
this.btnGo.TabIndex = 3;
this.btnGo.Text = "转到";
this.btnGo.Click += new System.EventHandler(this.btnGo_Click);
3.1.3“帮助”功效实现
“帮助”可实现“相关”功效。在主菜单中,选择“帮助”,打开“相关”,弹出一个对话框,它是相关程序简单描述,图3.2所表示。
图3.2 相关对话框
“相关”对话框是在“相关”Click事件中调用另一个窗体Form2来实现,“相关”程序代码以下:
this.menu_HelpAbout.Index = 0;
this.menu_HelpAbout.Text = "关?于?;
this.menu_HelpAbout.Click += new System.EventHandler(this.menu_HelpAbout_Click);
}
在Form2窗体设计中,添加一个PictureBox控件来显示图片,添加Label控件来实现文字显示,并用一个“确定”按钮来实现退出对话框。
程序以下所表示:
private void menu_HelpAbout_Click(object sender, System.EventArgs e)
{
MessageBox.Show("旭日浏览器1.0","旭日浏览器",MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
private void menu_FileExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
3.2 浏览控制按钮功效实现
在Form设计窗口中,在toolStrip控件上双击鼠标左键,为此控件Click事件添加对应程序代码,能够实现对浏览器进行后退、前进、暂停、刷新、首页、搜索操作。
程序代码以下:
this.mainToolBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
this.mainToolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.tbb_New,
this.toolBarButton1,
this.tbb_Back,
this.tbb_Forward,
this.toolBarButton2,
this.tbb_Stop,
this.tbb_Refresh,
this.tbb_GoHome,
this.toolBarButton3});
this.mainToolBar.ButtonSize = new System.Drawing.Size(60, 22);
this.mainToolBar.DropDownArrows = true;
this.mainToolBar.ImageList = this.imageList1;
this.mainToolBar.Location = new System.Drawing.Point(0, 0);
this.mainToolBar.Name = "mainToolBar";
this.mainToolBar.ShowToolTips = true;
this.mainToolBar.Size = new System.Drawing.Size(724, 28);
this.mainToolBar.TabIndex = 7;
this.mainToolBar.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right;
this.mainToolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.mainToolBar_ButtonClick);
//
// tbb_New
//
this.tbb_New.ImageIndex = 0;
this.tbb_New.Name = "tbb_New";
this.tbb_New.Text = "新建";
this.tbb_New.ToolTipText = "新建";
//
// toolBarButton1
//
this.toolBarButton1.Name = "toolBarButton1";
this.toolBarButton1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// tbb_Back
//
this.tbb_Back.ImageIndex = 1;
this.tbb_Back.Name = "tbb_Back";
this.tbb_Back.Text = "后退";
this.tbb_Back.ToolTipText = "后退";
//
// tbb_Forward
//
this.tbb_Forward.ImageIndex = 2;
this.tbb_Forward.Name = "tbb_Forward";
this.tbb_Forward.Text = "前进";
this.tbb_Forward.ToolTipText = "前进";
//
// toolBarButton2
//
this.toolBarButton2.Name = "toolBarButton2";
this.toolBarButton2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// tbb_Stop
//
this.tbb_Stop.ImageIndex = 3;
this.tbb_Stop.Name = "tbb_Stop";
this.tbb_Stop.Text = "停止";
this.tbb_Stop.ToolTipText = "停止";
//
// tbb_Refresh
//
this.tbb_Refresh.ImageIndex = 4;
this.tbb_Refresh.Name = "tbb_Refresh";
this.tbb_Refresh.Text = "刷新";
this.tbb_Refresh.ToolTipText = "刷新";
//
// tbb_Go
展开阅读全文