网络程序设计实验指导书

上传人:第*** 文档编号:34264820 上传时间:2018-02-22 格式:DOC 页数:37 大小:854.50KB
返回 下载 相关 举报
网络程序设计实验指导书_第1页
第1页 / 共37页
网络程序设计实验指导书_第2页
第2页 / 共37页
网络程序设计实验指导书_第3页
第3页 / 共37页
网络程序设计实验指导书_第4页
第4页 / 共37页
网络程序设计实验指导书_第5页
第5页 / 共37页
点击查看更多>>
资源描述

《网络程序设计实验指导书》由会员分享,可在线阅读,更多相关《网络程序设计实验指导书(37页珍藏版)》请在金锄头文库上搜索。

1、网络程序设计实验指导书实验教案(主要界面及代码)学院:计算机科学与技术专业:非师范年级:2009一、实验名称: 实验一 进程与线程(4 学时)二、仪器、设备: 教学机房1、安装有 vs2008 的计算机三、参考资料:C#网络应用编程四、实验目的(1)掌握进程查看、启动、停止的基本方法;(2)掌握线程创建、启动、终止的基本方法;(3)掌握开辟多线程的基本方法;(4)掌握在一个线程中引用其他线程中的控件的方法;五、实验重点、难点开辟多线程的基本方法;在一个线程中引用其他线程中的控件的方法六、实验内容1. 观察本机运行的所有进程,并显示进程相关的信息。要求:(1)用 DataGridView 显示所

2、有进程信息(2)鼠标单击 DataGridView 某处时,判断单击的是否为行开头或者某个单元格,如果是,显示该行进程的详细信息2. 在 Class1 类中声明两个方法 Method1 和 Method2,其中 Method1 不停地输出字符“a”,Method2 不停地输出字符“b”,在 Form1 中启动线程执行 Method1 和 Method2,并在 RichTextBox 中显示线程输出的字符。七、实验原理1 在VS 2008下新建Windows 窗体应用程序,并编写如下代码,并调试运行。namespace ProcessMonitorpublic partial class For

3、m1 : FormProcess myProcess;public Form1()InitializeComponent();dataGridView1.AllowUserToAddRows = false;dataGridView1.AutoResizeColumns();dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;dataGridView1.MultiSelect = false;private void Form1_Load(object sender, EventArgs e)

4、GetAllProcess();private void GetAllProcess()dataGridView1.Rows.Clear(); myProcess = Process.GetProcesses();foreach (Process p in myProcess)int newRowIndex = dataGridView1.Rows.Add();DataGridViewRow row = dataGridView1.RowsnewRowIndex;row.Cells0.Value = p.Id;row.Cells1.Value = p.ProcessName;row.Cells

