外文翻译--数据通信实验中的套接字编程

时间:2022-03-04 14:30:47  热度:324°C
10/外文资料翻译数据通信实验中的套接字编程 摘要虽然许多数据通信的课程都没有教授编程方面的内容,但计算机专业课程的规划应该包括编程。许多有编程内容的数据通信课程当处理详细的网络层工程时利用了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下编写的。他们是由ftp/varginia/edu 提供的。这些类对给出的任务表现出了非常好的功能。它的接口与输入输出流和提供安全类型的输入输出一样。在UDP和TCP域中有套接字流类,就像其中有管道流类一样。套接字缓冲区类来源于流缓冲区类。这样,学生们必须学习关于没有套接字输入与输出的流和缓冲区。套接字缓冲区类包括错误功能、准备好检测、直接操作、上溢出、下溢出和超时功能。套接字选项如消息路由、局部地址的再使用、广播等等都要设置。这样,套接字的详细情形就可以如希望的那样了。在我们特殊的课程中,使用这些C+类一方面的益处是学生们必须在一年级/二年级的水平课程中使用到C+语言,帮助他们保持学到的技能。 任务在选择一个为期三学期的课程任务时,我们渴望实现很多目标。我们被希望设计出一系列的任务来让学生编写一个客户端的应用、一个服务器的应用、一个对等网络应用,也提供一些像电子邮件和文件传输这样一些标准应用的经验。另外,任务应该由简单到复杂,循序渐进。我们在下面列出了这些任务要点。这些任务得到了学生们的良好反响。他们感觉到了实践的乐趣,同时,也有了一个好的计划。一些以前没有接触过它们的学生经过努力也都有非常好的结果。这五项明确的任务是: 任务一:套接字客户端到电子邮件服务器在本地或远程的机器上编写一个客户端程序去连接电子邮件服务器,然后发送一封电子邮件到一个用户名(userid在电子邮件地址中符号之前的名称)。用户不必要是本地或远程机器上的。例如,这个程序可能叫做smtp,包括两项任务:主机名和用户名。我们要求有一个简单的命令行接口,但是学生们可以***地发挥,做出更多精致的电子邮件类型接口来。SMTP(SMTP Simple Message Transfer Protocol/ 简单邮件传输协议/ 用于电子邮件的传输)的命令是一定会用到的。列举一些如下:HELO localname 确认连接机器本地名称不需要一些服务器不需要HELO,但一些要包括。HELP 发送命令列表MAIL FROM:name 可以是你愿意的任何东西不经过合法性的检验RCPT TO:name 邮件的容器不需要是本地名称DATA 允许信息进入以“/”作为消息的终止字符QUIT 断开连接同其他的任务一样,这个任务也会带给学生一些不合适的活动。下面是提给学生们的一些警告:显然你可能在程序中做一些不礼貌的事情。例如,你可能从Daffy Duck那里发送一串管理员的消息。这需要一些工作量,但这些消息的发送人将会被记录。请不要热衷于这样幼稚的行为。一些人可能会争辩说这样的任务太“危险” ,但是学生们可以学到如何操作套接字,能够解决如何自己发送邮件的问题。我们的方法是承认这样一个问题的存在并提出警告。 任务二:简单的网络信息服务器编写一个有如下特征的网络服务器程序:1/ 从输入套接字接受命令2/ 解释命令并***信息3/ 发送输出命令到输出套接字你不需要为这个任务编写一个客户端程序,因为标准的telnet(Telnet用于远程联接服务的标准协议或者实现此协议的软件/远程登录)客户端将可以提供这样的功能。Telnet允许你在客户端上给一个服务器过程发送信息并把握返回信息。一个信息的选择提供系统命令,像域名等等。系统的功能可以从一个C+程序内部执行。困难的部分是将命令的输出并发送输出到套接字与客户端连接起来。命令的输出应该与套接字直接连接。建议有两种途径:用管道流类和用传统的通过用户构造管道连接的C fork()来执行系统功能。 任务三:对等网络套接字通信编写一个作为两个相同程序执行的“聊天”程序。它应该允许用户自定义连接过程的输出所出现的信息。这两个过程经过一个套接字连接。程序将允许用户连接一个确定的过程并***另一个试图连接的处理。两台机器上运行相同的程序,任务必须包括这些要点:***的超时、通过服务器程序创建子进程、关闭套接字并终止子进程。一个有限状态过渡模型应该呈现出来帮助程序的设计。 任务四:文件传输服务器和客户端通过TCP/IP网络套接字连接编写一个文件传输程序。第一个程序应该与一个FTP服务器功能相同。它应该在幕后运行并等待一个指定端口的连接。第二个程序应该与一个FTP客户端功能相同。因此,需要一个用户接口。命令将通过响应进入并发送到服务器。文件应该可以进行双向传输。客户端程序应该通过响应行为接受下列命令:ls 服务器上文件列表put 从客户端到服务器传送文件get 从服务器到客户端传送文件quit 断开与服务器的连接: 在客户端执行这对服务器/客户端的性能比FTP要简单许多。SFTP(简单文件传输协议)与它类似。举例来说,FTP运用2个TCP连接,其中一个类似telnet连接用于控制,另一个作数据传输。SFTP用一个简单的TCP连接并提供用户访问控制,目录列表和变更,文件重命名和文件删除。对于这些命令,这里只有目录列表是需要的。FTP同样支持lcd、mput、mget等等。这个任务需要一个握手协议。 任务五:三个选择任务五A:使用UDP的FTP文件传输建立UDP套接字而不是TCP套接字执行任务4的文件传输程序。这个程序需要:***数据包 提供CRC错误校验 提供包的先后顺序数据包可能不是按照顺序到达,可能重复或丢失,需要重新请求或重新排列。每个数据包应该被确认(肯定地或否定地)。我们将采用一个协议来描述数据包的格式和错误信息等等。为了测验使用的协议,允许用户指定传输中将会出错的部分。任务五B:双向文件传输改为打开2个套接字执行任务4的文件传输程序,一个用于控制信息一个用于数据传输。另外,允许两个程序同时来回地发送文件,通过控制信道取消传送过程。使用多个子进程将是有益的。(一个有限状态机器将会是一个好方法)。FTP有着相似的工作方式。它有两个套接字连接,但是基于不同的原因,因为在这里它执行的是一个真正的服务器客户端协议,而不是对等网络协议。 任务五C:多用户聊天程序任务三涉及了对等网络聊天程序。这个任务需要多路技术创造聊天服务器的程序,它能够把握多重的套接字连接。没有必要编写客户端程序因为可以使用telnet。服务器可以从任何套接字接受输入行并把它们输出到剩余的套接字连接。当一个用户连接到聊天服务器,服务器应该及时提供一个用户名。这个名字应该被广播到其余的用户。在用户离开时同样要广播一条消息。当一个用户的消息被发送到其它连接的用户时,应提供用户名以供辨认。 结论重新设计数据通信课程实验内容的目的是提供这样的一些任务: 给学生们更有意义和更实际的内容 更另人愉快的,因此也能更好完成的内容 更现代,但仍然强调对所发生内容的理解而不仅仅是利用数据通信 循序渐进,环环相扣 基于更加可靠的硬件,丢弃了以前使用的PC机一旦这个套接字范例被选用,目的在于创造一些任务需要学生编写这样的代码: 利用C+类 提供一个简单的客户端有权使用定义明确的服务器 提供简单的服务器功能 提供对等网络通信 提供多路技术服务器功能 通过一种方式实现一个类似于众所周知网络服务的功能 需要学生们关注可靠通信 使用一些fork()形态并进行进程间通信编程这些任务在学生们中得到了非常好的反响。好学生发现通过设计好的用户接口或提供增加功能性来增强计划的方法。基础不是很好的学生能够完成任务并发现它们同样有意义和有趣。作者在一所小的***技术大学教授电脑科学的二十年中,这种实验任务的变化就像其它任何一门课程的变化一样地被接受了。 附原文:SOCKET PROGRAMMING IN THE DATA COMMUNICATIONS LABORATORYWilliam E/ TollComputing and System SciencesTaylor UniversityUpland/ IN 46989btollcss/tayloru/eduABSTRACTAlthough 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/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 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 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 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 SOCKETSOne 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 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 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 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 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/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-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 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

免责声明:
1. 《外文翻译--数据通信实验中的套接字编程》内容来源于互联网,版权归原著者或相关公司所有。
2. 若《86561825文库网》收录的文本内容侵犯了您的权益或隐私,请立即通知我们删除。