[Fan Q&A 11] How to build a TCP server on the internal network and be directly accessible from the external network
This article was submitted by netizen: Deng Gong, VX: A18665908735
Welcome everyone to become friends with technology experts.
Problem Description
Cause: Recently, the company wants to make a 4G module with GNSS (Global Navigation Satellite System) positioning function, and upload sensor data and device positioning data to the server. We chose simcom7600G, a 4G module that supports GSM. First, we used Alibaba Cloud’s remote A TCP server was built on the desktop to complete TCP communication between the server and the 4G module.
But the server has to be charged after all, so I thought of building a local server test platform on my computer to facilitate data communication with the 4G module through the public network.
Software Environment:
windows 10
-
Peanut shell intranet penetration client
-
SocketTool
-
Serial debugging assistant
Implementation steps
The following are the specific steps, with pictures and texts:
first step
First go to the official website of Peanut Shell to download the Peanut Shell intranet penetration client. The link is, https://hsk.oray.com/download/
As shown above, click to download for free.
Step 2
As shown in the picture above, we choose to install to the D drive, and then follow the steps to complete the installation. After the installation is completed,
Click to enter now
Click Register Now and a web page will pop up:
Fill in the information and get the verification code on your mobile phone. Select Individual User and click Register.
[Note that there is a difference between the domain name registered above and the domain name on the subsequent screenshots. Subsequent operations are subject to the information below]
Then log in, as shown below:
third step
As shown in the picture above, this is a TCP test routine that I have created.
the fourth step
As shown in the picture above, if the test routine has been created, you can click Edit to modify the specific details of the test. If it is the first time to use it, click the + sign in the lower right corner to enter the creation page:
the fifth step
As shown in the picture above, you can choose any name. Here we name it TCP Test 1 , and select TCP as the application type. You can try others by yourself, but HTTP seems to charge a few yuan for authentication fees.
If you choose not to use the module, the external network domain name is automatically generated by the software. We choose a random port for the external network port. Fixed ports are charged.
The intranet port is the port bound to the server you created. Here I used the TCP/UDP socket test tool in advance to create a TCP server with port 20000 on the host with the IP address 192.168.1.112 . The intranet IP address can be accessed through cmd View the tool.
As shown in the picture above, enter ipconfig on the command line and it will show that the local IP address is 192.168.1.112 . Copy it to the intranet host box. Then click Save to complete the creation.
Step 6
Next, download the TCP/UDP socket test tool . The download link is: http://www.xitongzhijia.net/soft/110847.html This is a green software. After decompression, open the software directly.
Step 7
As shown in the picture above, first select the TCP Server, then select 20000 as the listening port, and then click OK to create it. It is very simple.
Step 8
As shown above, click Diagnose on the Peanut Shell client after creating the TCP test:
The peanut shell does two things:
-
Bind the wireless router’s WAN port address 103.46.128.45 and the domain name x3720160v0.wicp.vip
-
All data packets sent to the WLAN port with port number 30854 are forwarded to the intranet PC with IP address 192.168.1.112 , and handed over to the process on the PC bound to port number 20000.
Step 9
As shown in the picture above: it must be shown that the connection to the forwarding server is successful and the connection to the LAN server is successful before it is truly available. If the local server is not set up, the LAN server will show that the connection failed.
Step 10
As shown above: After creating a test project for the first time, the client will prompt you to enter the subsequent web management page. This is more useful. The background management link is https://console.hsk.oray.com/forward.
Step 11
As shown in the picture above, connect the simcom7600g 4G module, open the serial port debugging assistant, and select the baud rate as 115200. The specific 4G modules will be different. There are many serial port debugging assistants online. Just choose the one that suits you.
First, let the 4G module register to the base station network, then open the 4G module network and query the assigned IP address. Then you can create a TCP connection and enter the AT command.
AT+CIPOPEN=0,"TCP","x3720160v0.wicp.vip",30854
-
0 represents the created socket serial number. This module supports a total of 10 processes from 0 to 9.
-
Select TCP as communication protocol.
-
For the domain name, choose the free domain name generated by Peanut Shell.
-
Select the peanut shell to generate 30854 for the port number.
Pay special attention to the port number and do not write the server port number 20000 that you created yourself, because Peanut Shell may have performed port remapping for security reasons.
Step 12
As shown in the picture above, we first use the 4G module to send 1234754321 to the server, and the service is received normally. Then the server sends ABCDEF to the 4G module, and the serial port assistant displays
RECV FROM:103.46.128.45:30854
+IPD6
ABCDEF
At this point, the test is completed! !
Summarize
Network environment diagram
As shown in the picture above, detailed access steps:
-
The 4G module accesses the domain name x3720160v0.wicp.vip through AT commands, and the destination port number is 30854
-
The DDNS protocol will return the IP address 102.46.128.45 corresponding to the domain name to the 4G module, and the 4G module can access the wan port of the wireless router at home.
-
All data packets sent by the 4G module will eventually reach the home wireless router
-
The wireless router will forward all data packets with the destination port number 30854 to the internal network IP address192.168.1.112 This PC is bound to the process of port number 20000
-
So the TCP/UDP Socket test tool will receive the data sent by the 4G module
Recommended reading
To join the group, please add Koujun’s personal WeChat account to take you to the advanced level of embedded.
Reply " 1024 " in the official account to get free learning materials. We look forward to your attention~