計(jì)算機(jī)類(lèi)數(shù)據(jù)通信實(shí)驗(yàn)中的套接字編程中英文翻譯@外文翻譯@外文文獻(xiàn)翻譯_第1頁(yè)
計(jì)算機(jī)類(lèi)數(shù)據(jù)通信實(shí)驗(yàn)中的套接字編程中英文翻譯@外文翻譯@外文文獻(xiàn)翻譯_第2頁(yè)
計(jì)算機(jī)類(lèi)數(shù)據(jù)通信實(shí)驗(yàn)中的套接字編程中英文翻譯@外文翻譯@外文文獻(xiàn)翻譯_第3頁(yè)
計(jì)算機(jī)類(lèi)數(shù)據(jù)通信實(shí)驗(yàn)中的套接字編程中英文翻譯@外文翻譯@外文文獻(xiàn)翻譯_第4頁(yè)
計(jì)算機(jī)類(lèi)數(shù)據(jù)通信實(shí)驗(yàn)中的套接字編程中英文翻譯@外文翻譯@外文文獻(xiàn)翻譯_第5頁(yè)
已閱讀5頁(yè),還剩15頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

付費(fèi)下載

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

附原文: SOCKET PROGRAMMING IN THE DATA COMMUNICATIONS LABORATORY William E. Toll Computing and System Sciences Taylor University Upland, IN 46989 ABSTRACT Although 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 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 more interesting. In addition, if socket classes are used with C+, only as much detail of socket operation as desired need be presented. lNTRODUCTION Data 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 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 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 aspects 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 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 consider 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 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 modeled 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 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 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 the paper. UNIX SOCKETS 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 may 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 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 the 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 packets 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 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 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 commonly 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 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 parallel processing. Therefore, parallel processing assignments as well as data communications projects can be built on the same framework. ADVANTAGES OF SOCKETS One obvious disadvantage of using 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 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 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 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 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 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 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 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 such 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 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. ADVANTAGES OF C+ SOCKET CLASSES Many 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 calls. 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, polling 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 same 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 pipestream 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 functions. 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 them retain skills gained at the freshman/sophomore level. ASSIGNMENTS In choosing assignments to give during a 3 semester ho ur 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-peer 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 received 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 assignments given were: ASSIGNMENT 1 - socket client to SMTP server Write 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 identifies connecting machine - local name is not needed - some servers do not need HELO, but include it since some do HELP sends list of commands MAIL FROM: name may be anything you wish -it is not checked for validity RCPT TO: name recipient of mail - need not be local name DATA allows entry of message- terminate message with . as only character on line QUIT disconnect This assignment, as well as others, teaches students how to do improper activities. The following warning was provided to the students: 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 work, but the sender of these messages could be traced. PLEASE do not engage in such juvenile behavior. ASSIGNMENT 2 - simple network information server Write a network server program which will behave as follows: 1. accept commands from the input socket 2. interpret the commands and gather the information 3. send the output of the commands to the output socket 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 information 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 executed from within a C+ program. The difficult part is to take the output of the commands and send the output to the socket connected to the client. The output of the commands should be connected directly to the socket. Two approaches are suggested: using the pipestream class and using a traditional C fork() to execute the system function which is connected by a user-constructed pipe. ASSIGNMENT 3 - peer to peer socket communications Write a “chat” 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. The program will allow the user to connect to a certain process or to listen for another processor trying to connect to it. The same program runs on both machines. Topics necessary for this assignment 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 program. ASSIGNMENT 4 - file transfer - client and server Write a pair or programs to transfer files over a TCP/IP network socket connection. The first program 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. Therefore, 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. The client program should accept the following commands with corresponding actions: 1s list files on server Put transfer file from client to server Get transfer file from server to client Quit disconnect from server : execute on client useful for 1s on client 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-like 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 directory listing is required here. FIT also supports lcd, mput, mget, etc. A hand-shaking protocol was required for this assignment. ASSIGNMENT 5 - three options were given: ASSIGNMENT 5A - FIT file transfer using UDP Implement the file transfer programs of assignment 4 built on UDP sockets rather than TCP sockets. The programs will need to: Assemble data packets Provide CRC error checking Provide packet sequencing Packets may arrive out of order, duplicated or missing. Packets may needto be re-requested and/or rearranged. Each packet should be acknowledged (positively or negatively). A protocol will need to be adopted which will describe the packet formal error messages, acknowledgments, etc. In order to test the robustness of the protocol used, allow the user to specifractions of transmissions that will (randomly) be done in error. ASSIGNMENT 5B - two channel bidirectional file transfer Implement the file transfer programs of assignment 4 modified to have two sockets open - one for control information and one for data transfer. In addition, allow the two programs to send files back and forth at the same time. A transfer can be aborted by using the control channel. It maybe helpful to fork multiple processes. (A finite state machine approach would be a good idea.) FTP works in a similar manner. It has two socket but does so for different reasons since it is a true client-server protocol rather than the peer-to-peer true protocol implemented here. ASSIGNMENT 5C - multi-user chat program Assignment 2 involved a peer-to-peer chat program, This assignment requires the creation of a multiplexing chat server program which can handle multiple socket connections. There is no need to write a client program since telnet can be used. The server should accept input lines from any connected socket and output them to the rest of the connected sockets. When a user connects to the chat server, the server should prompt for a user name. This name should be broadcast to the rest of the users as “use has just joined the conference.” Similarly, a message should be broadcast when the user leaves the conference. When a users message is sent to the other connected users, the user name should be included for identification. CONCLUSIONS The goals of redesigning the laboratory component of the data communications course were to provide assignments that are: more meaningful and practical to the students more enjoyable and, therefore, will be done better more modern but are still oriented toward understanding what is happening rather than simply using data communications increasingly complex and build on previous assignments based on more reliable hardware that the discarded PCs used previously Once the socket paradigm was chosen, goals were to create assignments which required students to write code that: makes use of C+ classes provides simple client access to a well defined server provides simple server functionality provides peer-to-peer communication provides multiplexing server functionality functions in a manner similar to a well-known network service requires students to be concerned with unreliable communications uses some form of fork() and interprocess communications programming The use of C+ socket classes and the assignments chosen meet all of the above goals if the optional forms of assignment 5 are chosen. The assignments were very well received by the students in the class. The better students found ways to enhance the projects by designing nice user interfaces or providing increased functionality. Less prepared or less capable students were able to complete the assignments and found them both meaningful and enjoyable. In the twenty years that the author has been teaching computer science at small liberal arts universities, this shift of lab assignments has worked as well and was as well received as any curriculum change that has been made. REFERENCES 1 W. Stallings, Data and Computer Communications, edition, MacMillan, New York, 1994 4th 2 W. D. Smith, The Design of An Inexpensive Undergraduate Data Communications Laboratory, SIGCSE Bulletin, Vol 23, No 1, 1991,273-276 3 D. Finkel and S, Chandra, NetCp - A Project Environment for an Undergraduate Computer Networks Course, SIGCSE Bulletin, Vol 26, No 1, 1994, 174-177 4 A Socket-Based Interprocess Communications Tutorial, Chapter 10 of SunOS Network Programming Guide. 5 An Advanced Socket-Based InterProcess Communications Tutorial, Chapter 11 of SunOS Network Programming Guide. 6 R. Quinton, An Introduction to Socket Programming, University Computing and Communication Services, The of Western Ontario, London, Ontario 7 G. Swaminat.haq C+ Socket Classes, Electrical Engineering Department, University of Virginia 譯文: 數(shù)據(jù)通信實(shí)驗(yàn)中的套接字編程 摘要 雖然許多數(shù)據(jù)通信的課程都沒(méi)有教授編程方面的內(nèi)容,但計(jì)算機(jī)專(zhuān)業(yè)課程的規(guī)劃應(yīng)該包括編程。許多有編程內(nèi)容的數(shù)據(jù)通信課程當(dāng)處理詳細(xì)的網(wǎng)絡(luò)層工程時(shí)利用了 PC 上的連續(xù)端口。 UNIX 套接字編程允許學(xué)生們處理同樣的事情和問(wèn)題,但是從文章中它看起來(lái)更有用,而且更有趣。另外,如果套接字類(lèi)使用 C+,希望得到的對(duì)套接字的操作差不多都可以呈現(xiàn)出 來(lái)。 序論 數(shù)據(jù)通信是大多數(shù)管理信息系統(tǒng) (MIS)以及服務(wù)器 /客戶(hù)端 (C/S)程序標(biāo)準(zhǔn)的一部分。目前作為課程廣泛改善實(shí)行的證據(jù)是提供教材的變化。許多教材,無(wú)論是針對(duì) MIS 還是 CS,都很少或沒(méi)有提供實(shí)驗(yàn)活動(dòng)。 MIS 編程趨向強(qiáng)調(diào)數(shù)據(jù)通信和網(wǎng)絡(luò)的管理。最近的新聞列表顯示了對(duì)使用數(shù)據(jù)通信和通信所提供的種類(lèi)和方式的調(diào)查。無(wú)論國(guó)內(nèi)或國(guó)外,合作方案都非常流行。 CS 編程會(huì)使用一些非常技術(shù)和寬泛的教材。很明顯,一個(gè)工程的規(guī)劃需要更多廣泛和詳細(xì)的課程去研究數(shù)據(jù)通信的物理和結(jié)構(gòu)方面。 實(shí)驗(yàn)可能的類(lèi)型同樣很廣泛。“全球合作模型 ”強(qiáng)迫教給我們數(shù)據(jù)通信如何工作,以用于復(fù)雜的通信機(jī)制和提供一個(gè)解釋這些系統(tǒng)功能的基礎(chǔ)。基于提供的資源,去考慮通過(guò)允許學(xué)生嘗試通信的不同的物理和邏輯類(lèi)型的設(shè)計(jì)選擇。 另一個(gè)極端是強(qiáng)調(diào)低水平的,數(shù)據(jù)通信物理理解的練習(xí) 幾乎是一個(gè)工程逼近。一個(gè)典型的例子是使用 PC 上連續(xù)的端口。除了編寫(xiě)代碼去操作物理硬盤(pán)之外,更多復(fù)雜的概念將被研究。在作者過(guò)去使用過(guò)的資料中,利用一個(gè)BiSynch協(xié)議和令牌環(huán)來(lái)實(shí)現(xiàn)文件傳送的分配。這個(gè)實(shí)驗(yàn)步驟包括基于一個(gè)發(fā)展中的 ISO OSI 數(shù)據(jù)鏈路層的大規(guī)模工程。 這些步驟中沒(méi)有提供實(shí)際可 操作的硬件經(jīng)驗(yàn)。除了這張紙中的練習(xí),作者還安排了一個(gè)通過(guò)硬件和軟件的安裝將 PC 機(jī)聯(lián)網(wǎng)的工程。服務(wù)器需要額外的安裝和配置。當(dāng)套接字模型被采用時(shí),這樣一個(gè)工程就可以繼續(xù)下去。這里的步驟呈現(xiàn)了為學(xué)生們提供了一個(gè)數(shù)據(jù)通信和網(wǎng)絡(luò)的廣闊視角。 UNIX 套接字 簡(jiǎn)單地講,套接字是一個(gè)機(jī)制,在相同或不同的機(jī)器上實(shí)現(xiàn)信息傳送的過(guò)程。如果這個(gè)過(guò)程在同樣的機(jī)器上,套接字可以用作管道。 Intetnet 套接字允許運(yùn)行在不同的機(jī)器之間的通信。這個(gè)系統(tǒng)與 file i/o 擁有同樣的調(diào)用。套接字編程的一個(gè)典型的步驟是創(chuàng)建一個(gè)過(guò)程,打開(kāi)服務(wù) 器套接字端口和偵聽(tīng)另一個(gè)嘗試連接的過(guò)程??蛻?hù)端可以用與服務(wù)器端套接字同樣的端口號(hào)打開(kāi)一個(gè)套接字,請(qǐng)求服務(wù)連接。如果服務(wù)器偵聽(tīng)到這個(gè)請(qǐng)求,就建立了一個(gè)連接。通信使用 read( )和 write()函數(shù)繼續(xù)。 通信有許多標(biāo)準(zhǔn)協(xié)議的類(lèi)型,比較普遍地兩種是 UDP( UDP , User Datagram Protocol, 用戶(hù)數(shù)據(jù)報(bào)協(xié)議)和 TCP( TCP , Transmission Control Protocol, 傳輸控制協(xié)議)。兩種協(xié)議都是經(jīng)過(guò)一個(gè)套接字過(guò)程傳送信息包。UDP 不提供一個(gè)數(shù)據(jù)被接收或者大量信息包被 順序接收的保證。 TCP 是一個(gè)可靠的和有次序的流協(xié)議。程序員在 TCP 套接字上輸入和輸出,作為一個(gè)來(lái)自終端或文件的字節(jié)流出現(xiàn)。如果 TCP 數(shù)據(jù)在一個(gè)合理的時(shí)間內(nèi)不能被成功傳送,將會(huì)顯示一個(gè)錯(cuò)誤。由于在 UDP 中涉及比較少的開(kāi)頭部分,如果有次序收到數(shù)據(jù)非常重要,程序也就必須更加復(fù)雜。 兩個(gè)過(guò)程之間的套接字連接是兩臺(tái)主機(jī) /端口對(duì)之間的連接,端口號(hào)指示了提供的特殊服務(wù)。許多經(jīng) TCP 套接字的服務(wù)通常提供一個(gè)可識(shí)別的首字母縮寫(xiě)詞:像 SMTP( SMTP , Simple Message Transport Protocol, 簡(jiǎn)單郵件傳輸協(xié)議 , 用于電子郵件的傳輸), NNTP( NNTP, Network News Transport Protocol,網(wǎng)絡(luò)新聞傳輸協(xié)議 (USE-NET))和 FTP( FTP, File Transfer Protocol , 文件傳送 輸 協(xié)議)。 Telnet( Telnet,用于遠(yuǎn)程聯(lián)接服務(wù)的標(biāo)準(zhǔn)協(xié)議或者實(shí)現(xiàn)此協(xié)議的軟件)是另外的套接字服務(wù)。 UNIX 提供了一種機(jī)制,憑借著提供服務(wù)的名字能夠譯出端口號(hào)。 套接字的優(yōu)勢(shì) 數(shù)據(jù)通信實(shí)驗(yàn)中利用套接字編程的一個(gè)明顯的缺點(diǎn)是沒(méi)有像 PC機(jī)連續(xù)端口那樣多的直接硬件交互 。然而,多數(shù)大學(xué)生不會(huì)處在這樣詳細(xì)的知識(shí)會(huì)很重要的情形中。即使有連續(xù)的端口,這個(gè)概念對(duì)許多學(xué)生來(lái)說(shuō)仍然很抽象?;谔捉幼植襟E地優(yōu)勢(shì)是它將套接字的抽象變得很具體。 在過(guò)去,基于 PC 機(jī)實(shí)驗(yàn)的一個(gè)優(yōu)勢(shì)是費(fèi)用的低廉。然而,至少有兩個(gè)因素來(lái)平衡這種優(yōu)勢(shì)。一是現(xiàn)在 UNIX 工作站普遍使用, PC 可以通過(guò)安裝 UNIX的免費(fèi)版本來(lái)轉(zhuǎn)換成工作站。另一個(gè)因素是,即使 PC 給相對(duì)便宜,實(shí)際上會(huì)出現(xiàn)老化,不穩(wěn)定,機(jī)器被分配到一個(gè)像數(shù)據(jù)通信實(shí)驗(yàn)這樣專(zhuān)注的工程。我們的經(jīng)驗(yàn)是我們可以負(fù)擔(dān)得起使用的機(jī)器都非常不穩(wěn)定。 雖然套接字編程的“高起 點(diǎn)”的本性已經(jīng)作為一個(gè)優(yōu)勢(shì)強(qiáng)調(diào)了,但使得分配像我們所希望的那樣詳細(xì)同樣是可能的。沒(méi)有任何軟件支持的套接字編程需要大量“低起點(diǎn)”的理解和操作。一個(gè)簡(jiǎn)單是修改將是基于 UDP 包而不是 TCP包的分配。許多附加的程序(經(jīng) CRC(循環(huán)冗余碼校驗(yàn))的錯(cuò)誤校驗(yàn)、順序數(shù)字、接收的確認(rèn)、接收錯(cuò)誤的否定確認(rèn))都是必要的。無(wú)論是 UDP 或是 TCP包,適當(dāng)?shù)脑O(shè)計(jì)握手機(jī)制對(duì)文件傳輸這樣的程序來(lái)說(shuō)都是必要的。 通過(guò)連續(xù)的端口分配,課程時(shí)間就可以投入到作為控制、狀態(tài)、數(shù)據(jù)記錄和類(lèi)似連續(xù)轉(zhuǎn)換的低起點(diǎn)概念中。通過(guò)一個(gè)套接字步驟,就可以討論像信 息報(bào)頭、網(wǎng)絡(luò)和機(jī)器字節(jié)順序這樣類(lèi)似的概念了。如果愿意,連續(xù)端口通信的許多適當(dāng)?shù)闹黝}都可以成為套接字程序和給出的許多相同分配的必須。即使分配了高起點(diǎn)的應(yīng)用,學(xué)生們?nèi)匀槐仨毨斫饬骱途彌_區(qū)之間的不同。 C+套接字類(lèi)的優(yōu)勢(shì) 許多參考書(shū)提供了套接字通信的詳細(xì)情形,這些參考書(shū)提供了任務(wù)的例子和方法。所有建立通信、把通信轉(zhuǎn)換成緩沖區(qū)流和錯(cuò)誤校驗(yàn)的詳細(xì)情況都可以由 UNIX 系統(tǒng)調(diào)用完成。許多低起點(diǎn)的理解對(duì)于編寫(xiě)穩(wěn)定的應(yīng)用程序來(lái)說(shuō)是必須的。 一個(gè)設(shè)計(jì)得很好的 C+類(lèi)可以被構(gòu)建用于使用簡(jiǎn)單的語(yǔ)義學(xué)提供套接字的完全功能。編 寫(xiě)客戶(hù)到建立的服務(wù)器、事件驅(qū)動(dòng)服務(wù)器和輪流檢測(cè)服務(wù)器是可能的。 作者提供了一組 C+類(lèi),這些程序都是在 GNU 下編寫(xiě)的。他們是由 提供的。這些類(lèi)對(duì)給出的任務(wù)表現(xiàn)出了非常好的功能。它的接口與輸入輸出流和提供安全類(lèi)型的輸入輸出一樣。在 UDP 和 TCP 域中有套接字流類(lèi),就像其中有管道流類(lèi)一樣。套接字緩沖區(qū)類(lèi)來(lái)源于流緩沖區(qū)類(lèi)。這樣,學(xué)生們必須學(xué)習(xí)關(guān)于沒(méi)有套接字輸入與輸出的流和緩沖區(qū)。 套接字緩沖區(qū)類(lèi)包括錯(cuò)誤 功能、準(zhǔn)備好檢測(cè)、直接操作、上溢出、下溢出和超時(shí)功能。套接字選項(xiàng)如消息路由、局部地址的再使用、廣播等等都要設(shè)置。這樣,套接字的詳細(xì)情形就可以如希望的那樣了。 在我們特殊的課程中,使用這些 C+類(lèi)一方面的益處是學(xué)生們必須在一年級(jí) /二年級(jí)的水平課程中使用到 C+語(yǔ)言,幫助他們保持學(xué)到的技能。 任務(wù) 在選擇一個(gè)為期三學(xué)期的課程任務(wù)時(shí),我們渴望實(shí)現(xiàn)很多目標(biāo)。我們被希望設(shè)計(jì)出一系列的任務(wù)來(lái)讓學(xué)生編寫(xiě)一個(gè)客戶(hù)端的應(yīng)用、一個(gè)服務(wù)器的應(yīng)用、一個(gè)對(duì)等網(wǎng)絡(luò)應(yīng)用,也提供一些像電子郵件和文件傳輸這樣一些標(biāo)準(zhǔn)應(yīng)用的經(jīng)驗(yàn)。另外,任 務(wù)應(yīng)該由簡(jiǎn)單到復(fù)雜,循序漸進(jìn)。我們?cè)谙旅媪谐隽诉@些任務(wù)要點(diǎn)。 這些任務(wù)得到了學(xué)生們的良好反響。他們感覺(jué)到了實(shí)踐的樂(lè)趣,同時(shí),也有了一個(gè)好的計(jì)劃。一些以前沒(méi)有接觸過(guò)它們的學(xué)生經(jīng)過(guò)努力也都有非常好的結(jié)果。這五項(xiàng)明確的任務(wù)是: 任務(wù)一:套接字客戶(hù)端到電子郵件服務(wù)器 在本地或遠(yuǎn)程的機(jī)器上編寫(xiě)一個(gè)客戶(hù)端程序去連接電子郵件服務(wù)器,然后發(fā)送一封電子郵件到一個(gè)用戶(hù)名( userid

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論