利来囯际W66

关注官方微信

中文.

Work Mode Selection of Networking Module

Date:2010-12-22 Author:Shanghai ZLAN Views:3677

This paper describes how to use various TCP working modes in serial port to TCP/IP, and flexibly select TCP client, TCP server, UDP and UDP multicast according to different applications. Then, I show you how to use ZLVircom to configure TCP/IP and to communicate with the SocketDlgTest program.

1. TCP&UDP Work Mode

TTCP/IP is the basic protocol for interconnection, and TCP/IP actually involves two layers of network protocol: network layer and transport layer. IP belongs to the network layer, and TCP belongs to the transport layer. In fact, TCP/IP protocol has other parts of the protocol, namely UDP protocol, UDP protocol and TCP protocol together constitute the transport layer of TCP/IP protocol. The TCP protocol has two working modes: client and server. In the application of RS232/RS485 networking module, the choice is mainly between UDP, TCP client and TCP server. As is shown in

1.1 Differences and comparisons between TCP and UDP

The TCP (Transmission Control Protocol) is a reliable connection Protocol. We can use the phones analogy to the TCP protocol. Using the TCP protocol for data transmission, first the connection needs to be established; Just as you need to dial the phones before you call. TCP is a reliable transmission, that is, the data you transmit is wrong or lost, and it will be automatically re-transmitted to ensure the correct data. It's just like when you're on the phones, if the signal isn't good, the recipient will say, "inaudible, say it again."

The UDP (User Datagram Protocol) is the message transport Protocol. We can use SMS to simulate UDP. With UDP, you don't have to ask for permission first (you don't need to establish a connection first), and you can send it at any time. However, the UDP protocol is unreliable, and the data you send out cannot be received correctly.

The so-called "correct reception" includes three aspects: 1) Missing problem: the data can be retransmitted after the data is lost. 2) Error problem: data content error can be detected and resent. 3) order problem: UDP does not guarantee that the order of the data, when send long text messages, for example, may be in the second part text messages received first, and then receive the first message content. This confuses the receiver a lot, and the TCP protocol does not have this problem.

UDP also has its own advantages. 1. Simple and convenient, UDP protocol is very similar to serial communication, because the serial port sends data itself based on non-connection (message). At this point in the serial port to Ethernet, using UDP protocol is in line with the original thinking. 2.UDP protocol has broadcast and multicast function, which can realize one-to-many communication.

  TCP UDP
Connection Requirements
Y
N
Line Occupation
Y
N
Reliable Transmission
Y
N
Simple and Easy to use
N
Y
Support Broadcast
N
Y
1.2 Differences between TCP client and TCP server

When selecting TCP for communication, both sides of the communication must be the TCP Client (TCP Client) and the TCP Server (TCP Server). By telephones, the caller is the TCP client, and the receiver is the TCP server. The IP address in the TCP/IP protocol is similar to the phones number, while the port number in TCP/IP is similar to the telephones extension number. Client (the dial person), you will first need to know each other's IP address and port (phones number and extension), connected to the first TCP server (the listeners pick up the phones), then can do data transmission (conversation). Different from general phones, the TCP server here can access multiple TCP client at the same time, as there are many routes road of the phones, it’s not that if one road phones is connecting the other phones cannot access.

In the RS232 to network of the ZLSN networking module, TCP connections have long connections and short connections. The TCP long connection is when the connection won’t be broken since established until the power is switched off. TCP short connections are when a connection is established when there is needed to communicate, and the connection is closed immediately after the communication is completed.

1.3 The UDP broadcast

Compared with TCP, the advantage of UDP is that it enables one-to-many communication. The following is the introduction of UDP broadcasting and UDP multicast.

UDP broadcast: UDP broadcast packets are different from ordinary UDP packets. UDP broadcasts are as follows:
1). UDP broadcast packets generally only exist within the LAN, which means that it cannot achieve cross-routing communication.
2). All computers in the same LAN can receive broadcast packets. This increases the burden of the network and reduces security.
3). ZLSN series module supports sending and receiving UDP broadcast packets. Additionally, the SocketDlgTest also supports sending and receiving UDP broadcast packets, which can be used for UDP broadcast debugging.

1.4 The UDP multicast

UDP multicast: UDP unicast (that is, ordinary UDP communication) can communicate between points and points. UDP broadcasts can realize sending data from one point to multiple points. But UDP broadcast has the following disadvantages: not only the networking module of needs to receive data can receive data, but also any computer in the LAN can receive data, so the packet privacy is not strong, and add load to the computer which does not wish to receive the data.

UDP multicast can solve the above problem, UDP multicast can realize send data from one point to multipoint, and only join the networking module of a multicast group can receive data, it won’t add load to module or computer out of multicast group, reduce the network load.

In order to determine whether the ZLAN products you buy support UDP multicast please open ZLVircom applications Settings dialog box, click the "advanced setting…" more, if the “UDP multicast” of advanced features supported by the device is selected it indicates the device support UDP multicast.

2. Select work mode
2.1 Selection of TCP and UDP

With TCP and UDP selection, the TCP protocol has a number of advantages, but only when you use the UDP protocol.

1). Save the line resources of the upper computer. In the serial port to Ethernet application of ZLSN module, if the TCP protocol is selected, and in TCP client mode, then the TCP connection is connected after the module is power-on, which belongs to the "long connection". This allows the TCP protocol to take up a communication line (a socket interface), and if the number of networking modules is large (for example, tens of thousands), then using TCP protocol takes up a lot of resources. UDP does not have this problem.

