通信类毕业外文文献翻译@外文翻译@中英文翻译_第1页
通信类毕业外文文献翻译@外文翻译@中英文翻译_第2页
通信类毕业外文文献翻译@外文翻译@中英文翻译_第3页
通信类毕业外文文献翻译@外文翻译@中英文翻译_第4页
通信类毕业外文文献翻译@外文翻译@中英文翻译_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

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

文档简介

1 使用 LabVIEW 中的 TCP/IP 和 UDP 协议 前言 互联网络协议 (IP), 用户数据报协议 (UDP)和传输控制协议 (TCP)是网络通信的基本的工具。TCP 与 IP 的名称来自于一组最著名的因特网协议中的两个 -传输控制协议和互联网络协议。 你能使用 TCP/IP 来进行单一网络或者互连网络间的通信。单独的网络会被大的地理距离分隔。 TCP/IP 把数据从一个子网网络或者因特网连接的计算机发送到另一个上。因为 TCP/IP在大多数计算机上是可用的,它能在多样化的系统中间传送信息。 LabVIEW 和 TCP/IP 你能在所有 平台上的 LabVIEW 中使用 TCP/IP。 LabVIEW 包含了 TCP 和 UDP 程序还有能让你建立客户端或者服务器程序的功能。 IP IP 执行低层次的计算机间的数据传送。在组成部分里的 IP 数据包称为数据报。一个数据报包含表明来源和目的地地址的数据和报头字。 IP 为通过网络或者因特网把数据发送到指定的目的地的数据报确定正确的路径。 IP 协议并不能保证发送。事实上,如果数据报在传输中被复制, IP 可能多次传送一个单独的数据报。所以,程序很少用 IP 而是用 TCP 或者 UDP 代替。 UDP UDP 在计算机进程中提供简单而低层次 的通信。进程通过把数据报发送到一个目的地计算机或者端口进行通信。一个端口是你发送数据的位置。 IP 处理计算机对计算机的发送。在数据报到达目的地计算机后, UDP 把数据报移动到其目的端口。如果目的端口不是开放的, UDP将删除数据报。 UDP 将发生 IP 的同样的发送问题。 应用程序的 UDP 的可靠性不强。例如,一项应用程序能经常把大量信息的数据传送到目的地而丢失少量的数据是肯定的。 在 LabVIEW 中使用 UDP 协议 2 因为 UDP 不是一个 TCP 似的一个以连接为基础的协议,在你发送或者收到数据之前,你不需要和目的地建立一种连接 。相反,当你每发送一个数据报时,由你指定数据目的地。操作系统不会报告传输差错 使用 UDP 打开功能在一个端口上打开一个 UDP 插口。同时打开的 UDP 端口的数量仍依赖于操作系统。 UDP 的打开的功能返回到网络连接时唯一识别 UDP 套接字。使用这种连接在子VI 程序中就是靠这个套接字。 用 UDP 编写功能发送数据到目的地,然后使用 UDP 阅读功能阅读那个数据。每写一个操作要求一个目的地地址和端口。每阅读一个操作包含来源地址和端口。 UDP 保存你所发送的每一个命令所指定的数据报字节。 在理论上,你能发送任何大小的数据报。然而,你 最好不使用 UDP 来发送大的数据报,因为它不像 TCP 一样可靠。 当你在一个端口上结束所有通信时,使用 UDP 结束功能去释放系统资源。 UDP 多路广播 你能使用 UDP 的功能来与一个单独的客户端通信或者通过广播对于所有局域网上的计算机通信。如果你想要传送成倍增加具体的计算机信息,你必须通过客户端列表构建 UDP 功能反复执行。因为 LabVIEW 能把数据的作为一个单独的拷贝发送到每个客户端并且保存对收到数据感兴趣的客户端列表,所以运用这种技术建立完全相同的网络交换。 使用多路广播可以在网络上的进行单个的发送端和多倍的客户 端之间的通信而不需要保存客户列表或者要求发送端把数据多重拷贝后发送给每个客户端。为了通过多路广播收到数据广播,所有客户端必须加入一个多路广播组。而发送端不需要加入该组。发送端只需规定一个多路广播的 IP 地址来定义这个多路广播组。多路广播的 IP 地址范围在 到 55 中。当一个客户端想要加入一个多路广播组时,它只需预定这个组的多路广播的 IP 地址。在客户端预定到一个多路广播组之后,客户端收到从多路广播的 IP地址发送的数据。 对于 LabVIEW 中的 多路广播 ,使用 UDP 多路广播 的打 开程序有能力读、写或者读和写 UDP数据。规定 TTL 为写数据, 多路广播 地址为读数据, 多路广播 端口号为读写数据。默认 TTL是 1,这意味着 LabVIEW 仅仅把数据报发送到本地的网络上。当一个发送方收到一个 多路广播 数据报时,它消耗数据报的生存时间。如果 TTL 大于 1,发送方把数据报转发到其它数据报。下面的表格说明了当你规定一个 TTL 的值时,一个 多路广播 数据报的运行。 3 0 主机上还存留数据报 1 数据报发送到每个在同一本地网络上已预定那个 IP 地址的客户端。中枢 /转发器和桥路 /开关转发数据报。发送方不转发数据报如果 TTL 为 1。 如果你规定一个值大于 1,数据报 通过 TTL-1 层被发送 , 并且 发送方转发它 。 参阅在 LabVIEW例子 commUDP.llb 中的 UDP 多路广播接受方程序和 UDP 多路广播发送方程序 VI 中使用 UDP 多路广播 的例程 。 TCP TCP 保证在网络中的可靠的通信,按顺序发送而没有差错,损失或者重发。 TCP 直到收到一个确认才转发 。 系统要求 在使用 TCP/IP 之前,确认你有必需的要求,这变化依赖于你使用的平台。 (Windows和 UNIX系统 )TCP/IP。 你不需要使用第三种产品连接使用 TCP/IP。如果 你的网络适当地被构成, LabVIEW没有要求附加的设置。 (Mac OS 系统 ) LabVIEW 网络要求打开传送,包括 Mac OS 7.5 和更新的版本。 在 LabVIEW 中使用 TCP TCP 是一个以连接为基础的协议,这意味着站点必须在传送数据之前建立一种连接。 TCP 许可多重、同时的连接。 你可以通过等待一种输入的连接或者通过积极地寻求一种与指定的地址连接建立连接。在建立 TCP 连接时,你必须指定一个地址和该地址的端口。端口范围在 0 到 65,535 点之间。UNIX 系统为特殊的应用程序保留端口数少于 1,024。在一个 给定的地址中不同的端口能识别不同的服务。 使用 TCP 的打开连接功能来与一个指定地址进行积极的连接。如果连接成功,功能返回网络连接的返回数唯一识别那个连接。使用这种连接 refnum 来访问子 VI 程序。 你能使用如下技术来等输入连接: 用 TCP 听程序创建立一个听者并且在一个指定的端口等待一种可接受的 TCP 连接。如果连接成功, VI 程序返回连接数,地址和远程 TCP 客户端口。 TCP 创建听者功创建一个听者然后用 TCP 的听者功能上等待的一个听者接受新的连接。在听者功能上的 TCP 等待返回你所发送的功能和返回数的同样的听者 ID。当你结束等 4 候新的连接时,用 TCP 关闭连接功能区关闭一个听者。你不能对一个听者进行读写。 用第二种技术的优势是你能使用 TCP 关闭连接功能来取消听操作,这在你想要为了一种连接听而没有超时,但是你想要取消当另一个条件变真时的听时是很有用的。你能在任何时间关闭听程序。 当你建立一种连接时,用 TCP 读功能和 TCP 写功能能在远程应用中队数据进行读写。 用 TCP 关闭连接功能区关闭远程连接。如果没被读的仍保留着而关闭连接,你可能失去数据。当关闭连接时,在你的计算机上使用较高层次协议。在连接被关闭后,你不能再读写它。 TCP 和 UDP 之间的区别 在你想要可靠的数据传输时, TCP 是最好的协议。 UDP 是高性能的无需连接的协议,但是它不保证可靠性。 建立 TCP 客户端 注意:请参考最近的版本 LabVIEW 帮助功能对这些指令和功能的细节描述。 完成如下步骤使用 TCP 功能建立一个 TCP 顾客。 1. 用 TCP的打开连接功能来打开一个服务器的连接。你必须规定服务器的因特网地址和服务器的端口。 地址在网络上识别计算机。远程端口在服务器使用听的计算机上识别一个通信通道。当你建立一个 TCP 服务器时,你要规定你想要服务器为通信使用的端口。 2. 用 TCP的写功 能把信息发送到服务器上。 3. 用 TCP的读功能来读发自服务器的信息。你必须规定你想读的字节数。 4. 用 TCP的关闭功能来关闭与服务器的连接。 请参阅 labviewexamplescommTCP.llb 中对单一数据客户端的 TCP 例程。 超时和差错 当你设计一种网络应用时,应细心考虑失败是如何发生的。例如,如果服务器被毁,确定如何使每个客户 VI 程序掌控它。 一种解决方式是确保每个客户 VI 程序有超时功能。如果发生没能在一定量的时间之后生产结果,客户端继续执行。在继续时,客户端能试图重建连接或者报告出错。如果必要的话 ,客户端 VI 程序能关闭应用程序。 5 建立 TCP 服务器 注意:请参考最近的版本 LabVIEW 帮助功能对这些指令和功能的细节描述。 完全如下步骤用 TCP 功能来建立一个 TCP 服务器。 1. 使用 TCP听程序等待连接。你必须规定端口。这个端口必须是客户端试图访问的同一个端口。 2. 如果连接被建立,用 TCP读功能从接受到信息的端口读信息。 3. 用 TCP写功能返回结果。数据必须是一种客户端能接受的形式。 4. 用 TCP关连接功能来关闭连接。 请参阅 labviewexamplescommTCP.llb 中对单一数据客户端的 TCP 例程。 TCP 和 UDP 例子 请参阅 labviewexamplescommTCP.llb 和 labviewexamplescommUDP.llb 中用 TCP 和UDP 的 VI 程序和功能。 Application Note 160 6 Using LabVIEW with TCP/IP and UDP Introduction Internet Protocol (IP), User Datagram Protocol (UDP), and Transmission Control Protocol (TCP) are basic tools for network communication. The name TCP/IP comes from two of the best-known protocols of the Internet protocol suite, the Transmission Control Protocol and the Internet Protocol. You can use TCP/IP to communicate over single networks or interconnected networks. The individual networks can be separated by large geographical distances. TCP/IP routes data from one network or Internet-connected computer to another. Because TCP/IP is available on most computers, it can transfer information among diverse systems. LabVIEW and TCP/IP You can use the TCP/IP protocols with LabVIEW on all platforms. LabVIEW includes TCP and UDP VIs and functions you can use to create client or server VIs. IP IP performs the low-level service of moving data between computers. IP packages data into components called datagrams. A datagram contains the data and a header that indicates the source and destination addresses. IP determines the correct path for the datagram to take across the network or Internet and sends the data to the specified destination. IP cannot guarantee delivery. In fact, IP might deliver a single datagram more than once if the datagram is duplicated in transmission. Programs rarely use IP but use TCP or UDP instead. UDP UDP provides simple, low-level communication among processes on computers. Processes communicate by sending datagrams to a destination computer or port. A port is the location where you send data. IP handles the computer-to-computer delivery. After the datagram reaches the destination computer, UDP moves the datagram to its destination port. If the destination port is not open, UDP discards the datagram. UDP shares the same delivery problems of IP. Use UDP in applications in which reliability is not critical. For example, an application might transmit informative data to a destination frequently enough that a few lost segments of data are not problematic. LabVIEW, National Instruments, and are trademarks of National Instruments Corporation. Product and company names mentioned herein are trademarks or trade names of their respective companies. For patents covering National Instruments products, refer to the appropriate location: HelpPatents in your software, the patents.txt file on your CD, or /patents. 342028C-01 20002004 National Instruments Corporation. All rights reserved. March 2004 7 Using UDP in LabVIEW Because UDP is not a connection-based protocol such as TCP, you do not need to establish a connection with a destination before you send or receive data. Instead, you specify the destination for the data when you send each datagram. Operating systems do not report transmission errors. Use the UDP Open function to open a UDP socket on a port. The number of simultaneously open UDP ports depends on the operating system. The UDP Open function returns a network connection refnum that uniquely identifies the UDP socket. Use this connection refnum to refer to this socket in subsequent VI calls. Use the UDP Write function to send data to a destination, and use the UDP Read function to read that data. Each write operation requires a destination address and port. Each read operation contains the source address and port. UDP preserves the datagram bytes that you specified for each command you send. In theory, you can send datagrams of any size. However, you typically would not use UDP to send large datagrams because it is not as reliable as TCP. When you finish all communications on a port, use the UDP Close function to free system resources. UDP Multicast You can use the UDP functions to communicate to a single client (single-cast) or to all computers on the subnet through a broadcast. If you want to communicate to multiple specific computers, you must configure the UDP functions to iterate through a list of clients. Using this technique creates duplicate network traffic because LabVIEW sends a separate copy of the data to each client and maintains a list of clients interested in receiving the data. Use multicasting to communicate between a single sender and multiple clients on a network without requiring the sender to maintain a list of clients or send multiple copies of the data to each client. To receive data broadcast by a multicast sender, all clients must join a multicast group. The sender does not have to join a group to send data. The sender specifies a multicast IP address, which defines a multicast group. Multicast IP addresses are in the to 55 range. When a client wants to join a multicast group, it subscribes to the multicast IP address of the group. After subscribing to a multicast group, the client receives data sent to the multicast IP address. To multicast in LabVIEW, use the UDP Multicast Open VI to open connections capable of reading, writing, or reading and writing UDP data. Specify the time-to-live (TTL) for writing data, the multicast address for reading data, and the multicast port number for reading and writing data. The default TTL is 1, which means LabVIEW sends the datagram only to the local subnet. When a router receives a multicast datagram, it decrements the datagram TTL. If the TTL is greater than 1, the router forwards the datagram to other routers. The following table lists what action occurs to a multicast datagram when you specify a value for the time-to-live parameter. 0 Datagram remains on the host computer. 1 Datagram sent to every client on the same local subnet that subscribes to that IP address. Hubs/repeaters and bridges/switches forward the datagram. Routers do not forward the datagram if the TTL is 1. Application Note 160 2 8 If you specify a value greater than 1, the datagram is sent and routers forward it through TTL-1 layers. Refer to the UDP Multicast Receiver VI and the UDP Multicast Sender VI in the labviewexamplescommUDP.llb for examples of using UDP multicasting. 9 TCP TCP ensures reliable transmission across networks, delivering data in sequence without errors, loss, or duplication. TCP retransmits the datagram until it receives an acknowledgment. System Requirements Before using TCP/IP, confirm that you have the necessary requirements, which vary depending on the platform you use. (Wi ndo ws a nd U N IX) TCP/IP is built in. You do not need to use a third-party product to communicate using TCP/IP. If your network is configured properly, LabVIEW requires no additional setup. (Mac OS) LabVIEW networking requires Open Transport, included in Mac OS 7.5 and later. Using TCP in LabVIEW TCP is a connection-based protocol, which means that sites must establish a connection before transferring data. TCP permits multiple, simultaneous connections. You initiate a connection by waiting for an incoming connection or by actively seeking a connection with a specified address. In establishing TCP connections, you have to specify the address and a port at that address. A number between 0 and 65,535 represents a port. UNIX reserves port numbers less than 1,024 for privileged applications. Different ports at a given address identify different services at that address. Use the TCP Open Connection function to actively establish a connection with a specific address and port. If the connection is successful, the function returns a network connection refnum that uniquely identifies that connection. Use this connection refnum to refer to the connection in subsequent VI calls. You can use the following techniques to wait for an incoming connection: Use the TCP Listen VI to create a listener and wait for an accepted TCP connection at a specified port. If the connection is successful, the VI returns a connection refnum, the address, and the port of the remote TCP client. Use the TCP Create Listener function to create a listener and use the TCP Wait on Listener function to listen for and accept new connections. The TCP Wait on Listener function returns the same listener ID you wired to the function and the connection refnum for a connection. When you finish waiting for new connections, use the TCP Close Connection function to close a listener. You cannot read from or write to a listener. The advantage of using the second technique is that you can use the TCP Close Connection function to cancel a listen operation, which is useful when you want to listen for a connection without using a timeout, but you want to cancel the listen when another condition becomes true. You can close the listen VI at any time. When you establish a connection, use the TCP Read function and the TCP Write function to read and write data to the remote application. Use the TCP Close Connection function to close the connection to the remote application. If unread data remains and the connection closes, you might lose data. Use a higher level protocol for your computer to determine when to close the connection. After a connection is closed, you cannot read from it or write to it again. National Instruments Corporation 3 Application Note 160 10 Deciding between TCP and UDP TCP is the best protocol to use if you want reliable data transmission. UDP is a connectionless protocol with higher performance, but it does not ensure reliable data transmission. 中北大 学 2005 届本科毕业设计说明书 第 11 页 共 11 页 Creating a TCP Client Note Refer to the LabVIEW Help for the most recent version of these instructions and details for each of the functions. Complete the following steps to create a TCP client using the TCP functions. 1. Use the TCP Open Connection function to open a connection to a server. You must specify the Internet address of the server and the port for the server. The address identifies a computer on the network. The remote port identifies a communication channel on the computer that the server uses to listen for communication requests. When you create a TCP server, you specify the port that you want the server to use for communication. 2. Use the TCP Write function to send a message to a server. 3. Use the TCP Read function to read a message from the server. You must specify the number of bytes you want to read. 4. U

温馨提示

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

评论

0/150

提交评论