计算机类数据通信实验中的套接字编程中英文翻译@外文翻译@外文文献翻译_第1页
计算机类数据通信实验中的套接字编程中英文翻译@外文翻译@外文文献翻译_第2页
计算机类数据通信实验中的套接字编程中英文翻译@外文翻译@外文文献翻译_第3页
计算机类数据通信实验中的套接字编程中英文翻译@外文翻译@外文文献翻译_第4页
计算机类数据通信实验中的套接字编程中英文翻译@外文翻译@外文文献翻译_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

附原文: 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 “low 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 译文: 数据通信实验中的套接字编程 摘要 虽然许多数据通信的课程都没有教授编程方面的内容,但计算机专业课程的规划应该包括编程。许多有编程内容的数据通信课程当处理详细的网络层工程时利用了 PC 上的连续端口。 UNIX 套接字编程允许学生们处理同样的事情和问题,但是从文章中它看起来更有用,而且更有趣。另外,如果套接字类使用 C+,希望得到的对套接字的操作差不多都可以呈现出 来。 序论 数据通信是大多数管理信息系统 (MIS)以及服务器 /客户端 (C/S)程序标准的一部分。目前作为课程广泛改善实行的证据是提供教材的变化。许多教材,无论是针对 MIS 还是 CS,都很少或没有提供实验活动。 MIS 编程趋向强调数据通信和网络的管理。最近的新闻列表显示了对使用数据通信和通信所提供的种类和方式的调查。无论国内或国外,合作方案都非常流行。 CS 编程会使用一些非常技术和宽泛的教材。很明显,一个工程的规划需要更多广泛和详细的课程去研究数据通信的物理和结构方面。 实验可能的类型同样很广泛。“全球合作模型 ”强迫教给我们数据通信如何工作,以用于复杂的通信机制和提供一个解释这些系统功能的基础。基于提供的资源,去考虑通过允许学生尝试通信的不同的物理和逻辑类型的设计选择。 另一个极端是强调低水平的,数据通信物理理解的练习 几乎是一个工程逼近。一个典型的例子是使用 PC 上连续的端口。除了编写代码去操作物理硬盘之外,更多复杂的概念将被研究。在作者过去使用过的资料中,利用一个BiSynch协议和令牌环来实现文件传送的分配。这个实验步骤包括基于一个发展中的 ISO OSI 数据链路层的大规模工程。 这些步骤中没有提供实际可 操作的硬件经验。除了这张纸中的练习,作者还安排了一个通过硬件和软件的安装将 PC 机联网的工程。服务器需要额外的安装和配置。当套接字模型被采用时,这样一个工程就可以继续下去。这里的步骤呈现了为学生们提供了一个数据通信和网络的广阔视角。 UNIX 套接字 简单地讲,套接字是一个机制,在相同或不同的机器上实现信息传送的过程。如果这个过程在同样的机器上,套接字可以用作管道。 Intetnet 套接字允许运行在不同的机器之间的通信。这个系统与 file i/o 拥有同样的调用。套接字编程的一个典型的步骤是创建一个过程,打开服务 器套接字端口和侦听另一个尝试连接的过程。客户端可以用与服务器端套接字同样的端口号打开一个套接字,请求服务连接。如果服务器侦听到这个请求,就建立了一个连接。通信使用 read( )和 write()函数继续。 通信有许多标准协议的类型,比较普遍地两种是 UDP( UDP , User Datagram Protocol, 用户数据报协议)和 TCP( TCP , Transmission Control Protocol, 传输控制协议)。两种协议都是经过一个套接字过程传送信息包。UDP 不提供一个数据被接收或者大量信息包被 顺序接收的保证。 TCP 是一个可靠的和有次序的流协议。程序员在 TCP 套接字上输入和输出,作为一个来自终端或文件的字节流出现。如果 TCP 数据在一个合理的时间内不能被成功传送,将会显示一个错误。由于在 UDP 中涉及比较少的开头部分,如果有次序收到数据非常重要,程序也就必须更加复杂。 两个过程之间的套接字连接是两台主机 /端口对之间的连接,端口号指示了提供的特殊服务。许多经 TCP 套接字的服务通常提供一个可识别的首字母缩写词:像 SMTP( SMTP , Simple Message Transport Protocol, 简单邮件传输协议 , 用于电子邮件的传输), NNTP( NNTP, Network News Transport Protocol,网络新闻传输协议 (USE-NET))和 FTP( FTP, File Transfer Protocol , 文件传送 输 协议)。 Telnet( Telnet,用于远程联接服务的标准协议或者实现此协议的软件)是另外的套接字服务。 UNIX 提供了一种机制,凭借着提供服务的名字能够译出端口号。 套接字的优势 数据通信实验中利用套接字编程的一个明显的缺点是没有像 PC机连续端口那样多的直接硬件交互 。然而,多数大学生不会处在这样详细的知识会很重要的情形中。即使有连续的端口,这个概念对许多学生来说仍然很抽象。基于套接字步骤地优势是它将套接字的抽象变得很具体。 在过去,基于 PC 机实验的一个优势是费用的低廉。然而,至少有两个因素来平衡这种优势。一是现在 UNIX 工作站普遍使用, PC 可以通过安装 UNIX的免费版本来转换成工作站。另一个因素是,即使 PC 给相对便宜,实际上会出现老化,不稳定,机器被分配到一个像数据通信实验这样专注的工程。我们的经验是我们可以负担得起使用的机器都非常不稳定。 虽然套接字编程的“高起 点”的本性已经作为一个优势强调了,但使得分配像我们所希望的那样详细同样是可能的。没有任何软件支持的套接字编程需要大量“低起点”的理解和操作。一个简单是修改将是基于 UDP 包而不是 TCP包的分配。许多附加的程序(经 CRC(循环冗余码校验)的错误校验、顺序数字、接收的确认、接收错误的否定确认)都是必要的。无论是 UDP 或是 TCP包,适当的设计握手机制对文件传输这样的程序来说都是必要的。 通过连续的端口分配,课程时间就可以投入到作为控制、状态、数据记录和类似连续转换的低起点概念中。通过一个套接字步骤,就可以讨论像信 息报头、网络和机器字节顺序这样类似的概念了。如果愿意,连续端口通信的许多适当的主题都可以成为套接字程序和给出的许多相同分配的必须。即使分配了高起点的应用,学生们仍然必须理解流和缓冲区之间的不同。 C+套接字类的优势 许多参考书提供了套接字通信的详细情形,这些参考书提供了任务的例子和方法。所有建立通信、把通信转换成缓冲区流和错误校验的详细情况都可以由 UNIX 系统调用完成。许多低起点的理解对于编写稳定的应用程序来说是必须的。 一个设计得很好的 C+类可以被构建用于使用简单的语义学提供套接字的完全功能。编 写客户到建立的服务器、事件驱动服务器和轮流检测服务器是可能的。 作者提供了一组 C+类,这些程序都是在 GNU 下编写的。他们是由 提供的。这些类对给出的任务表现出了非常好的功能。它的接口与输入输出流和提供安全类型的输入输出一样。在 UDP 和 TCP 域中有套接字流类,就像其中有管道流类一样。套接字缓冲区类来源于流缓冲区类。这样,学生们必须学习关于没有套接字输入与输出的流和缓冲区。 套接字缓冲区类包括错误 功能、准备好检测、直接操作、上溢出、下溢出和超时功能。套接字选项如消息路由、局部地址的再使用、广播等等都要设置。这样,套接字的详细情形就可以如希望的那样了。 在我们特殊的课程中,使用这些 C+类一方面的益处是学生们必须在一年级 /二年级的水平课程中使用到 C+语言,帮助他们保持学到的技能。 任务 在选择一个为期三学期的课程任务时,我们渴望实现很多目标。我们被希望设计出一系列的任务来让学生编写一个客户端的应用、一个服务器的应用、一个对等网络应用,也提供一些像电子邮件和文件传输这样一些标准应用的经验。另外,任 务应该由简单到复杂,循序渐进。我们在下面列出了这些任务要点。 这些任务得到了学生们的良好反响。他们感觉到了实践的乐趣,同时,也有了一个好的计划。一些以前没有接触过它们的学生经过努力也都有非常好的结果。这五项明确的任务是: 任务一:套接字客户端到电子邮件服务器 在本地或远程的机器上编写一个客户端程序去连接电子邮件服务器,然后发送一封电子邮件到一个用户名( userid

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论