2). Simplify the complexity of upper computer programming. Socket programming based on UDP is simpler than TCP.

3). Need for broadcast or multicast applications.

2.2 Selection of client and server

1). One monitoring center or multiple monitoring centers
One monitoring center: in the centralized monitoring system of one single monitoring center, the ZLSN module dispersed in each collection points send the collecting data to center computer, in this time it’s better to choose the mode of ZLSN module as TCP Client, as long as each module set a destination IP (IP address of center computer). Of course, you can use the center as the client and module as the service side, but the center must remember the IP address of each module, which is not conducive to the malleability and configuration flexibility of system.
Multiple monitoring center: now more than one centers need to monitor the networking module, because TCP client modules can only connect a center (a destination IP), multiple centers cannot monitor a module of TCP client mode (unless adopt ZLAN "class AT commands" function, modules can connect to different center according to different needs). You should use the module as the service end. If you need multiple computers to monitor a ZLSN module at the same time (not time share), select the multi-tcp connection module with ZLSN2090 as the core, and ZLSN2090 supports 10 TCP connections at the same time.

2). Which party knows the IP address of the other party? If one of the two parties A and B (such as A) does not know the IP address of the other party (such as B), A must be as the TCP server. This is because A does not know the IP address of B, nor can it do the connection operation. In the network of using a lot of ZLSN modules, the IP address of ZLSN networking module are dynamically obtained, so the center doesn’t know IP address of all modules, at this time the module should be as Client.

3). Host-slave relationship. In the communication mode of host-slave, the host always sends data first, the slave give answer. In the application of TCP short-connection, the host should be as Client. Because the short-connection use the way of establishing TCP connection when there has data sending, only the host knows when need to send the data and when need to establish connection, the host must Client.

2.3 Selection of TCP short connection and TCP long connection

TCP short connections are generally more efficient than long connections due to the low resource utilization of TCP lines. But the following situation should use long connection: the two communication parties no have the host-slave relationship. Either party has the possibility of sending data first, so always keep the TCP connection. When selecting a long connection, it is important to note that when the connection is established to the current, whether the intermediate network line is disconnected, it needs to detect the availability of the connection at all times, and the short connection is free of this problem, and it is convenient to use.

3. Parameter configuration and network connection

Here we introduce how to use zlvircom to configure the serial port to TCP/IP and to communicate with the SocketDlgTest program. ZLAN networking products comply with the standard TCP/IP protocol, so any network terminal complying with the agreement can communicate with the networking products, ZLAN technology provides the network debugging tools (SocketDlgTest program, the user can find the software in the start menu/procedures/ZLVircom/debugging tools) to simulate the network terminal to communicate with the networking products. If want two network terminals (network debugging tools and networking products) can communication, the parameter configuration must be matched.

3.1 UDP Mode

In UDP mode, the parameter configuration is shown in figure 2, left is the configuration of networking products in vircom, and right is the setting of SocketDlgTest for network debugging tools. First the two must be both UDP work modes. In addition, the red arrows indicate that the destination IP and port of network tool must point to those of networking products. The blue arrows indicate that the destination IP of networking products must be the IP address of computer which the network tool in, and the destination port of networking products must be the local port of network debugging tool. These network parameters are configured to ensure two-way UDP data communication.

3.2 TCP Mode

Work mode in the TCP mode has two type: TCP server and TCP client, no matter adopt what kind of mode, must one is the Server, the other is the Client, then Client can access the Server, both for the Client or the Server is unable to realize communication.When networking products are used as clients, there must be three corresponding relationships, as shown in figure 3. The Work Mode of networking products as Client Mode corresponding to the Server Mode of network tools, the destination IP of networking products must be the IP address of the computer which network tools in, the destination port of networking products must be the local port of network tools. The networking product will automatically connect the network tools after setting, and the data can be sent and received after the connection is established.

3.3 TCP Server

There are also three corresponding relationships when networking products as Server, as shown in figure 3. After this setting, click on the open button of the network tool to establish a TCP connection with the networking product, and the data can be sent and received after the connection is established.

4. Pair-Connection Mode

If the host is not a Socket program (SocketDlgTest) or ZLVircom, but the two devices are connected via the Ethernet port, the configuration method is similar. First, users need to connect two devices and the computer to the same LAN. This computer runs ZLVircom (or ZLDevManage), it is just to configure, after configuration there no need to connect.

Click on ZLVircom's Device Manage to find these two devices, as shown in figure 6. Then click "device edit" to configure the device. Device pair-connection can be divided into TCP pair-connection and UDP pair-connection. If it is a TCP pair-connection, the parameters of the two devices are shown in figure 5. The parameters shown by the arrow must correspond as the corresponding mode of connection to the PC machine. After the success of the TCP connection, can return to the "Device Manage" dialog to see the connection status, as shown in figure 6, if the state of the two devices are "connected" say TCP link has been established between the two devices.

If the pair-connection in UDP mode, the configuration parameters are shown in figure 7, and the corresponding parameters of the arrows must be one-to-one. In UDP pair-connection the data will automatically be sent to the specified device as long as the parameters are configured correctly without checking the connection status.

Finally, it is necessary to remind that if the device is pair-connected, except the Ethernet parameter configuration set as above, the serial port parameters also need to be correctly set. It is mainly because the baud rate of the networking products and the baud rate of the user's device should be accordance. After this setting, user devices can send data to each other through the serial port of two networking products.

利来囯际W66