5、2.Value = string.Format(0:#,#0.00MB, p.WorkingSet64 / 1024.0f / 1024.0f);/有些进程无法获取启动时间和文件名信息,所以要用try/catchtryrow.Cells3.Value = string.Format(0, p.StartTime);row.Cells4.Value = p.MainModule.FileName;catchrow.Cells3.Value = ;row.Cells4.Value = ;private void ShowProcessInfo(Process p)StringBuilder sb

6、= new StringBuilder();sb.AppendLine(进程名称: + p.ProcessName + , ID: + p.Id);trysb.AppendLine(进程优先级: + p.BasePriority + (优先级类别: + p.PriorityClass + ));ProcessModule m = p.MainModule;sb.AppendLine(文件名: + m.FileName);sb.AppendLine(版本: + m.FileVersionInfo.FileVersion);sb.AppendLine(描述: + m.FileVersionInfo

7、.FileDescription);sb.AppendLine(语言: + m.FileVersionInfo.Language);sb.AppendLine(-);if (p.Modules != null)ProcessModuleCollection pmc = p.Modules;sb.AppendLine(调用的模块(.dll):);for (int i = 1; i / 获取本机IP信息/ private void buttonLocalIP_Click(object sender, EventArgs e)listBoxLocalInfo.Items.Clear();string

8、 name = Dns.GetHostName();listBoxLocalInfo.Items.Add(本机主机名: + name);IPHostEntry me = Dns.GetHostEntry(name);listBoxLocalInfo.Items.Add(本机所有IP地址:);foreach (IPAddress ip in me.AddressList)listBoxLocalInfo.Items.Add(ip);IPAddress localip = IPAddress.Parse(127.0.0.1);IPEndPoint iep = new IPEndPoint(loca

9、lip, 80);listBoxLocalInfo.Items.Add(IP端点: + iep.ToString();listBoxLocalInfo.Items.Add(IP端口: + iep.Port);listBoxLocalInfo.Items.Add(IP地址: + iep.Address);listBoxLocalInfo.Items.Add(IP地址族: + iep.AddressFamily);listBoxLocalInfo.Items.Add(可分配端口最大值: + IPEndPoint.MaxPort); listBoxLocalInfo.Items.Add(可分配端口最

10、小值: + IPEndPoint.MinPort);/ / 获取远程主机信息/ private void buttonRemoteIP_Click(object sender, EventArgs e)this.listBoxRemoteInfo.Items.Clear();IPHostEntry remoteHost = Dns.GetHostEntry(this.textBoxRmoteIP.Text);IPAddress remoteIP = remoteHost.AddressList;IPEndPoint iep;foreach (IPAddress ip in remoteIP)i

11、ep = new IPEndPoint(ip, 80);listBoxRemoteInfo.Items.Add(iep);程序运行结果如下图:2 在VS 2008下新建Windows 窗体应用程序,并编写如下代码,并调试运行。namespace EncoderDecoderExamplepublic partial class MainForm : Formpublic MainForm()InitializeComponent();textBoxOldText.Text = 测试数据:abc,123,我;textBoxEncoder.ReadOnly = textBoxDecoder.Rea

12、dOnly = true;private void MainForm_Load(object sender, EventArgs e)/显示现有的编码类型foreach (EncodingInfo ei in Encoding.GetEncodings()Encoding en = ei.GetEncoding();comboBoxType.Items.Add(string.Format(01, en.HeaderName, en.EncodingName);comboBoxType.SelectedIndex = comboBoxType.FindString(gb2312);private

13、 void buttonRun_Click(object sender, EventArgs e)/编码 String codeType = boBoxType.SelectedItem.ToString();codeType = codeType.Substring(0, codeType.IndexOf();Encoder encoder = Encoding.GetEncoding(codeType).GetEncoder();char chars = this.textBoxOldText.Text.ToCharArray();Byte bytes = new Byteencoder.

14、GetByteCount(chars, 0, chars.Length, true);encoder.GetBytes(chars, 0, chars.Length, bytes, 0, true);textBoxEncoder.Text = Convert.ToBase64String(bytes);/解码Decoder decoder = Encoding.GetEncoding(codeType).GetDecoder();int charLen = decoder.GetChars(bytes, 0, bytes.Length, chars, 0);String strResult =

15、 ;foreach (char c in chars)strResult = strResult + c.ToString();textBoxDecoder.Text = strResult;程序结果如下:一、实验名称: 实验三 掌握如何使用 WinSock编写简单的基于 TCP协议的网络通信程序。(4 学时)二、仪器、设备: 教学机房1、安装有 vs2008 的计算机三、参考资料:C#网络应用编程四、实验目的(1)掌握面向连接套接字编程、无连接套接字编程基本步骤(2)掌握 FileStream、NetworkStream 类的用法;五、实验重点、难点掌握面向连接套接字编程、无连接套接字编程基本步骤六、实验内容(1)编写一个控制台程序,利用同步Socket实现客户端和服务器的消息通信。其中,服务器可以与多个客户端通信,并随时接收客户端发送的消息。七、实验原理1 在VS 2008下新建Windows 控制台应用程序,并编写客户端如下代码,并调试运行。namespace SocketClientclass Programprivate static byte result = new Byte1024;static void Main(string ar

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号