版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、<p> 數(shù)據(jù)通信實(shí)驗(yàn)中的套接字編程</p><p><b> 摘要</b></p><p> 雖然許多數(shù)據(jù)通信的課程都沒有教授編程方面的內(nèi)容,但計(jì)算機(jī)專業(yè)課程的規(guī)劃應(yīng)該包括編程。許多有編程內(nèi)容的數(shù)據(jù)通信課程當(dāng)處理詳細(xì)的網(wǎng)絡(luò)層工程時(shí)利用了PC上的連續(xù)端口。UNIX套接字編程允許學(xué)生們處理同樣的事情和問題,但是從文章中它看起來更有用,而且更有趣。另外,如
2、果套接字類使用C++,希望得到的對套接字的操作差不多都可以呈現(xiàn)出來。</p><p><b> 序論</b></p><p> 數(shù)據(jù)通信是大多數(shù)管理信息系統(tǒng)(MIS)以及服務(wù)器/客戶端(C/S)程序標(biāo)準(zhǔn)的一部分。目前作為課程廣泛改善實(shí)行的證據(jù)是提供教材的變化。許多教材,無論是針對MIS還是CS,都很少或沒有提供實(shí)驗(yàn)活動。MIS編程趨向強(qiáng)調(diào)數(shù)據(jù)通信和網(wǎng)絡(luò)的管理。最近
3、的新聞列表顯示了對使用數(shù)據(jù)通信和通信所提供的種類和方式的調(diào)查。無論國內(nèi)或國外,合作方案都非常流行。CS編程會使用一些非常技術(shù)和寬泛的教材。很明顯,一個(gè)工程的規(guī)劃需要更多廣泛和詳細(xì)的課程去研究數(shù)據(jù)通信的物理和結(jié)構(gòu)方面。</p><p> 實(shí)驗(yàn)可能的類型同樣很廣泛?!叭蚝献髂P汀睆?qiáng)迫教給我們數(shù)據(jù)通信如何工作,以用于復(fù)雜的通信機(jī)制和提供一個(gè)解釋這些系統(tǒng)功能的基礎(chǔ)。基于提供的資源,去考慮通過允許學(xué)生嘗試通信的不同的物
4、理和邏輯類型的設(shè)計(jì)選擇。</p><p> 另一個(gè)極端是強(qiáng)調(diào)低水平的,數(shù)據(jù)通信物理理解的練習(xí)——幾乎是一個(gè)工程逼近。一個(gè)典型的例子是使用PC上連續(xù)的端口。除了編寫代碼去操作物理硬盤之外,更多復(fù)雜的概念將被研究。在作者過去使用過的資料中,利用一個(gè)BiSynch協(xié)議和令牌環(huán)來實(shí)現(xiàn)文件傳送的分配。這個(gè)實(shí)驗(yàn)步驟包括基于一個(gè)發(fā)展中的ISO OSI數(shù)據(jù)鏈路層的大規(guī)模工程。</p><p> 這些步
5、驟中沒有提供實(shí)際可操作的硬件經(jīng)驗(yàn)。除了這張紙中的練習(xí),作者還安排了一個(gè)通過硬件和軟件的安裝將PC機(jī)聯(lián)網(wǎng)的工程。服務(wù)器需要額外的安裝和配置。當(dāng)套接字模型被采用時(shí),這樣一個(gè)工程就可以繼續(xù)下去。這里的步驟呈現(xiàn)了為學(xué)生們提供了一個(gè)數(shù)據(jù)通信和網(wǎng)絡(luò)的廣闊視角。</p><p><b> UNIX套接字</b></p><p> 簡單地講,套接字是一個(gè)機(jī)制,在相同或不同的機(jī)器上
6、實(shí)現(xiàn)信息傳送的過程。如果這個(gè)過程在同樣的機(jī)器上,套接字可以用作管道。Intetnet套接字允許運(yùn)行在不同的機(jī)器之間的通信。這個(gè)系統(tǒng)與file i/o擁有同樣的調(diào)用。套接字編程的一個(gè)典型的步驟是創(chuàng)建一個(gè)過程,打開服務(wù)器套接字端口和偵聽另一個(gè)嘗試連接的過程。客戶端可以用與服務(wù)器端套接字同樣的端口號打開一個(gè)套接字,請求服務(wù)連接。如果服務(wù)器偵聽到這個(gè)請求,就建立了一個(gè)連接。通信使用read( )和write()函數(shù)繼續(xù)。</p>
7、<p> 通信有許多標(biāo)準(zhǔn)協(xié)議的類型,比較普遍地兩種是UDP(UDP ,User Datagram Protocol, 用戶數(shù)據(jù)報(bào)協(xié)議)和TCP(TCP ,Transmission Control Protocol, 傳輸控制協(xié)議)。兩種協(xié)議都是經(jīng)過一個(gè)套接字過程傳送信息包。UDP不提供一個(gè)數(shù)據(jù)被接收或者大量信息包被順序接收的保證。TCP是一個(gè)可靠的和有次序的流協(xié)議。程序員在TCP套接字上輸入和輸出,作為一個(gè)來自終端或文件的字
8、節(jié)流出現(xiàn)。如果TCP數(shù)據(jù)在一個(gè)合理的時(shí)間內(nèi)不能被成功傳送,將會顯示一個(gè)錯(cuò)誤。由于在UDP中涉及比較少的開頭部分,如果有次序收到數(shù)據(jù)非常重要,程序也就必須更加復(fù)雜。</p><p> 兩個(gè)過程之間的套接字連接是兩臺主機(jī)/端口對之間的連接,端口號指示了提供的特殊服務(wù)。許多經(jīng)TCP套接字的服務(wù)通常提供一個(gè)可識別的首字母縮寫詞:像SMTP(SMTP ,Simple Message Transport Protocol,
9、 簡單郵件傳輸協(xié)議, 用于電子郵件的傳輸),NNTP(NNTP,Network News Transport Protocol,網(wǎng)絡(luò)新聞傳輸協(xié)議(USE-NET))和FTP(FTP,F(xiàn)ile Transfer Protocol , 文件傳送[輸]協(xié)議)。Telnet(Telnet,用于遠(yuǎn)程聯(lián)接服務(wù)的標(biāo)準(zhǔn)協(xié)議或者實(shí)現(xiàn)此協(xié)議的軟件)是另外的套接字服務(wù)。UNIX提供了一種機(jī)制,憑借著提供服務(wù)的名字能夠譯出端口號。</p><
10、;p><b> 套接字的優(yōu)勢</b></p><p> 數(shù)據(jù)通信實(shí)驗(yàn)中利用套接字編程的一個(gè)明顯的缺點(diǎn)是沒有像PC機(jī)連續(xù)端口那樣多的直接硬件交互。然而,多數(shù)大學(xué)生不會處在這樣詳細(xì)的知識會很重要的情形中。即使有連續(xù)的端口,這個(gè)概念對許多學(xué)生來說仍然很抽象。基于套接字步驟地優(yōu)勢是它將套接字的抽象變得很具體。</p><p> 在過去,基于PC機(jī)實(shí)驗(yàn)的一個(gè)優(yōu)勢是費(fèi)
11、用的低廉。然而,至少有兩個(gè)因素來平衡這種優(yōu)勢。一是現(xiàn)在UNIX工作站普遍使用,PC可以通過安裝UNIX的免費(fèi)版本來轉(zhuǎn)換成工作站。另一個(gè)因素是,即使PC給相對便宜,實(shí)際上會出現(xiàn)老化,不穩(wěn)定,機(jī)器被分配到一個(gè)像數(shù)據(jù)通信實(shí)驗(yàn)這樣專注的工程。我們的經(jīng)驗(yàn)是我們可以負(fù)擔(dān)得起使用的機(jī)器都非常不穩(wěn)定。</p><p> 雖然套接字編程的“高起點(diǎn)”的本性已經(jīng)作為一個(gè)優(yōu)勢強(qiáng)調(diào)了,但使得分配像我們所希望的那樣詳細(xì)同樣是可能的。沒有任
12、何軟件支持的套接字編程需要大量“低起點(diǎn)”的理解和操作。一個(gè)簡單是修改將是基于UDP包而不是TCP包的分配。許多附加的程序(經(jīng)CRC(循環(huán)冗余碼校驗(yàn))的錯(cuò)誤校驗(yàn)、順序數(shù)字、接收的確認(rèn)、接收錯(cuò)誤的否定確認(rèn))都是必要的。無論是UDP或是TCP包,適當(dāng)?shù)脑O(shè)計(jì)握手機(jī)制對文件傳輸這樣的程序來說都是必要的。</p><p> 通過連續(xù)的端口分配,課程時(shí)間就可以投入到作為控制、狀態(tài)、數(shù)據(jù)記錄和類似連續(xù)轉(zhuǎn)換的低起點(diǎn)概念中。通過一
13、個(gè)套接字步驟,就可以討論像信息報(bào)頭、網(wǎng)絡(luò)和機(jī)器字節(jié)順序這樣類似的概念了。如果愿意,連續(xù)端口通信的許多適當(dāng)?shù)闹黝}都可以成為套接字程序和給出的許多相同分配的必須。即使分配了高起點(diǎn)的應(yīng)用,學(xué)生們?nèi)匀槐仨毨斫饬骱途彌_區(qū)之間的不同。</p><p> C++套接字類的優(yōu)勢</p><p> 許多參考書提供了套接字通信的詳細(xì)情形,這些參考書提供了任務(wù)的例子和方法。所有建立通信、把通信轉(zhuǎn)換成緩沖區(qū)流
14、和錯(cuò)誤校驗(yàn)的詳細(xì)情況都可以由UNIX系統(tǒng)調(diào)用完成。許多低起點(diǎn)的理解對于編寫穩(wěn)定的應(yīng)用程序來說是必須的。</p><p> 一個(gè)設(shè)計(jì)得很好的C++類可以被構(gòu)建用于使用簡單的語義學(xué)提供套接字的完全功能。編寫客戶到建立的服務(wù)器、事件驅(qū)動服務(wù)器和輪流檢測服務(wù)器是可能的。</p><p> 作者提供了一組C++類,這些程序都是在GNU下編寫的。他們是由ftp.varginia.edu 提供的。這
15、些類對給出的任務(wù)表現(xiàn)出了非常好的功能。它的接口與輸入輸出流和提供安全類型的輸入輸出一樣。在UDP和TCP域中有套接字流類,就像其中有管道流類一樣。套接字緩沖區(qū)類來源于流緩沖區(qū)類。這樣,學(xué)生們必須學(xué)習(xí)關(guān)于沒有套接字輸入與輸出的流和緩沖區(qū)。</p><p> 套接字緩沖區(qū)類包括錯(cuò)誤功能、準(zhǔn)備好檢測、直接操作、上溢出、下溢出和超時(shí)功能。套接字選項(xiàng)如消息路由、局部地址的再使用、廣播等等都要設(shè)置。這樣,套接字的詳細(xì)情形就
16、可以如希望的那樣了。</p><p> 在我們特殊的課程中,使用這些C++類一方面的益處是學(xué)生們必須在一年級/二年級的水平課程中使用到C++語言,幫助他們保持學(xué)到的技能。</p><p><b> 任務(wù)</b></p><p> 在選擇一個(gè)為期三學(xué)期的課程任務(wù)時(shí),我們渴望實(shí)現(xiàn)很多目標(biāo)。我們被希望設(shè)計(jì)出一系列的任務(wù)來讓學(xué)生編寫一個(gè)客戶端的應(yīng)
17、用、一個(gè)服務(wù)器的應(yīng)用、一個(gè)對等網(wǎng)絡(luò)應(yīng)用,也提供一些像電子郵件和文件傳輸這樣一些標(biāo)準(zhǔn)應(yīng)用的經(jīng)驗(yàn)。另外,任務(wù)應(yīng)該由簡單到復(fù)雜,循序漸進(jìn)。我們在下面列出了這些任務(wù)要點(diǎn)。</p><p> 這些任務(wù)得到了學(xué)生們的良好反響。他們感覺到了實(shí)踐的樂趣,同時(shí),也有了一個(gè)好的計(jì)劃。一些以前沒有接觸過它們的學(xué)生經(jīng)過努力也都有非常好的結(jié)果。這五項(xiàng)明確的任務(wù)是:</p><p> 任務(wù)一:套接字客戶端到電子郵
18、件服務(wù)器</p><p> 在本地或遠(yuǎn)程的機(jī)器上編寫一個(gè)客戶端程序去連接電子郵件服務(wù)器,然后發(fā)送一封電子郵件到一個(gè)用戶名(userid—在電子郵件地址中@符號之前的名稱)。用戶不必要是本地或遠(yuǎn)程機(jī)器上的。例如,這個(gè)程序可能叫做smtp,包括兩項(xiàng)任務(wù):主機(jī)名和用戶名。</p><p> 我們要求有一個(gè)簡單的命令行接口,但是學(xué)生們可以自由地發(fā)揮,做出更多精致的電子郵件類型接口來。SMTP(
19、SMTP —Simple Message Transfer Protocol, 簡單郵件傳輸協(xié)議, 用于電子郵件的傳輸)的命令是一定會用到的。列舉一些如下:</p><p> HELO localname 確認(rèn)連接機(jī)器——本地名稱不需要——一些服務(wù)器不需要HELO,但一些要包括。</p><p> HELP 發(fā)送命令列表</
20、p><p> MAIL FROM:name 可以是你愿意的任何東西——不經(jīng)過合法性的檢驗(yàn)</p><p> RCPT TO:name 郵件的容器——不需要是本地名稱</p><p> DATA 允許信息進(jìn)入——以“.”作為消息的終止字符</p><p> QUIT
21、 斷開連接</p><p> 同其他的任務(wù)一樣,這個(gè)任務(wù)也會帶給學(xué)生一些不合適的活動。下面是提給學(xué)生們的一些警告:</p><p> 顯然你可能在程序中做一些不禮貌的事情。例如,你可能從Daffy Duck那里發(fā)送一串管理員的消息。這需要一些工作量,但這些消息的發(fā)送人將會被記錄。請不要熱衷于這樣幼稚的行為。</p><p>
22、 一些人可能會爭辯說這樣的任務(wù)太“危險(xiǎn)” ,但是學(xué)生們可以學(xué)到如何操作套接字,能夠解決如何自己發(fā)送郵件的問題。我們的方法是承認(rèn)這樣一個(gè)問題的存在并提出警告。</p><p> 任務(wù)二:簡單的網(wǎng)絡(luò)信息服務(wù)器</p><p> 編寫一個(gè)有如下特征的網(wǎng)絡(luò)服務(wù)器程序:</p><p> 1. 從輸入套接字接受命令</p><p> 2. 解釋
23、命令并集合信息</p><p> 3. 發(fā)送輸出命令到輸出套接字</p><p> 你不需要為這個(gè)任務(wù)編寫一個(gè)客戶端程序,因?yàn)闃?biāo)準(zhǔn)的telnet(Telnet—用于遠(yuǎn)程聯(lián)接服務(wù)的標(biāo)準(zhǔn)協(xié)議或者實(shí)現(xiàn)此協(xié)議的軟件,遠(yuǎn)程登錄)客戶端將可以提供這樣的功能。Telnet允許你在客戶端上給一個(gè)服務(wù)器過程發(fā)送信息并把握返回信息。一個(gè)信息的選擇提供系統(tǒng)命令,像域名等等。系統(tǒng)的功能可以從一個(gè)C++程序內(nèi)部
24、執(zhí)行。困難的部分是將命令的輸出并發(fā)送輸出到套接字與客戶端連接起來。命令的輸出應(yīng)該與套接字直接連接。建議有兩種途徑:用管道流類和用傳統(tǒng)的通過用戶構(gòu)造管道連接的C fork()來執(zhí)行系統(tǒng)功能。</p><p> 任務(wù)三:對等網(wǎng)絡(luò)套接字通信</p><p> 編寫一個(gè)作為兩個(gè)相同程序執(zhí)行的“聊天”程序。它應(yīng)該允許用戶自定義連接過程的輸出所出現(xiàn)的信息。這兩個(gè)過程經(jīng)過一個(gè)套接字連接。程序?qū)⒃试S用
25、戶連接一個(gè)確定的過程并監(jiān)聽另一個(gè)試圖連接的處理。</p><p> 兩臺機(jī)器上運(yùn)行相同的程序,任務(wù)必須包括這些要點(diǎn):監(jiān)聽的超時(shí)、通過服務(wù)器程序創(chuàng)建子進(jìn)程、關(guān)閉套接字并終止子進(jìn)程。一個(gè)有限狀態(tài)過渡模型應(yīng)該呈現(xiàn)出來幫助程序的設(shè)計(jì)。</p><p> 任務(wù)四:文件傳輸——服務(wù)器和客戶端</p><p> 通過TCP/IP網(wǎng)絡(luò)套接字連接編寫一個(gè)文件傳輸程序。</
26、p><p> 第一個(gè)程序應(yīng)該與一個(gè)FTP服務(wù)器功能相同。它應(yīng)該在幕后運(yùn)行并等待一個(gè)指定端口的連接。第二個(gè)程序應(yīng)該與一個(gè)FTP客戶端功能相同。因此,需要一個(gè)用戶接口。命令將通過響應(yīng)進(jìn)入并發(fā)送到服務(wù)器。文件應(yīng)該可以進(jìn)行雙向傳輸。</p><p> 客戶端程序應(yīng)該通過響應(yīng)行為接受下列命令:</p><p> ls 服務(wù)器上文件列表<
27、/p><p> put 從客戶端到服務(wù)器傳送文件</p><p> get 從服務(wù)器到客戶端傳送文件</p><p> quit 斷開與服務(wù)器的連接</p><p> :<command> 在客戶端執(zhí)行<command>&
28、lt;/p><p> 這對服務(wù)器/客戶端的性能比FTP要簡單許多。SFTP(簡單文件傳輸協(xié)議)與它類似。舉例來說,F(xiàn)TP運(yùn)用2個(gè)TCP連接,其中一個(gè)類似telnet連接用于控制,另一個(gè)作數(shù)據(jù)傳輸。SFTP用一個(gè)簡單的TCP連接并提供用戶訪問控制,目錄列表和變更,文件重命名和文件刪除。對于這些命令,這里只有目錄列表是需要的。FTP同樣支持lcd、mput、mget等等。這個(gè)任務(wù)需要一個(gè)握手協(xié)議。</p>
29、<p><b> 任務(wù)五:三個(gè)選擇</b></p><p> 任務(wù)五A:使用UDP的FTP文件傳輸</p><p> 建立UDP套接字而不是TCP套接字執(zhí)行任務(wù)4的文件傳輸程序。這個(gè)程序需要:</p><p><b> ⊙集合數(shù)據(jù)包</b></p><p> ⊙ 提供CRC錯(cuò)
30、誤校驗(yàn)</p><p> ⊙ 提供包的先后順序</p><p> 數(shù)據(jù)包可能不是按照順序到達(dá),可能重復(fù)或丟失,需要重新請求或重新排列。每個(gè)數(shù)據(jù)包應(yīng)該被確認(rèn)(肯定地或否定地)。我們將采用一個(gè)協(xié)議來描述數(shù)據(jù)包的格式和錯(cuò)誤信息等等。為了測驗(yàn)使用的協(xié)議,允許用戶指定傳輸中將會出錯(cuò)的部分。</p><p> 任務(wù)五B:雙向文件傳輸</p><p>
31、; 改為打開2個(gè)套接字執(zhí)行任務(wù)4的文件傳輸程序,一個(gè)用于控制信息一個(gè)用于數(shù)據(jù)傳輸。另外,允許兩個(gè)程序同時(shí)來回地發(fā)送文件,通過控制信道取消傳送過程。使用多個(gè)子進(jìn)程將是有益的。(一個(gè)有限狀態(tài)機(jī)器將會是一個(gè)好方法)。</p><p> FTP有著相似的工作方式。它有兩個(gè)套接字連接,但是基于不同的原因,因?yàn)樵谶@里它執(zhí)行的是一個(gè)真正的服務(wù)器——客戶端協(xié)議,而不是對等網(wǎng)絡(luò)協(xié)議。</p><p>
32、 任務(wù)五C:多用戶聊天程序</p><p> 任務(wù)三涉及了對等網(wǎng)絡(luò)聊天程序。這個(gè)任務(wù)需要多路技術(shù)創(chuàng)造聊天服務(wù)器的程序,它能夠把握多重的套接字連接。沒有必要編寫客戶端程序因?yàn)榭梢允褂胻elnet。</p><p> 服務(wù)器可以從任何套接字接受輸入行并把它們輸出到剩余的套接字連接。當(dāng)一個(gè)用戶連接到聊天服務(wù)器,服務(wù)器應(yīng)該及時(shí)提供一個(gè)用戶名。這個(gè)名字應(yīng)該被廣播到其余的用戶。在用戶離開時(shí)同樣要廣
33、播一條消息。當(dāng)一個(gè)用戶的消息被發(fā)送到其它連接的用戶時(shí),應(yīng)提供用戶名以供辨認(rèn)。</p><p><b> 結(jié)論</b></p><p> 重新設(shè)計(jì)數(shù)據(jù)通信課程實(shí)驗(yàn)內(nèi)容的目的是提供這樣的一些任務(wù):</p><p> ⊙ 給學(xué)生們更有意義和更實(shí)際的內(nèi)容</p><p> ⊙ 更另人愉快的,因此也能更好完成的內(nèi)容<
34、/p><p> ⊙ 更現(xiàn)代,但仍然強(qiáng)調(diào)對所發(fā)生內(nèi)容的理解而不僅僅是利用數(shù)據(jù)通信</p><p> ⊙ 循序漸進(jìn),環(huán)環(huán)相扣</p><p> ⊙ 基于更加可靠的硬件,丟棄了以前使用的PC機(jī)</p><p> 一旦這個(gè)套接字范例被選用,目的在于創(chuàng)造一些任務(wù)需要學(xué)生編寫這樣的代碼:</p><p><b>
35、⊙ 利用C++類</b></p><p> ⊙ 提供一個(gè)簡單的客戶端有權(quán)使用定義明確的服務(wù)器</p><p> ⊙ 提供簡單的服務(wù)器功能</p><p> ⊙ 提供對等網(wǎng)絡(luò)通信</p><p> ⊙ 提供多路技術(shù)服務(wù)器功能</p><p> ⊙ 通過一種方式實(shí)現(xiàn)一個(gè)類似于眾所周知網(wǎng)絡(luò)服務(wù)的功能&l
36、t;/p><p> ⊙ 需要學(xué)生們關(guān)注可靠通信</p><p> ⊙ 使用一些fork()形態(tài)并進(jìn)行進(jìn)程間通信編程</p><p> 這些任務(wù)在學(xué)生們中得到了非常好的反響。好學(xué)生發(fā)現(xiàn)通過設(shè)計(jì)好的用戶接口或提供增加功能性來增強(qiáng)計(jì)劃的方法。基礎(chǔ)不是很好的學(xué)生能夠完成任務(wù)并發(fā)現(xiàn)它們同樣有意義和有趣。作者在一所小的自由技術(shù)大學(xué)教授電腦科學(xué)的二十年中,這種實(shí)驗(yàn)任務(wù)的變化就像
37、其它任何一門課程的變化一樣地被接受了。 </p><p><b> 附原文:</b></p><p> SOCKET PROGRAMMING IN THE DATA COMMUNICATIONS LABORATORY</p><p> William E. Toll</p><p> Computing and
38、System Sciences</p><p> Taylor University</p><p> Upland, IN 46989</p><p> btoll@css.tayloru.edu</p><p><b> ABSTRACT</b></p><p> Although
39、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 s
40、erial ports 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 m
41、ore interesting. In addition, if socket classes are</p><p> lNTRODUCTION</p><p> Data communications is a standard part of most MIS and CS programs. The actual implementation of the course var
42、ies widely as evidenced by the variety of text books available. Many texts, whether oriented toward MIS or CS, provide little or no laboratory activity. MIS programs tend to emphasize management of data communications an
43、d networks. Recent news lists postings indicate an emphasis on using data communications and investigations of the types and styles of communication available. National,</p><p> The possible types of labora
44、tory 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 syste
45、ms function. It is possible, based on the available resources, to consider design alternatives by allowing students to explore different physical or logical types of communication. </p><p> At the other ext
46、reme are exercises that emphasize low-level physical understanding of data communications - almost an engineering approach. Atypical example would be the use of serial ports on PCs. In addition to writing code to manipul
47、ate 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 a
48、lternative low-level approach is modeled by </p><p> None of these approaches provide practical hands-on hardware experience. In addition to the exercises described in this paper, the author assigns a proje
49、ct involving 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.</p><p>
50、 Students placed in practical or in their first job have considered the data communications course important. They have typically not believed the PC serial port programming to be important, however. The approach presen
51、ted 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 the paper.</p>&
52、lt;p> UNIX SOCKETS</p><p> Simply 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 m
53、ay be used as pipes. Internet sockets allow communication between processes running on different machines. The system calls are the same as file i/o. A typical approach to socket programming is to create a process that o
54、pens a Sewer socket port and listens for another process to attempt connection. A client can open a socke</p><p><b> .</b></p><p> There are many types of standard protocols. Two o
55、f the most common are UDP (user datagram protocol) and TCP (transmission control protocol). Both protocols transmit packets of information between processes via a socket. UDP does not provide a guarantee that data will b
56、e 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 stream from a ter
57、minal or a </p><p> The socket connection between two processes is a connection between host. port pairs where the port number indicates a particular service that is made available. Many of the services com
58、monly available via TCP sockets are recognizable acronyms: SMTP (Simple Mail Transport Protocol used for e-mail), NNTP (Network News Transport Protocol, used for Usenet news) and FIT (File Transport Protocol). Telnet and
59、 rsh are additional socket services. UNIX provides a mechanism whereby the name of an availabl</p><p> Sockets are also used for the interprocess communication necessary in concurrent or parallel processing
60、. Therefore, parallel processing assignments as well as data communications projects can be built on the same framework.</p><p> ADVANTAGES OF SOCKETS</p><p> One obvious disadvantage of using
61、 socket programming for the data communications lab is that there is less direct hardware interaction than with PC serial ports. However, most graduates will not be in situations where such detailed knowledge will be imp
62、ortant. 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 practical uses such as mail,
63、 telnet, etc.) become much </p><p> 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
64、 workstations are now commonly available. PC labs can be converted to workstations by installing free versions of UNIX. Since most, if not all, socket assignments given in a data communications course are not compute int
65、ensive and do not require a graphical interface, workstations need not be dedicated to the course as would be </p><p> Although the “high level” nature of socket programming has been stressed as an advantag
66、e, 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 t
67、o base assignments on UDP packets rather than TCP packets. Much additional programming (error checking via CRCS, sequence numbers, acknowledgment of receipt negative acknowledgment for receipt </p><p> With
68、 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 heade
69、rs and network and machine byte order can 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 h
70、igh level applications are assigned, the students must s</p><p> ADVANTAGES OF C++ SOCKET CLASSES</p><p> Many references provide details of socket communication [4,5,6]. These references prov
71、ide 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 calls. Much low level understan
72、ding may be required to write applications that are stable.</p><p> A well designed set of C++ classes can be constructed which will provide the full power of sockets while requiring simple semantics. It is
73、 possible to write clients to established servers, event driven servers, polling servers, etc.</p><p> The author provided the students with a set of C++ socket classes written and copyright by Gnanasekaran
74、 Swaminathan of the Electrical Engineering Department of the University of Virginia (gs4t@virginia. edu) [7]. These routines have been written to work with GNU libg++ and appear the same as the iostream library. They are
75、 available from ftp.virginia.edu. These classes have functioned very well for the assignments given. The interface is the same as the iostream library and provides type-safe inp</p><p> Sockbuf classes incl
76、ude error functions, ready checks, flush operations, overflow, underflow, and timeout functions. Socket options such as message routing, reuse of local address, broadcast, etc. can also be set. Thus, socket detail may be
77、 included as desired.</p><p> 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 them retain skills gaine
78、d at the freshman/sophomore level.</p><p> ASSIGNMENTS</p><p> In choosing assignments to give during a 3 semester hour course, several goals were desired, It was hoped to design a set of assi
79、gnments which would require the student to write a client application, a server application a peer-to-peer application and also provide experience with some standard applications such as electronic mail and file transfer
80、. In addition the assignments should begin simply and become more complicated during the semester. The assignments outlined below meet these criteria.</p><p> The assignments were very well received by the
81、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 a
82、ssignments and produced good results.</p><p> Specifically. the five assignments given were:</p><p> ASSIGNMENT 1 - socket client to SMTP server</p><p> Write a client program to
83、 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 argume
84、nts: hostname use rid.</p><p> 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 subs
85、et follows:</p><p> HELO local name identifies connecting machine -</p><p> local name is not needed - some</p><p> servers do not need HELO, but</p><p> inc
86、lude it since some do</p><p> HELP sends list of commands</p><p> MAIL FROM: name may be anything you wish -it is</p><p> not checked for validity</p>
87、<p> RCPT TO: name recipient of mail - need not be</p><p> local name</p><p> DATA allows entry of message-</p><p> terminate message with ’.’ as<
88、/p><p> only character on line</p><p> QUIT disconnect</p><p> This assignment, as well as others, teaches students how to do improper activities. The following warn
89、ing was provided to the students:</p><p> Obviously one could do impolite things with this program. You could, for example, send some administrator a bunch of messages from Daffy Duck. It would take some wo
90、rk, but the sender of these messages could be traced. PLEASE do not engage in such juvenile behavior.</p><p> ASSIGNMENT 2 - simple network information server</p><p> Write a network server pr
91、ogram which will behave as follows:</p><p> 1. accept commands from the input socket</p><p> 2. interpret the commands and gather the information</p><p> 3. send the output of th
92、e commands to the output socket</p><p> You will not need to write a client program for this assignment as the standard telnet client will provide the necessary functions. Telnet allows you to send informat
93、ion over a client to a server process and handles the printing of the return information. A selection of information providing system commands such as domain name, who, etc. was chosen. The system functions can be execut
94、ed from within a C++ program. The difficult part is to take the output of the commands and send the output to the </p><p> ASSIGNMENT 3 - peer to peer socket communications</p><p> Write a “ch
95、at” program which will execute as two identical programs. It should allow users to type information that will appear as output on the connected process. The two processes will be connected via a socket.</p><p&
96、gt; The program will allow the user to connect to a certain process or to listen for another processor trying to connect to it.</p><p> The same program runs on both machines. Topics necessary for this ass
97、ignment include: timeout on listen, creating a child process as done by many server programs, closing sockets and killing child processes. A finite-state transition model could be presented to help in the design of this
98、program.</p><p> ASSIGNMENT 4 - file transfer - client and server</p><p> Write a pair or programs to transfer files over a TCP/IP network socket connection.</p><p> The first pr
99、ogram should function in much the same way as an FIT server. It should be run in the background and wait for a connection on a specified port. The second program will function in much the same way as an FIT client. There
100、fore, a user interface will be needed. Commands will be entered and sent to the server with responses noted. Files may be transferred in either direction.</p><p> The client program should accept the follow
101、ing commands with corresponding actions:</p><p> 1s list files on server</p><p> Put transfer file from client to server</p><p> Get tr
102、ansfer file from server to client</p><p> Quit disconnect from server</p><p> :<command> execute <command> on client useful for 1s on client</p><p>
103、 The capabilities (and therefore, protocol) of this client/server pair are much simpler than FIT. SFTP (Simple File Transfer Protocol) is closer to what is required. FTP, for example, uses2.TCP connections, a telnet-lik
104、e connection for control and a second for data transfer. SFTP uses a single TCP connection and supports user access control, directory listing and changing, file renaming and file deletion. Of these commands, only direct
溫馨提示
- 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. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 外文翻譯--socket通信翻譯數(shù)據(jù)通信實(shí)驗(yàn)中的套接字編程 英文版
- 數(shù)據(jù)通信
- 數(shù)據(jù)通信
- 數(shù)據(jù)通信題庫
- 數(shù)據(jù)通信基礎(chǔ)
- 數(shù)據(jù)通信基礎(chǔ)
- 數(shù)據(jù)通信畢業(yè)論文外文文獻(xiàn)翻譯
- 淺議數(shù)據(jù)通信在通信系統(tǒng)中的應(yīng)用
- 無線數(shù)據(jù)通信產(chǎn)品
- 數(shù)據(jù)通信維護(hù)規(guī)程
- 設(shè)計(jì)一個(gè)完整的數(shù)據(jù)通信系統(tǒng)--數(shù)據(jù)通信課程設(shè)計(jì)
- 華為數(shù)據(jù)通信產(chǎn)品介紹
- 數(shù)據(jù)通信課程設(shè)計(jì)
- 數(shù)據(jù)通信的理論基礎(chǔ)
- 數(shù)據(jù)通信試題庫
- 無線通信的列車控制中的數(shù)據(jù)通信子系統(tǒng)
- 無線數(shù)據(jù)通信系統(tǒng)的設(shè)計(jì)
- 試論數(shù)據(jù)通信及其應(yīng)用前景
- 數(shù)據(jù)通信技術(shù)基礎(chǔ)知識
- 數(shù)據(jù)通信全部習(xí)題以及答案
評論
0/150
提交評論