Turn: analyze the TCP/UDP connection process using the GPRS module

Source: Internet
Author: User

In fact, on gprs dtu, the protocol stack is TCP/IP over PPP. We must have some corresponding concepts when using them. Therefore, we will give a brief description of the issues related to the use of the GPRS module. If you want to learn more about these protocols, please refer to the relevant books:

1. each GPRS module calls ATD * 99 *** 1 # (or ATD * 99 *** 1 #) after that, we are using the PPP protocol to shake hands with mobile access devices (generally a special ggsn router of a mobile company). When the PPP handshake succeeds, the GPRS module obtains a dynamic IP address. In general, the dynamic IP addresses obtained after the GPRS module goes offline (after the connection is hung up or the power is directly down) and then dialed again and shook hands with the PPP are different. However, mobile companies can activate specific APN and issue Special SIM cards for customers, so that the dynamic IP addresses obtained from this SIM card remain unchanged every time. That is to say, you can bind the SIM card to the IP address.

2. during the test, we should note the following fact: when using the Internet APN ("cmnet, if we use the GPRS module to actively initiate a TCP connection to a static public IP address on the public network, as long as the machine on the public network does listen on the corresponding port, this can be connected; on the contrary, if a TCP connection is actively initiated from a static IP address on the public network to the IP address dynamically obtained by the GPRS module, the connection will not succeed. The reason for this phenomenon is: in fact, the dynamic IP address obtained by the GPRS module is the address on a special internal network segment, if the address in this special internal network segment needs to be connected to the external network (Public Network) you must forward the TCP communication through a device similar to a TCP proxy (or NAT. In other words, this dynamic address is not accessible to other machines on the network.

3. The main function of the standard at command + cgdcont is to specify the APN. APN is short for Access Point name (Access Point). Mobile provides Virtual Private Net (VPN) services to industrial customers by activating special APN. For example, if you want to access the Internet, you should use "cmnet" as the APN. Another example is that an enterprise applied for the VPN service from a mobile company, and the mobile company activated an APN for it as "hxsw. then we should use this APN to set the GPRS module. The format is as follows:
At + cgdcont = 1, "ip", "hxsw. GD"

4. determine that a TCP connection has four elements: the IP address of both parties and the TCP port number of both parties, this is why the GPRS module combines the local port, destination port, and destination IP address as the connection ID (the Dynamic Address obtained by the GPRS module after the PPP handshake is successful, as long as the connection is continuously reconnected change).

5. When using TCP for data communication, it must go through three stages. The first stage is the connection establishment stage, the second stage is the data transmission and receiving stage, and the third stage is the connection release stage:

1). Connection establishment phase:
The connection establishment involves both active and passive connections. Generally, the client initiates a connection and the server passively accepts the connection.

The so-called active connection means that the local party initiates a connection request to the remote end, and the passive connection means that the local party listens on a port, wait for the remote end and actively initiate a connection request to itself and respond, and finally shake hands to build the chain successfully.

After the connection is successful and switched to the data state, we can use the open command frame to control the GPRS module for active connection. Of course, you must specify the IP address and port number of the other party during connection. The GPRS module also supports passive connection. Currently, the program only supports listening on one port. After the other party actively connects (the GPRS module passively connects), a new communication connection will be established. The GPRS module will notify the host machine of the successful passive connection event.

2). Data sending and receiving phase:
After a connection is established, we can send and receive data on the connection.

We can use the send command frame to control the GPRS module for data transmission. Of course, you must specify the connection number when sending the message (which is determined by the unique local port, destination address, and port ).

For the data sent by the other party, the GPRS module first stores the data in its own data buffer, and then notifies the host machine that the data has arrived at this event. After the host machine reads the data that has arrived at the event, the Recv command frame should be used in a timely manner to control all data connected to the GPRS module to be read through the serial port. After the data is read, the original data buffer space occupied by the data will be released. Note that the data buffer zone of the GPRS module is limited (the total amount is only 25 KB bytes). Therefore, the host computer must read the data sent from the other party in time. Otherwise, the data accumulates, this may cause data buffer overflow and data loss.

3). Hanging up the connection stage:
When all the data on a connection has been sent and received, the connection can be hung up.

Similar to the connection establishment phase, the link is also divided into active and passive.

We can use the rset command frame to control the GPRS module to actively stop the connection.

If the connection is actively hung up by the other party, the GPRS module will notify the host computer to handle the event.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.