# A Magnetotelluric Signal Acquisition and Monitoring System Based on a Cloud Platform
## 5 Development of Cloud Platform Monitoring Software
### Data Communication Development  
The structure of the data communication module is shown in Figure 18. The data communication module mainly includes the Socket communication module and the data command parsing module. The Socket communication module is responsible for the connection between the instrument and the cloud platform. This study adopted a one-to-many organizational structure, where the instrument actively initiates a connection request to the cloud platform after powering on. The cloud platform, as the server, waits for the instrument's request and completes the connection. After the connection is established, this module is responsible for maintaining data transmission between the instrument and the cloud platform. Figure 16: File download workflow in the Controller layer. Figure 17: File upload workflow in the Controller layer. The data command parsing module is mainly used to parse the data obtained by the cloud platform. This study uses a custom data command transmission protocol, and this module is used to parse the protocol and process the data command content accordingly. As shown in Figure 19, the instrument is responsible for data acquisition and passively waits for connections and request commands from other devices in the system, only actively sending power-on and power-off notifications to the cloud platform's fixed IP address during startup and shutdown. The cloud platform is responsible for storing the basic information of the acquisition station, obtaining the data collected by the acquisition station, and maintaining a heartbeat handshake with the acquisition station. The terminal is responsible for user interaction functions, obtaining basic information of the acquisition station from the cloud platform, and establishing a direct connection with the acquisition station using the address in the basic information to monitor the acquisition station in real time or obtain stored acquisition data from the cloud platform. This study introduces Socket to implement data communication between the cloud platform and the instrument. As shown in Figure 19, the cloud platform is the server, and the instrument is the client. The construction process is as follows:  
1. The instrument and cloud platform first create a Socket object by calling the socket function and specifying the Socket type. 2. The user interaction function and the client's location  
2. The cloud platform server binds the Socket object to a specific IP address and port number by calling the bind function. This port is the server's identifier for establishing a connection with the instrument. 3. The cloud platform server starts listening for connection requests from the instrument client by calling the listen function. 4. The instrument client sends a connection request to the server via Socket based on the server's IP address and port number. 5. The cloud platform server listens for connection requests from the instrument client and accepts the connection request by calling the accept function, returning a new Socket object for communication with the instrument client. 6. After the connection is established, the server and client can transmit data through their respective Socket objects, sending and receiving data by reading and writing data streams on the Socket object. 7. When the communication is completed or an error occurs, the Socket object is closed, ending the connection and releasing resources. The program logic of the cloud platform's Socket communication is shown in Figure 20. The main thread is responsible for creating the Socket service, binding the specified port, entering the listening state, and waiting for connection requests from the instrument. It continuously monitors the network port, and when an instrument initiates a connection request, the main thread accepts the request and establishes preliminary communication. After each instrument (e.g., the nth instrument) successfully connects, the main thread assigns an independent thread (e.g., thread n) to achieve concurrent communication with multiple instruments.