![數(shù)據(jù)通信實驗中的套接字編程(中英文對照)_第1頁](http://file2.renrendoc.com/fileroot_temp3/2021-6/19/8a7c74c0-1935-4cb1-a196-ed89c9ca8fef/8a7c74c0-1935-4cb1-a196-ed89c9ca8fef1.gif)
![數(shù)據(jù)通信實驗中的套接字編程(中英文對照)_第2頁](http://file2.renrendoc.com/fileroot_temp3/2021-6/19/8a7c74c0-1935-4cb1-a196-ed89c9ca8fef/8a7c74c0-1935-4cb1-a196-ed89c9ca8fef2.gif)
![數(shù)據(jù)通信實驗中的套接字編程(中英文對照)_第3頁](http://file2.renrendoc.com/fileroot_temp3/2021-6/19/8a7c74c0-1935-4cb1-a196-ed89c9ca8fef/8a7c74c0-1935-4cb1-a196-ed89c9ca8fef3.gif)
![數(shù)據(jù)通信實驗中的套接字編程(中英文對照)_第4頁](http://file2.renrendoc.com/fileroot_temp3/2021-6/19/8a7c74c0-1935-4cb1-a196-ed89c9ca8fef/8a7c74c0-1935-4cb1-a196-ed89c9ca8fef4.gif)
![數(shù)據(jù)通信實驗中的套接字編程(中英文對照)_第5頁](http://file2.renrendoc.com/fileroot_temp3/2021-6/19/8a7c74c0-1935-4cb1-a196-ed89c9ca8fef/8a7c74c0-1935-4cb1-a196-ed89c9ca8fef5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、數(shù)據(jù)通信實驗中的套接字編程 摘要雖然許多數(shù)據(jù)通信的課程都沒有教授編程方面的內(nèi)容,但計算機(jī)專業(yè)課程的規(guī)劃應(yīng)該包括編程。許多有編程內(nèi)容的數(shù)據(jù)通信課程當(dāng)處理詳細(xì)的網(wǎng)絡(luò)層工程時利用了pc上的連續(xù)端口。unix套接字編程允許學(xué)生們處理同樣的事情和問題,但是從文章中它看起來更有用,而且更有趣。另外,如果套接字類使用c+,希望得到的對套接字的操作差不多都可以呈現(xiàn)出來。 序論數(shù)據(jù)通信是大多數(shù)管理信息系統(tǒng)(mis)以及服務(wù)器/客戶端(c/s)程序標(biāo)準(zhǔn)的一部分。目前作為課程廣泛改善實行的證據(jù)是提供教材的變化。許多教材,無論是針對mis還是cs,都很少或沒有提供實驗活動。mis編程趨向強(qiáng)調(diào)數(shù)據(jù)通信和網(wǎng)絡(luò)的管理。最近
2、的新聞列表顯示了對使用數(shù)據(jù)通信和通信所提供的種類和方式的調(diào)查。無論國內(nèi)或國外,合作方案都非常流行。cs編程會使用一些非常技術(shù)和寬泛的教材。很明顯,一個工程的規(guī)劃需要更多廣泛和詳細(xì)的課程去研究數(shù)據(jù)通信的物理和結(jié)構(gòu)方面。實驗可能的類型同樣很廣泛。“全球合作模型”強(qiáng)迫教給我們數(shù)據(jù)通信如何工作,以用于復(fù)雜的通信機(jī)制和提供一個解釋這些系統(tǒng)功能的基礎(chǔ)?;谔峁┑馁Y源,去考慮通過允許學(xué)生嘗試通信的不同的物理和邏輯類型的設(shè)計選擇。另一個極端是強(qiáng)調(diào)低水平的,數(shù)據(jù)通信物理理解的練習(xí)幾乎是一個工程逼近。一個典型的例子是使用pc上連續(xù)的端口。除了編寫代碼去操作物理硬盤之外,更多復(fù)雜的概念將被研究。在作者過去使用過的資
3、料中,利用一個bisynch協(xié)議和令牌環(huán)來實現(xiàn)文件傳送的分配。這個實驗步驟包括基于一個發(fā)展中的iso osi數(shù)據(jù)鏈路層的大規(guī)模工程。這些步驟中沒有提供實際可操作的硬件經(jīng)驗。除了這張紙中的練習(xí),作者還安排了一個通過硬件和軟件的安裝將pc機(jī)聯(lián)網(wǎng)的工程。服務(wù)器需要額外的安裝和配置。當(dāng)套接字模型被采用時,這樣一個工程就可以繼續(xù)下去。這里的步驟呈現(xiàn)了為學(xué)生們提供了一個數(shù)據(jù)通信和網(wǎng)絡(luò)的廣闊視角。 unix套接字簡單地講,套接字是一個機(jī)制,在相同或不同的機(jī)器上實現(xiàn)信息傳送的過程。如果這個過程在同樣的機(jī)器上,套接字可以用作管道。intetnet套接字允許運(yùn)行在不同的機(jī)器之間的通信。這個系統(tǒng)與file i/o擁
4、有同樣的調(diào)用。套接字編程的一個典型的步驟是創(chuàng)建一個過程,打開服務(wù)器套接字端口和偵聽另一個嘗試連接的過程??蛻舳丝梢杂门c服務(wù)器端套接字同樣的端口號打開一個套接字,請求服務(wù)連接。如果服務(wù)器偵聽到這個請求,就建立了一個連接。通信使用read( )和write()函數(shù)繼續(xù)。通信有許多標(biāo)準(zhǔn)協(xié)議的類型,比較普遍地兩種是udp(udp ,user datagram protocol, 用戶數(shù)據(jù)報協(xié)議)和tcp(tcp ,transmission control protocol, 傳輸控制協(xié)議)。兩種協(xié)議都是經(jīng)過一個套接字過程傳送信息包。udp不提供一個數(shù)據(jù)被接收或者大量信息包被順序接收的保證。tcp是一個
5、可靠的和有次序的流協(xié)議。程序員在tcp套接字上輸入和輸出,作為一個來自終端或文件的字節(jié)流出現(xiàn)。如果tcp數(shù)據(jù)在一個合理的時間內(nèi)不能被成功傳送,將會顯示一個錯誤。由于在udp中涉及比較少的開頭部分,如果有次序收到數(shù)據(jù)非常重要,程序也就必須更加復(fù)雜。兩個過程之間的套接字連接是兩臺主機(jī)/端口對之間的連接,端口號指示了提供的特殊服務(wù)。許多經(jīng)tcp套接字的服務(wù)通常提供一個可識別的首字母縮寫詞:像smtp(smtp ,simple message transport protocol, 簡單郵件傳輸協(xié)議, 用于電子郵件的傳輸),nntp(nntp,network news transport protoc
6、ol,網(wǎng)絡(luò)新聞傳輸協(xié)議(use-net))和ftp(ftp,file transfer protocol , 文件傳送輸協(xié)議)。telnet(telnet,用于遠(yuǎn)程聯(lián)接服務(wù)的標(biāo)準(zhǔn)協(xié)議或者實現(xiàn)此協(xié)議的軟件)是另外的套接字服務(wù)。unix提供了一種機(jī)制,憑借著提供服務(wù)的名字能夠譯出端口號。 套接字的優(yōu)勢數(shù)據(jù)通信實驗中利用套接字編程的一個明顯的缺點(diǎn)是沒有像pc機(jī)連續(xù)端口那樣多的直接硬件交互。然而,多數(shù)大學(xué)生不會處在這樣詳細(xì)的知識會很重要的情形中。即使有連續(xù)的端口,這個概念對許多學(xué)生來說仍然很抽象?;谔捉幼植襟E地優(yōu)勢是它將套接字的抽象變得很具體。在過去,基于pc機(jī)實驗的一個優(yōu)勢是費(fèi)用的低廉。然而,至少
7、有兩個因素來平衡這種優(yōu)勢。一是現(xiàn)在unix工作站普遍使用,pc可以通過安裝unix的免費(fèi)版本來轉(zhuǎn)換成工作站。另一個因素是,即使pc給相對便宜,實際上會出現(xiàn)老化,不穩(wěn)定,機(jī)器被分配到一個像數(shù)據(jù)通信實驗這樣專注的工程。我們的經(jīng)驗是我們可以負(fù)擔(dān)得起使用的機(jī)器都非常不穩(wěn)定。雖然套接字編程的“高起點(diǎn)”的本性已經(jīng)作為一個優(yōu)勢強(qiáng)調(diào)了,但使得分配像我們所希望的那樣詳細(xì)同樣是可能的。沒有任何軟件支持的套接字編程需要大量“低起點(diǎn)”的理解和操作。一個簡單是修改將是基于udp包而不是tcp包的分配。許多附加的程序(經(jīng)crc(循環(huán)冗余碼校驗)的錯誤校驗、順序數(shù)字、接收的確認(rèn)、接收錯誤的否定確認(rèn))都是必要的。無論是udp
8、或是tcp包,適當(dāng)?shù)脑O(shè)計握手機(jī)制對文件傳輸這樣的程序來說都是必要的。通過連續(xù)的端口分配,課程時間就可以投入到作為控制、狀態(tài)、數(shù)據(jù)記錄和類似連續(xù)轉(zhuǎn)換的低起點(diǎn)概念中。通過一個套接字步驟,就可以討論像信息報頭、網(wǎng)絡(luò)和機(jī)器字節(jié)順序這樣類似的概念了。如果愿意,連續(xù)端口通信的許多適當(dāng)?shù)闹黝}都可以成為套接字程序和給出的許多相同分配的必須。即使分配了高起點(diǎn)的應(yīng)用,學(xué)生們?nèi)匀槐仨毨斫饬骱途彌_區(qū)之間的不同。 c+套接字類的優(yōu)勢許多參考書提供了套接字通信的詳細(xì)情形,這些參考書提供了任務(wù)的例子和方法。所有建立通信、把通信轉(zhuǎn)換成緩沖區(qū)流和錯誤校驗的詳細(xì)情況都可以由unix系統(tǒng)調(diào)用完成。許多低起點(diǎn)的理解對于編寫穩(wěn)定的應(yīng)用
9、程序來說是必須的。一個設(shè)計得很好的c+類可以被構(gòu)建用于使用簡單的語義學(xué)提供套接字的完全功能。編寫客戶到建立的服務(wù)器、事件驅(qū)動服務(wù)器和輪流檢測服務(wù)器是可能的。作者提供了一組c+類,這些程序都是在gnu下編寫的。他們是由 提供的。這些類對給出的任務(wù)表現(xiàn)出了非常好的功能。它的接口與輸入輸出流和提供安全類型的輸入輸出一樣。在udp和tcp域中有套接字流類,就像其中有管道流類一樣。套接字緩沖區(qū)類來源于流緩沖區(qū)類。這樣,學(xué)生們必須學(xué)習(xí)關(guān)于沒有套接字輸入與輸出的流和緩沖區(qū)。套接字緩沖區(qū)類包括錯誤功能、準(zhǔn)備好檢測、直接操作、上溢出、下溢出和超時功能。套接字選項如消息路由、局部地
10、址的再使用、廣播等等都要設(shè)置。這樣,套接字的詳細(xì)情形就可以如希望的那樣了。在我們特殊的課程中,使用這些c+類一方面的益處是學(xué)生們必須在一年級/二年級的水平課程中使用到c+語言,幫助他們保持學(xué)到的技能。 任務(wù)在選擇一個為期三學(xué)期的課程任務(wù)時,我們渴望實現(xiàn)很多目標(biāo)。我們被希望設(shè)計出一系列的任務(wù)來讓學(xué)生編寫一個客戶端的應(yīng)用、一個服務(wù)器的應(yīng)用、一個對等網(wǎng)絡(luò)應(yīng)用,也提供一些像電子郵件和文件傳輸這樣一些標(biāo)準(zhǔn)應(yīng)用的經(jīng)驗。另外,任務(wù)應(yīng)該由簡單到復(fù)雜,循序漸進(jìn)。我們在下面列出了這些任務(wù)要點(diǎn)。這些任務(wù)得到了學(xué)生們的良好反響。他們感覺到了實踐的樂趣,同時,也有了一個好的計劃。一些以前沒有接觸過它們的學(xué)生經(jīng)過努力也都
11、有非常好的結(jié)果。這五項明確的任務(wù)是: 任務(wù)一:套接字客戶端到電子郵件服務(wù)器在本地或遠(yuǎn)程的機(jī)器上編寫一個客戶端程序去連接電子郵件服務(wù)器,然后發(fā)送一封電子郵件到一個用戶名(userid在電子郵件地址中符號之前的名稱)。用戶不必要是本地或遠(yuǎn)程機(jī)器上的。例如,這個程序可能叫做smtp,包括兩項任務(wù):主機(jī)名和用戶名。我們要求有一個簡單的命令行接口,但是學(xué)生們可以自由地發(fā)揮,做出更多精致的電子郵件類型接口來。smtp(smtp simple message transfer protocol, 簡單郵件傳輸協(xié)議, 用于電子郵件的傳輸)的命令是一定會用到的。列舉一些如下:helo localname 確認(rèn)連
12、接機(jī)器本地名稱不需要一些服務(wù)器不需要helo,但一些要包括。help 發(fā)送命令列表mail from:name 可以是你愿意的任何東西不經(jīng)過合法性的檢驗rcpt to:name 郵件的容器不需要是本地名稱data 允許信息進(jìn)入以“.”作為消息的終止字符quit 斷開連接同其他的任務(wù)一樣,這個任務(wù)也會帶給學(xué)生一些不合適的活動。下面是提給學(xué)生們的一些警告:顯然你可能在程序中做一些不禮貌的事情。例如,你可能從daffy duck那里發(fā)送一串管理員的消息。這需要一些工作量,但這些消息的發(fā)送人將會被記錄。請不要熱衷于這樣幼稚的行為。一些人可能會爭辯說這樣的任務(wù)太“危險” ,但是學(xué)生們可以學(xué)到如何操作套接
13、字,能夠解決如何自己發(fā)送郵件的問題。我們的方法是承認(rèn)這樣一個問題的存在并提出警告。 任務(wù)二:簡單的網(wǎng)絡(luò)信息服務(wù)器編寫一個有如下特征的網(wǎng)絡(luò)服務(wù)器程序:1. 從輸入套接字接受命令2. 解釋命令并集合信息3. 發(fā)送輸出命令到輸出套接字你不需要為這個任務(wù)編寫一個客戶端程序,因為標(biāo)準(zhǔn)的telnet(telnet用于遠(yuǎn)程聯(lián)接服務(wù)的標(biāo)準(zhǔn)協(xié)議或者實現(xiàn)此協(xié)議的軟件,遠(yuǎn)程登錄)客戶端將可以提供這樣的功能。telnet允許你在客戶端上給一個服務(wù)器過程發(fā)送信息并把握返回信息。一個信息的選擇提供系統(tǒng)命令,像域名等等。系統(tǒng)的功能可以從一個c+程序內(nèi)部執(zhí)行。困難的部分是將命令的輸出并發(fā)送輸出到套接字與客戶端連接起來。命令的
14、輸出應(yīng)該與套接字直接連接。建議有兩種途徑:用管道流類和用傳統(tǒng)的通過用戶構(gòu)造管道連接的c fork()來執(zhí)行系統(tǒng)功能。 任務(wù)三:對等網(wǎng)絡(luò)套接字通信編寫一個作為兩個相同程序執(zhí)行的“聊天”程序。它應(yīng)該允許用戶自定義連接過程的輸出所出現(xiàn)的信息。這兩個過程經(jīng)過一個套接字連接。程序?qū)⒃试S用戶連接一個確定的過程并監(jiān)聽另一個試圖連接的處理。兩臺機(jī)器上運(yùn)行相同的程序,任務(wù)必須包括這些要點(diǎn):監(jiān)聽的超時、通過服務(wù)器程序創(chuàng)建子進(jìn)程、關(guān)閉套接字并終止子進(jìn)程。一個有限狀態(tài)過渡模型應(yīng)該呈現(xiàn)出來幫助程序的設(shè)計。 任務(wù)四:文件傳輸服務(wù)器和客戶端通過tcp/ip網(wǎng)絡(luò)套接字連接編寫一個文件傳輸程序。第一個程序應(yīng)該與一個ftp服務(wù)器
15、功能相同。它應(yīng)該在幕后運(yùn)行并等待一個指定端口的連接。第二個程序應(yīng)該與一個ftp客戶端功能相同。因此,需要一個用戶接口。命令將通過響應(yīng)進(jìn)入并發(fā)送到服務(wù)器。文件應(yīng)該可以進(jìn)行雙向傳輸??蛻舳顺绦驊?yīng)該通過響應(yīng)行為接受下列命令:ls 服務(wù)器上文件列表put 從客戶端到服務(wù)器傳送文件get 從服務(wù)器到客戶端傳送文件quit 斷開與服務(wù)器的連接:<command> 在客戶端執(zhí)行<command>這對服務(wù)器/客戶端的性能比ftp要簡單許多。sftp(簡單文件傳輸協(xié)議)與它類似。舉例來說,ftp運(yùn)用2個tcp連接,其中一個類似telnet連接用于控制,另一個作數(shù)據(jù)傳輸。sftp用一個簡單
16、的tcp連接并提供用戶訪問控制,目錄列表和變更,文件重命名和文件刪除。對于這些命令,這里只有目錄列表是需要的。ftp同樣支持lcd、mput、mget等等。這個任務(wù)需要一個握手協(xié)議。 任務(wù)五:三個選擇任務(wù)五a:使用udp的ftp文件傳輸建立udp套接字而不是tcp套接字執(zhí)行任務(wù)4的文件傳輸程序。這個程序需要:集合數(shù)據(jù)包 提供crc錯誤校驗 提供包的先后順序數(shù)據(jù)包可能不是按照順序到達(dá),可能重復(fù)或丟失,需要重新請求或重新排列。每個數(shù)據(jù)包應(yīng)該被確認(rèn)(肯定地或否定地)。我們將采用一個協(xié)議來描述數(shù)據(jù)包的格式和錯誤信息等等。為了測驗使用的協(xié)議,允許用戶指定傳輸中將會出錯的部分。任務(wù)五b:雙向文件傳輸改為打
17、開2個套接字執(zhí)行任務(wù)4的文件傳輸程序,一個用于控制信息一個用于數(shù)據(jù)傳輸。另外,允許兩個程序同時來回地發(fā)送文件,通過控制信道取消傳送過程。使用多個子進(jìn)程將是有益的。(一個有限狀態(tài)機(jī)器將會是一個好方法)。ftp有著相似的工作方式。它有兩個套接字連接,但是基于不同的原因,因為在這里它執(zhí)行的是一個真正的服務(wù)器客戶端協(xié)議,而不是對等網(wǎng)絡(luò)協(xié)議。 任務(wù)五c:多用戶聊天程序任務(wù)三涉及了對等網(wǎng)絡(luò)聊天程序。這個任務(wù)需要多路技術(shù)創(chuàng)造聊天服務(wù)器的程序,它能夠把握多重的套接字連接。沒有必要編寫客戶端程序因為可以使用telnet。服務(wù)器可以從任何套接字接受輸入行并把它們輸出到剩余的套接字連接。當(dāng)一個用戶連接到聊天服務(wù)器,
18、服務(wù)器應(yīng)該及時提供一個用戶名。這個名字應(yīng)該被廣播到其余的用戶。在用戶離開時同樣要廣播一條消息。當(dāng)一個用戶的消息被發(fā)送到其它連接的用戶時,應(yīng)提供用戶名以供辨認(rèn)。 結(jié)論重新設(shè)計數(shù)據(jù)通信課程實驗內(nèi)容的目的是提供這樣的一些任務(wù): 給學(xué)生們更有意義和更實際的內(nèi)容 更另人愉快的,因此也能更好完成的內(nèi)容 更現(xiàn)代,但仍然強(qiáng)調(diào)對所發(fā)生內(nèi)容的理解而不僅僅是利用數(shù)據(jù)通信 循序漸進(jìn),環(huán)環(huán)相扣 基于更加可靠的硬件,丟棄了以前使用的pc機(jī)一旦這個套接字范例被選用,目的在于創(chuàng)造一些任務(wù)需要學(xué)生編寫這樣的代碼: 利用c+類 提供一個簡單的客戶端有權(quán)使用定義明確的服務(wù)器 提供簡單的服務(wù)器功能 提供對等網(wǎng)絡(luò)通信 提供多路技術(shù)服務(wù)
19、器功能 通過一種方式實現(xiàn)一個類似于眾所周知網(wǎng)絡(luò)服務(wù)的功能 需要學(xué)生們關(guān)注可靠通信 使用一些fork()形態(tài)并進(jìn)行進(jìn)程間通信編程這些任務(wù)在學(xué)生們中得到了非常好的反響。好學(xué)生發(fā)現(xiàn)通過設(shè)計好的用戶接口或提供增加功能性來增強(qiáng)計劃的方法?;A(chǔ)不是很好的學(xué)生能夠完成任務(wù)并發(fā)現(xiàn)它們同樣有意義和有趣。作者在一所小的自由技術(shù)大學(xué)教授電腦科學(xué)的二十年中,這種實驗任務(wù)的變化就像其它任何一門課程的變化一樣地被接受了。 附原文:socket programming in the data communications laboratorywilliam e. tollcomputing and system scien
20、cestaylor universityupland, in 46989abstractalthough many data communications courses are taught with no programming content courses designed for computer science majors should include programming. many data communications courses with a programming component make use of serial p
21、orts on pcs while some deal with detailed network layer projects. unix socket programming allows the students to deal with the same issues and problems, but in a context that is more likely be useful and that is more interesting. in addition, if socket classes are used with c+, only as much detail o
22、f socket operation as desired need be presented.lntroductiondata communications is a standard part of most mis and cs programs. the actual implementation of the course varies widely as evidenced by the variety of text books available. many texts, whether oriented toward mis or cs, provide little or
23、no laboratory activity. mis programs tend to emphasize management of data communications and networks. recent news lists postings indicate an emphasis on using data communications and investigations of the types and styles of communication available. national, or international, cooperative projects
24、are popular. cs programs may use very technical texts or a broad text such as used by the author 1 where principles, design approaches, and standards are emphasized. obviously, an engineering program would have a much more extensive and detailed course(s) to investigate the physical and structural a
25、spects of data communication. the course taught by the author is required of all cs majors. students in the course maybe in any of the specialized tracks (artificial intelligence, business information systems, graphics or scientific programming) as well as a more generic cs major. the possible types
26、 of laboratory experiences are also broad. the “global cooperation model” teaches how data communications works by forcing students to use sophisticated communications mechanisms and provides a basis for explaining how these systems function. it is possible, based on the available resources, to cons
27、ider design alternatives by allowing students to explore different physical or logical types of communication. at the other extreme are exercises that emphasize low-level physical understanding of data communications - almost an engineering approach. atypical example would be the use of serial ports
28、 on pcs. in addition to writing code to manipulate the physical hardware, many more complicated concepts can be studied. in material the author has used in the past, file transfer assignments using a modified bisynch protocol and token rings are implemented 2. an alternative low-level approach is mo
29、deled by the netcp software 3. this laboratory approach involves a large scale project based on developing the 0s11s0 data link layer.none of these approaches provide practical hands-on hardware experience. in addition to the exercises described in this paper, the author assigns a project involving
30、installation of hardware and software to add a pc to a network. a server can be installed and configured for extra credit. such a project was continued when the socket model was adopted.students placed in practical or in their first job have considered the data communications course important. they
31、have typically not believed the pc serial port programming to be important, however. the approach presented here is designed to provide abroad overview of data communication and network issues to our students. the goals for the laboratory part of the data communications course are presented later in
32、 the paper.unix socketssimply stated sockets area mechanism by which messages may be sent between processes on the same or different machines. if the processes are on the same machine, the sockets may be used as pipes. internet sockets allow communication between processes running on different machi
33、nes. the system calls are the same as file i/o. a typical approach to socket programming is to create a process that opens a sewer socket port and listens for another process to attempt connection. a client can open a socket, with the same port number as the server socket, requesting connection to t
34、he service. when the server hears the request a connection is established. communication can now proceed with read() and write().there are many types of standard protocols. two of the most common are udp (user datagram protocol) and tcp (transmission control protocol). both protocols transmit packet
35、s of information between processes via a socket. udp does not provide a guarantee that data will be received or that a multiple packet transmission will be received in order. tcp is a stream protocol that is reliable and sequenced. to the programmer input and output on a tcp socket appears as a byte
36、 stream from a terminal or a file. if tcp data cannot be transmitted successfully within a reasonable amount of time, an error is indicated. there is less overhead involved in udp, but programming must be much more sophisticated if orderly message receipt is important.the socket connection between t
37、wo processes is a connection between host. port pairs where the port number indicates a particular service that is made available. many of the services commonly available via tcp sockets are recognizable acronyms: smtp (simple mail transport protocol used for e-mail), nntp (network news transport pr
38、otocol, used for usenet news) and fit (file transport protocol). telnet and rsh are additional socket services. unix provides a mechanism whereby the name of an available services is translated to a port number.sockets are also used for the interprocess communication necessary in concurrent or paral
39、lel processing. therefore, parallel processing assignments as well as data communications projects can be built on the same framework.advantages of socketsone obvious disadvantage of using socket programming for the data communications lab is that there is less direct hardware interaction than with
40、pc serial ports. however, most graduates will not be in situations where such detailed knowledge will be important. even with the serial port approach the concepts have remained somewhat abstract to many students the socket based approach has the advantage that the abstract concepts of sockets (and
41、practical uses such as mail, telnet, etc.) become much more concrete.one advantage that pc based labs have had in the past is that they were inexpensive. however, there are at least two factors that balance this advantage. one is that unix workstations are now commonly available. pc labs can be conv
42、erted to workstations by installing free versions of unix. since most, if not all, socket assignments given in a data communications course are not compute intensive and do not require a graphical interface, workstations need not be dedicated to the course as would be true of pcs. another factor is
43、that even though pcs are relatively inexpensive, what happens practically is that older, less reliable, machines are assigned to a dedicated project such as a data communications lab. our experience was that the machines we could “afford” to use were quite unreliable.although the “high level” nature
44、 of socket programming has been stressed as an advantage, it is possible to make the assignments as detailed as desired. socket programming without any support software can require a great deal of “l(fā)ow level” understanding and manipulation. one simple modification would be to base assignments on udp
45、 packets rather than tcp packets. much additional programming (error checking via crcs, sequence numbers, acknowledgment of receipt negative acknowledgment for receipt of a bad packet) would be necessary. with either udp or tcp packets, properly designed handshaking mechanisms may be necessary for s
46、uch applications as file transfer.with serial port assignments, lecture time was devoted to such low level concepts as control, status and data registers, and parallel to serial conversion. with a socket based approach analogous concepts such as packet headers and network and machine byte order can
47、be discussed. if desired many of the topics appropriate for serial port communication can be required for socket programs and many of the same assignments can be given. even if high level applications are assigned, the students must still understand the differences between streams and buffers.advant
48、ages of c+ socket classesmany references provide details of socket communication 4,5,6. these references provide examples and ideas for assignments. au of the detail of establishing communications, converting the communication into a buffered stream and error checking can be done with unix system ca
49、lls. much low level understanding may be required to write applications that are stable.a well designed set of c+ classes can be constructed which will provide the full power of sockets while requiring simple semantics. it is possible to write clients to established servers, event driven servers, po
50、lling servers, etc.the author provided the students with a set of c+ socket classes written and copyright by gnanasekaran swaminathan of the electrical engineering department of the university of virginia (gs4tvirginia. edu) 7. these routines have been written to work with gnu libg+ and appear the s
51、ame as the iostream library. they are available from . these classes have functioned very well for the assignments given. the interface is the same as the iostream library and provides type-safe input and output, there are sockstream classes in the udp and tcp domains as well as a pi
52、pestream class. the sockbuf classes are derived from the streambuf class of the libg+ iostream library. thus, students must learn about streams and buffers for non-socket input and output.sockbuf classes include error functions, ready checks, flush operations, overflow, underflow, and timeout functi
53、ons. socket options such as message routing, reuse of local address, broadcast, etc. can also be set. thus, socket detail may be included as desired.in our particular curriculum a side benefit of using these c+ classes is that students are required to use c+ in a junior/senior level course to help t
54、hem retain skills gained at the freshman/sophomore level.assignmentsin choosing assignments to give during a 3 semester hour course, several goals were desired, it was hoped to design a set of assignments which would require the student to write a client application, a server application a peer-to-p
55、eer application and also provide experience with some standard applications such as electronic mail and file transfer. in addition the assignments should begin simply and become more complicated during the semester. the assignments outlined below meet these criteria.the assignments were very well re
56、ceived by the students. they were perceived to be of practical interest and, at the same time, to be fun projects. some students who do not have a history of applying themselves well to project assignments spent much effort on these assignments and produced good results.specifically. the five assign
57、ments given were:assignment 1 - socket client to smtp serverwrite a client program to connect with an smtp server on a local or remote machine and send a mail message to a use rid. the user need not be on either the local or remote machine. for example, the program might be named smtp and have two arguments: hostname use rid.a simple command line interface is required but students were free to develop much more elaborate e-mail style interfaces. the commands understood by smtp must be used. a subset follows:helo local name iden
溫馨提示
- 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年三氟丙烯合作協(xié)議書
- 三年級下冊口算題
- 三年級數(shù)學(xué)下冊口算練習(xí)
- 三年級數(shù)學(xué)上冊第二單元口算兩位數(shù)減兩位數(shù)教案
- 重慶交通大學(xué)《管理學(xué)精要》2023-2024學(xué)年第二學(xué)期期末試卷
- 2025年春統(tǒng)編版語文一年級下冊第一單元單元任務(wù)群整體公開課一等獎創(chuàng)新教學(xué)設(shè)計
- 瓊臺師范學(xué)院《商務(wù)研究與信息系統(tǒng)》2023-2024學(xué)年第二學(xué)期期末試卷
- 南京理工大學(xué)《工程制圖與計算機(jī)繪圖》2023-2024學(xué)年第二學(xué)期期末試卷
- 吉林工程職業(yè)學(xué)院《中國當(dāng)代史專題》2023-2024學(xué)年第二學(xué)期期末試卷
- 水庫建設(shè)實施方案的經(jīng)濟(jì)效益分析
- 中國服裝零售行業(yè)發(fā)展環(huán)境、市場運(yùn)行格局及前景研究報告-智研咨詢(2025版)
- 新概念第一冊單詞匯總帶音標(biāo)EXCEL版
- 作用于血液及造血器官的藥 作用于血液系統(tǒng)藥物
- 心肺復(fù)蘇(最全版)完整版
- 春節(jié)節(jié)后施工復(fù)工安全培訓(xùn)
- GB/T 3478.1-1995圓柱直齒漸開線花鍵模數(shù)基本齒廓公差
- GB/T 1346-2001水泥標(biāo)準(zhǔn)稠度用水量、凝結(jié)時間、安定性檢驗方法
- FZ/T 25001-2012工業(yè)用毛氈
- 瑞幸咖啡SWOT分析
- DL∕T 1867-2018 電力需求響應(yīng)信息交換規(guī)范
- 小學(xué)生品德發(fā)展水平指標(biāo)評價體系(小學(xué))
評論
0/150
提交評論