




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、網(wǎng)絡(luò)程序設(shè)計實驗指導(dǎo)書一、 課程名稱與大綱依據(jù)課程名稱:網(wǎng)絡(luò)程序設(shè)計 依據(jù): 網(wǎng)絡(luò)程序設(shè)計T課程教學(xué)大綱 二、 實驗性質(zhì)與類別 性質(zhì):操作、程序設(shè)計類實驗類別:應(yīng)用、技能訓(xùn)練實驗 三、 實驗教學(xué)安排學(xué)時:26學(xué)時四、實驗?zāi)康囊髮嶒灲虒W(xué)是網(wǎng)絡(luò)程序設(shè)計課程教學(xué)的一個必要組成部分,不屬于單獨的實驗課程。通過理論教學(xué)和實驗等環(huán)節(jié)的教學(xué),使學(xué)生加深對教學(xué)內(nèi)容的理解與認(rèn)識,培養(yǎng)學(xué)生的網(wǎng)絡(luò)程序設(shè)計、調(diào)試和動態(tài)頁面制作的能力。五、 實驗內(nèi)容實驗一、委托與事件1實驗二、控件應(yīng)用3實驗三、ADO.NET編程3實驗四、實現(xiàn)tcp點對點通信、udp點對點、組播的步驟和程序基本架構(gòu)3實驗五、編程實現(xiàn)FTP、SMTP、
2、POP3通信的基本步驟和程序框架30實驗六、GDI+的應(yīng)用68實驗七、基于組件的開發(fā)技術(shù)68實驗八、web service的開發(fā)與應(yīng)用68實驗一、委托與事件 實驗?zāi)康模毫私馕信c事件的基本概念,學(xué)習(xí)使用委托與事件進行簡單的程序開發(fā) 實驗內(nèi)容與步驟:1 聲明一個委托類型和一個事件2編寫調(diào)用事件的方法3編寫事件的處理方法4將事件和委托關(guān)聯(lián)5編寫主程序驗證 參考代碼: using System;namespace MyCollections using System.Collections;public delegate void ChangedEventHandler(object sender,
3、 EventArgs e);public class ListWithChangedEvent: ArrayList public event ChangedEventHandler Changed;protected virtual void OnChanged(EventArgs e) if (Changed != null)Changed(this, e);public override int Add(object value) int i = base.Add(value);OnChanged(EventArgs.Empty);return i;public override voi
4、d Clear() base.Clear();OnChanged(EventArgs.Empty);public override object thisint index set baseindex = value;OnChanged(EventArgs.Empty);namespace TestEvents using MyCollections;class EventListener private ListWithChangedEvent List;public EventListener(ListWithChangedEvent list) List = list;List.Chan
5、ged += new ChangedEventHandler(ListChanged);private void ListChanged(object sender, EventArgs e) Console.WriteLine(開始讓我處理了!);public void Detach() List.Changed -= new ChangedEventHandler(ListChanged);List = null;class Test public static void Main() ListWithChangedEvent list = new ListWithChangedEvent
6、();EventListener listener = new EventListener(list);list.Add(item 1);list.Clear();listener.Detach();Console.Read();實驗二、控件應(yīng)用實驗?zāi)康?熟悉C#.NET的winform窗體控件和WEB控件的使用 實驗要求:1、winform窗體控件使用:設(shè)計一個winform窗體,包括mainmenu控件、textbox控件、tooltip控件、tabcontrol控件、listview控件,并編寫相應(yīng)的事件響應(yīng)代碼2、簡單網(wǎng)頁:設(shè)計一個網(wǎng)頁,包括button控件、textbox控件、pan
7、el控件、listbox控件、dropdownlist控件、image控件、hyperlink控件、table控件、marquee控件、embed控件、iframe控件、彈出對話框、驗證控件,并編寫相應(yīng)的響應(yīng)代碼。實驗三、ADO.NET編程 實驗?zāi)康模簩W(xué)習(xí)數(shù)據(jù)庫聯(lián)接,了解sqldataadapter和sqldatareader工作原理 實驗內(nèi)容與要求: 1、 編程聯(lián)接數(shù)據(jù)庫,在winform上顯示sqlserver2000中的pubs數(shù)據(jù)庫的authers的內(nèi)容,利用水晶報表把顯示的內(nèi)容生成報表;比較sqldataadapter和sqldatareader的區(qū)別。 2、自建用自動增量做主碼的數(shù)
8、據(jù)表,使用dataset和datagrid在網(wǎng)頁中分頁顯示表中的數(shù)據(jù);然后a) 使用交互方式在dataset中添加十條記錄,并顯示在datagrid中;b) 再刪去3條,并顯示在datagrid中;c) 再增加2條,并顯示在datagrid中;d) 再使用dataset修改數(shù)據(jù)表。實驗四、實現(xiàn)tcp點對點通信、udp點對點、組播的步驟和程序基本架構(gòu)實驗?zāi)康模簩崿F(xiàn)tcp點對點通信、udp點對點、組播的步驟和程序基本架構(gòu)實驗內(nèi)容與要求: 閱讀和調(diào)試完成下列參考程序;修改UDP點對點程序使它能進行在廣域網(wǎng)中兩局域網(wǎng)(10.1.1.*和11.1.1.*)之間進行點對點通信。網(wǎng)絡(luò)拓?fù)鋱D如下,其中ip:1
9、0.1.1.*,11.1.1.* 為局域網(wǎng)地址,1、開發(fā)tcp同步和異步套接字點對點通信程序 /服務(wù)器端using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Net;using System.Net.Sockets;using System.Threading;namespace TestSyncServer/ / Form1 的摘要說明。/ public cl
10、ass Form1 : System.Windows.Forms.Formprivate Socket socket;private Socket clientSocket;Thread thread;private System.Windows.Forms.Label label1;private System.Windows.Forms.Label label2;private System.Windows.Forms.Label label3;private System.Windows.Forms.Label label4;private System.Windows.Forms.Gr
11、oupBox groupBox1;private System.Windows.Forms.TextBox textBoxIP;private System.Windows.Forms.TextBox textBoxPort;private System.Windows.Forms.Button buttonStart;private System.Windows.Forms.Button buttonSend;private System.Windows.Forms.Button buttonStop;private System.Windows.Forms.ListBox listBoxS
12、tate;private System.Windows.Forms.RichTextBox richTextBoxAccept;private System.Windows.Forms.RichTextBox richTextBoxSend;/ / 必需的設(shè)計器變量。/ private System.ComponentModel.Container components = null;public Form1()/ Windows 窗體設(shè)計器支持所必需的/InitializeComponent();/ TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼/this
13、.listBoxState.Items.Clear();this.richTextBoxAccept.Text=;this.richTextBoxSend.Text=;/ / 清理所有正在使用的資源。/ protected override void Dispose( bool disposing )if( disposing )if (components != null) components.Dispose();base.Dispose( disposing );#region Windows 窗體設(shè)計器生成的代碼/ / 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改/ 此方法的內(nèi)容。
14、/ private void InitializeComponent()this.label1 = new System.Windows.Forms.Label();this.label2 = new System.Windows.Forms.Label();this.label3 = new System.Windows.Forms.Label();this.label4 = new System.Windows.Forms.Label();this.groupBox1 = new System.Windows.Forms.GroupBox();this.listBoxState = new
15、 System.Windows.Forms.ListBox();this.textBoxIP = new System.Windows.Forms.TextBox();this.textBoxPort = new System.Windows.Forms.TextBox();this.buttonStart = new System.Windows.Forms.Button();this.buttonSend = new System.Windows.Forms.Button();this.buttonStop = new System.Windows.Forms.Button();this.
16、richTextBoxAccept = new System.Windows.Forms.RichTextBox();this.richTextBoxSend = new System.Windows.Forms.RichTextBox();this.groupBox1.SuspendLayout();this.SuspendLayout();/ / label1/ this.label1.Location = new System.Drawing.Point(8, 32);this.label1.Name = label1;this.label1.Size = new System.Draw
17、ing.Size(56, 23);this.label1.TabIndex = 0;this.label1.Text = 服務(wù)器IP;/ / label2/ this.label2.Location = new System.Drawing.Point(8, 72);this.label2.Name = label2;this.label2.Size = new System.Drawing.Size(56, 23);this.label2.TabIndex = 0;this.label2.Text = 監(jiān)聽端口;/ / label3/ this.label3.Location = new S
18、ystem.Drawing.Point(8, 136);this.label3.Name = label3;this.label3.Size = new System.Drawing.Size(56, 23);this.label3.TabIndex = 0;this.label3.Text = 接收信息;/ / label4/ this.label4.Location = new System.Drawing.Point(8, 224);this.label4.Name = label4;this.label4.Size = new System.Drawing.Size(56, 23);t
19、his.label4.TabIndex = 0;this.label4.Text = 發(fā)送信息;/ / groupBox1/ this.groupBox1.Controls.Add(this.listBoxState);this.groupBox1.Location = new System.Drawing.Point(216, 16);this.groupBox1.Name = groupBox1;this.groupBox1.TabIndex = 1;this.groupBox1.TabStop = false;this.groupBox1.Text = 服務(wù)器狀態(tài);/ / listBox
20、State/ this.listBoxState.ItemHeight = 12;this.listBoxState.Location = new System.Drawing.Point(8, 16);this.listBoxState.Name = listBoxState;this.listBoxState.Size = new System.Drawing.Size(184, 76);this.listBoxState.TabIndex = 0;/ / textBoxIP/ this.textBoxIP.Location = new System.Drawing.Point(72, 3
21、2);this.textBoxIP.Name = textBoxIP;this.textBoxIP.ReadOnly = true;this.textBoxIP.Size = new System.Drawing.Size(128, 21);this.textBoxIP.TabIndex = 2;this.textBoxIP.Text = ;/ / textBoxPort/ this.textBoxPort.Location = new System.Drawing.Point(72, 72);this.textBoxPort.Name = textBoxPort;this.
22、textBoxPort.ReadOnly = true;this.textBoxPort.TabIndex = 3;this.textBoxPort.Text = 6788;/ / buttonStart/ this.buttonStart.Location = new System.Drawing.Point(56, 320);this.buttonStart.Name = buttonStart;this.buttonStart.TabIndex = 5;this.buttonStart.Text = 開始監(jiān)聽;this.buttonStart.Click += new System.Ev
23、entHandler(this.buttonStart_Click);/ / buttonSend/ this.buttonSend.Location = new System.Drawing.Point(168, 320);this.buttonSend.Name = buttonSend;this.buttonSend.TabIndex = 5;this.buttonSend.Text = 發(fā)送信息;this.buttonSend.Click += new System.EventHandler(this.buttonSend_Click);/ / buttonStop/ this.but
24、tonStop.Location = new System.Drawing.Point(288, 320);this.buttonStop.Name = buttonStop;this.buttonStop.TabIndex = 5;this.buttonStop.Text = 停止監(jiān)聽;this.buttonStop.Click += new System.EventHandler(this.buttonStop_Click);/ / richTextBoxAccept/ this.richTextBoxAccept.Location = new System.Drawing.Point(7
25、2, 120);this.richTextBoxAccept.Name = richTextBoxAccept;this.richTextBoxAccept.Size = new System.Drawing.Size(344, 96);this.richTextBoxAccept.TabIndex = 6;this.richTextBoxAccept.Text = richTextBoxAccept;/ / richTextBoxSend/ this.richTextBoxSend.Location = new System.Drawing.Point(72, 224);this.richT
26、extBoxSend.Name = richTextBoxSend;this.richTextBoxSend.Size = new System.Drawing.Size(344, 80);this.richTextBoxSend.TabIndex = 6;this.richTextBoxSend.Text = richTextBoxSend;/ / Form1/ this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);this.ClientSize = new System.Drawing.Size(432, 349);this.Con
27、trols.Add(this.richTextBoxAccept);this.Controls.Add(this.buttonStart);this.Controls.Add(this.textBoxPort);this.Controls.Add(this.textBoxIP);this.Controls.Add(this.groupBox1);this.Controls.Add(this.label1);this.Controls.Add(this.label2);this.Controls.Add(this.label3);this.Controls.Add(this.label4);th
28、is.Controls.Add(this.buttonSend);this.Controls.Add(this.buttonStop);this.Controls.Add(this.richTextBoxSend);this.Name = Form1;this.Text = 服務(wù)器;this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);this.Load += new System.EventHandler(this.Form1_Load);this.groupBox1.ResumeLa
29、yout(false);this.ResumeLayout(false);#endregion/ / 應(yīng)用程序的主入口點。/ STAThreadstatic void Main() Application.Run(new Form1();private void buttonStart_Click(object sender, System.EventArgs e)this.buttonStart.Enabled=false;IPAddress ip=IPAddress.Parse(this.textBoxIP.Text);IPEndPoint server=new IPEndPoint(ip
30、,Int32.Parse(this.textBoxPort.Text);socket=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);socket.Bind(server);/監(jiān)聽客戶端連接socket.Listen(10);clientSocket=socket.Accept();/顯示客戶IP和端口號this.listBoxState.Items.Add(與客戶 +clientSocket.RemoteEndPoint.ToString()+ 建立連接);/創(chuàng)建一個線程接收客戶信息threa
31、d=new Thread(new ThreadStart(AcceptMessage);thread.Start();private void AcceptMessage()while(true)tryNetworkStream netStream=new NetworkStream(clientSocket);byte datasize=new byte4;netStream.Read(datasize,0,4);int size=System.BitConverter.ToInt32(datasize,0);Byte message=new bytesize;int dataleft=si
32、ze;int start=0;/while(dataleft0)int recv=netStream.Read(message,start,dataleft);/start+=recv;/dataleft-=recv;/string gg;/gg=message.ToString();this.richTextBoxAccept.Rtf=System.Text.Encoding.Unicode.GetString(datasize);catchthis.listBoxState.Items.Add(與客戶斷開連接);break;private void buttonSend_Click(obj
33、ect sender, System.EventArgs e)string str=this.richTextBoxSend.Rtf;int i=str.Length;if(i=0)return;else /因為str為Unicode編碼,每個字符占2字節(jié),所以實際字節(jié)數(shù)應(yīng)*2i*=2;byte datasize=new byte4; /將32位整數(shù)值轉(zhuǎn)換為字節(jié)數(shù)組datasize=System.BitConverter.GetBytes(i);byte sendbytes=System.Text.Encoding.Unicode.GetBytes(str);tryNetworkStream
34、netStream=new NetworkStream(clientSocket);netStream.Write(datasize,0,4);netStream.Write(sendbytes,0,sendbytes.Length);netStream.Flush();this.richTextBoxSend.Rtf=;catchMessageBox.Show(無法發(fā)送!);private void buttonStop_Click(object sender, System.EventArgs e)this.buttonStart.Enabled=true;trysocket.Shutdo
35、wn(SocketShutdown.Both);socket.Close();if(clientSocket.Connected)clientSocket.Close();thread.Abort();catchMessageBox.Show(監(jiān)聽尚未開始,關(guān)閉無效!);private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)trysocket.Shutdown(SocketShutdown.Both);socket.Close();if(clientSocket.Connected)c
36、lientSocket.Close();thread.Abort();catch/客戶端using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Net;using System.Net.Sockets;using System.Threading;using System.Runtime.Serialization.Formatters.Binary;using
37、System.Runtime.Serialization;namespace TestSyncClient/ / Form1 的摘要說明。/ public class Form1 : System.Windows.Forms.Formprivate Socket socket;private Thread thread; public static int fs=0;private System.Windows.Forms.Label label1;private System.Windows.Forms.Label label2;private System.Windows.Forms.La
38、bel label3;private System.Windows.Forms.Label label4;private System.Windows.Forms.GroupBox groupBox1;private System.Windows.Forms.TextBox textBoxIP;private System.Windows.Forms.TextBox textBoxPort;private System.Windows.Forms.Button buttonRequest;private System.Windows.Forms.Button buttonSend;privat
39、e System.Windows.Forms.Button buttonClose;private System.Windows.Forms.ListBox listBoxState;private System.Windows.Forms.RichTextBox richTextBoxSend;private System.Windows.Forms.RichTextBox richTextBoxReceive;private System.Windows.Forms.Button button1;private System.Windows.Forms.TextBox textBox1;/
40、 / 必需的設(shè)計器變量。/ private System.ComponentModel.Container components = null;public Form1()/ Windows 窗體設(shè)計器支持所必需的/InitializeComponent();/ TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼/this.richTextBoxSend.Text=;this.richTextBoxReceive.Text=;this.listBoxState.Items.Clear();this.textBox1.Text=fs.ToString();/ /
41、清理所有正在使用的資源。/ protected override void Dispose( bool disposing )if( disposing )if (components != null) components.Dispose();base.Dispose( disposing );#region Windows 窗體設(shè)計器生成的代碼/ / 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改/ 此方法的內(nèi)容。/ private void InitializeComponent()this.label1 = new System.Windows.Forms.Label();this.
42、label2 = new System.Windows.Forms.Label();this.label3 = new System.Windows.Forms.Label();this.label4 = new System.Windows.Forms.Label();this.groupBox1 = new System.Windows.Forms.GroupBox();this.listBoxState = new System.Windows.Forms.ListBox();this.textBoxIP = new System.Windows.Forms.TextBox();this
43、.textBoxPort = new System.Windows.Forms.TextBox();this.buttonRequest = new System.Windows.Forms.Button();this.buttonSend = new System.Windows.Forms.Button();this.buttonClose = new System.Windows.Forms.Button();this.richTextBoxSend = new System.Windows.Forms.RichTextBox();this.richTextBoxReceive = ne
44、w System.Windows.Forms.RichTextBox();this.button1 = new System.Windows.Forms.Button();this.textBox1 = new System.Windows.Forms.TextBox();this.groupBox1.SuspendLayout();this.SuspendLayout();/ / label1/ this.label1.Location = new System.Drawing.Point(11, 31);this.label1.Name = label1;this.label1.Size
45、= new System.Drawing.Size(85, 29);this.label1.TabIndex = 0;this.label1.Text = 服務(wù)器IP;/ / label2/ this.label2.Location = new System.Drawing.Point(11, 93);this.label2.Name = label2;this.label2.Size = new System.Drawing.Size(85, 29);this.label2.TabIndex = 0;this.label2.Text = 請求端口;/ / label3/ this.label
46、3.Location = new System.Drawing.Point(11, 154);this.label3.Name = label3;this.label3.Size = new System.Drawing.Size(85, 30);this.label3.TabIndex = 0;this.label3.Text = 接收信息;/ / label4/ this.label4.Location = new System.Drawing.Point(11, 267);this.label4.Name = label4;this.label4.Size = new System.Dr
47、awing.Size(85, 30);this.label4.TabIndex = 0;this.label4.Text = 發(fā)送信息;/ / groupBox1/ this.groupBox1.Controls.Add(this.listBoxState);this.groupBox1.Location = new System.Drawing.Point(267, 10);this.groupBox1.Name = groupBox1;this.groupBox1.Size = new System.Drawing.Size(266, 129);this.groupBox1.TabInde
48、x = 1;this.groupBox1.TabStop = false;this.groupBox1.Text = 程序狀態(tài);/ / listBoxState/ this.listBoxState.ItemHeight = 15;this.listBoxState.Location = new System.Drawing.Point(11, 21);this.listBoxState.Name = listBoxState;this.listBoxState.Size = new System.Drawing.Size(245, 79);this.listBoxState.TabIndex = 0;/ / textBoxIP/ this.textBoxIP.Location = new System.Drawing.Point(107, 31);this.textBoxIP.Name = textBoxIP;this.textBoxIP.ReadOnly = true;this.textBoxIP.Size = new System.Drawing.Size(133, 25);this.textBoxIP.TabIndex = 2;this.textBoxIP.Text = ;/ / textBoxPort/ this.text
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 陜西省商洛市商南縣2024-2025學(xué)年八年級上學(xué)期期末生物學(xué)試題(含答案)
- 湖南省邵陽市新邵縣第二中學(xué)2024-2025學(xué)年高三下學(xué)期2月開學(xué)考試生物學(xué)試題(含答案)
- 小學(xué)生作文素材故事解讀
- 風(fēng)險評估與應(yīng)對策略分析表
- 蓋板制作工程 現(xiàn)場質(zhì)量檢驗報告單
- 基于人工智能的智能交通管理系統(tǒng)預(yù)案
- 餐飲行業(yè)廚師勞動合同
- 年度辦公室工作任務(wù)安排表
- 如何理解和運用動詞:七年級英語語法專題
- 初中語法銜接教學(xué)方案:go與going的區(qū)別
- 《新能源汽車動力電池技術(shù)》課件
- 婦女健康 知識講座課件
- (已壓縮)礦產(chǎn)資源儲量技術(shù)標(biāo)準(zhǔn)解讀300問-1-90
- 醫(yī)院培訓(xùn)課件:《靜脈中等長度導(dǎo)管臨床應(yīng)用專家共識》
- 2023江蘇護理職業(yè)學(xué)院高職單招語文/數(shù)學(xué)/英語筆試參考題庫含答案解析
- 高二數(shù)學(xué)平面向量的基本定理
- 高中美術(shù)-美術(shù)鑒賞《審美自律》
- 強讀和弱讀-(課堂)課件
- 裕興新概念英語第二冊筆記第42課
- 管理高爾夫?qū)崙?zhàn)訓(xùn)練課程課件
- 2022年義務(wù)教育語文課程標(biāo)準(zhǔn)(2022版)解讀【新課標(biāo)背景下的初中名著閱讀教學(xué)質(zhì)量提升思考】
評論
0/150
提交評論