A service data sending method, receiving method, device, system and equipment
The MLCP protocol enables efficient and flexible data transmission on mobile devices, solving the problems of high resource consumption and low configurability of existing long-connection protocols, and improving bandwidth utilization and transmission efficiency.
Patent Information
- Application Number
- CN202311061515.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-22
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-08-22
AI Technical Summary
Existing long-connection protocol frameworks have too many layers and multiple encapsulations, resulting in high resource consumption. They also provide few callback entry points, low configurability and scalability, and cannot meet the needs of complex business scenarios in the mobile Internet.
Using the MLCP protocol, a heartbeat data packet is generated and split into data segments by creating an MLCP connection. The data packets are then transmitted using Sockets and reassembled at the receiving end. Flexible encapsulation and callback interfaces are provided to reduce resource consumption and improve bandwidth utilization.
It enables efficient and flexible data transmission on mobile devices, reduces resource consumption, improves transmission efficiency, and supports custom heartbeat keep-alive and log recording, making it suitable for various network environments.
Smart Images

Figure CN117061586B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer data transmission technology, and more particularly to a technology for business data transmission. Background Technology
[0002] In computer network systems, different business data are typically transmitted and processed as byte streams to achieve business functions or provide business services. In application scenarios where the amount of business data transmitted is large, or where frequent interaction is required between the data sender and receiver, long-connection protocols are usually used to establish transmission channels. Currently commonly used long-connection protocols such as WebSocket and HTTP / HTTPS either have too many framework layers and multiple encapsulations, resulting in high overhead and high resource consumption, or they provide few callback entry points, resulting in low configurability and scalability. Moreover, some existing long-connection protocols do not have heartbeat keep-alive functionality, which needs to be implemented manually at the business application level.
[0003] With the rapid development of the mobile internet, interactive services based on the mobile internet are emerging in an endless stream. For example, various social apps and chat apps used on mobile devices often need to establish long connections to achieve data transmission during the data interaction process.
[0004] In application scenarios with numerous mobile devices and increasingly complex business scenarios, existing long-connection protocols, which are mainly used in computer network systems, are not very suitable. Summary of the Invention
[0005] The purpose of this application is to provide a business data sending method, receiving method, apparatus, system, and device to at least partially solve the technical problems of existing long connection protocols for byte stream data transmission, which have too many framework layers, multiple encapsulations, and high overhead, resulting in high resource consumption, or provide few callback entry points, and have low configurability and scalability.
[0006] According to one embodiment of this application, a business data transmission method is provided, applied to a data sender, wherein the method includes:
[0007] Create and initiate an MLCP connection with the data receiver;
[0008] Based on the heartbeat keep-alive sending interval, generate heartbeat data packets with MLCP frame structure, and based on the service data sending request, encapsulate the service data to be sent into several service data packets with MLCP frame structure.
[0009] Based on the first data length, the heartbeat data packet and each service data packet are split into several data segments respectively;
[0010] Heartbeat data packets and several data segments corresponding to each service data packet are sequentially sent to the data receiver via Socket.
[0011] Optionally, MLCP includes:
[0012] The MLCPSocket class corresponds to the Socket operation layer in the MLCP hierarchy and is used to implement Socket connection management, data sending, and data receiving.
[0013] The MLCPSocketControl class corresponds to the MLCP control layer in the MLCP hierarchy. It inherits from the MLCPSocket class and is used to implement Socket requests and MLCP long connection logic control.
[0014] The MLCP class corresponds to the MLCP interface layer in the MLCP hierarchy. It inherits from the MLCPSocketControl class and is used to implement the external public interface.
[0015] The MLCPInterface class is used to provide a callback function interface;
[0016] The MLCPCallBack class is used for callback function management;
[0017] The MLCPLogUtil class provides logging tools.
[0018] Optionally, the MLCP further includes:
[0019] The MLCPNetUtil class is used to provide network management;
[0020] The MLCPSysUtil class is used to provide system management;
[0021] The MLCPVerUtil class is used to provide version management.
[0022] Optionally, the MLCPSocket class includes:
[0023] The Socket connection creation interface is used to initialize the Socket connection, initialize the data buffer, and call the data receiving interface to start the data receiving process.
[0024] The Socket connection close interface is used to destroy the data buffer, destroy the data connection thread, and destroy the Socket connection.
[0025] The first data transmission interface is used to split the data packets of the MLCP frame structure into several data segments, and send the corresponding data segments of the data packets of the MLCP frame structure in sequence through the Socket.
[0026] The data receiving interface is used to sequentially receive several data segments corresponding to data packets of the MLCP frame structure via Socket and write the data segments into the data buffer.
[0027] The data buffer management interface is used to initialize, write to, read from, get the length of the data buffer, and clear the data buffer.
[0028] Optionally, the Socket connection creation interface, the Socket connection closing interface, the first data sending interface, and the data receiving interface are further used for:
[0029] Exception handling and logging.
[0030] Optionally, the MLCPSocketControl class includes:
[0031] The first initialization interface is used to set the connection name, context object, and logging switch;
[0032] The first setting callback interface is used to initialize the MLCPCallBack class and call the setting callback interface of the MLCPCallBack class;
[0033] The connection interface is started to set parameters such as connection URL, port, heartbeat keep-alive time interval, and disconnection reconnection interval. The Socket connection creation interface is called to create an MLCP connection, a read thread is started to read data from the data buffer, a callback interface is used to return data, the heartbeat keep-alive interface is called to start the heartbeat keep-alive thread, and disconnection reconnection is enabled.
[0034] The heartbeat keep-alive interface is used to send heartbeat keep-alive data packets and reconnect after a disconnection.
[0035] The reconnection port is used to call the Socket connection closing interface to close the MLCP connection and to call the connection starting interface to start the MLCP connection.
[0036] The second data sending interface is used for callback interfaces to call the first data sending interface to send data and reconnect after disconnection.
[0037] The first connection closing interface is used to call the data buffer management interface to clear the data buffer, call the Socket connection closing interface to close the MLCP connection, and destroy the data reading thread.
[0038] The first interface for obtaining connection status is used to return the MLCP connection status.
[0039] The first data clearing interface is used to call the data buffer management interface to clear the data buffer.
[0040] Optionally, the connection initiation interface, the heartbeat keep-alive interface, the reconnection interface, the second data transmission interface, and the first connection termination interface are further used for:
[0041] Exception handling and logging.
[0042] Optionally, the MLCP class includes:
[0043] The second initialization interface is used to call the first initialization interface;
[0044] The second setting callback interface is used to call the first setting callback interface;
[0045] A connection interface, used to call the startup connection interface;
[0046] A data sending interface is used to call the second data sending interface;
[0047] The second interface for obtaining connection status is used to call the first interface for obtaining connection status.
[0048] The second data clearing interface is used to call the first data clearing interface;
[0049] The second close connection interface is used to call the first close connection interface.
[0050] Optionally, the MLCPCallBack class includes:
[0051] The third step is to set up a callback interface to receive parameters from the MLCPInterface class.
[0052] The callback interface is used to call the callback function of the MLCPInterface class, passing in the business application type, MLCP instance name, connection status and business data, or returning these parameters to the business application.
[0053] Optionally, the MLCPInterface class includes:
[0054] A callback function, wherein the parameters of the callback function include the business application type, MLCP instance name, connection status, and context object.
[0055] Optionally, the MLCPLogUtil class includes:
[0056] The management log switch interface is used to set and retrieve the log switch status.
[0057] The information log interface is used to print information type logs, and the save log to file interface is called to save the information type logs to a file;
[0058] The debug log recording interface is used to print debug type logs, and the save log to file interface is called to save the debug type logs to a file;
[0059] The warning log interface is used to print warning type logs, and the save log to file interface is called to save the warning type logs to a file;
[0060] The exception logging interface is used to print exception type logs, and the save log to file interface is called to save the exception type logs to a file;
[0061] The interface for saving logs to files is used to create directories, create files, and write files.
[0062] The delete log file interface is used to retrieve expired log files and delete them.
[0063] Optionally, the step of creating and initiating an MLCP connection with the data receiver includes:
[0064] Using the MLCP class, set the first core parameter, which includes: context object, MLCP instance name, and logging switch;
[0065] Using the MLCPSocketControl and MLCPInterface classes, a callback function and a second core parameter are set. The parameters of the callback function include the current MLCP instance name, connection status, and context object. The second core parameter includes: the connection URL, port, heartbeat keep-alive sending interval, disconnection reconnection interval, and data buffer size.
[0066] Based on the second core parameter, create and start an MLCP connection.
[0067] Optionally, if the MLCP connection with the data receiver fails, the method further includes:
[0068] Based on the disconnection and reconnection interval, restart the MLCP connection with the data receiver.
[0069] Optionally, the MLCPNetUtil class includes:
[0070] The interface for obtaining network connection type is used to retrieve the network type.
[0071] The interface for obtaining network connection status is used to call the underlying system interface to determine the network status and to call the interface for obtaining network connection type to obtain the network type.
[0072] Optionally, the MLCPSysUtil class includes:
[0073] Get IP address interface;
[0074] Interface for obtaining SIM card status;
[0075] The first data type conversion interface is used to convert int to byte array;
[0076] The second data type conversion interface is used to convert byte arrays to int;
[0077] The third data type conversion interface is used to convert input streams into byte arrays;
[0078] A byte array truncation interface for byte array truncation operations;
[0079] The byte array concatenation interface is used for byte array concatenation operations.
[0080] Optionally, the MLCPVerUtil class includes:
[0081] The version number retrieval interface is used to obtain the version number of the currently used MLCP.
[0082] Optionally, the MLCP frame structure includes:
[0083] Compression method field, encryption method field, total frame number field, current frame field, key field, payload length bit width field, payload length field, payload field.
[0084] Optionally, when splitting the heartbeat data packet or each service data packet into several data segments, if the length of the last actual remaining data is less than the length of the first data segment, then the length of the last data segment is the length of the actual remaining data.
[0085] According to another embodiment of one aspect of this application, a method for receiving business data is provided, applied to a data receiver, wherein the method includes:
[0086] Create and initiate an MLCP connection with the data sender;
[0087] Initialize the data buffer, receive data sent sequentially by the data sender via Socket, and read data according to the second data length based on the first data reading interval to obtain data segments and write them into the data buffer;
[0088] Based on the second data reading interval, several data segments are read from the data buffer and assembled into a data packet with an MLCP frame structure, wherein the data packet is a heartbeat keep-alive data packet or a service data packet;
[0089] Business data is obtained from service data packets based on the MLCP frame structure.
[0090] Optionally, the method further includes:
[0091] Once a data segment is successfully read from the data buffer, the data segment is deleted from the data buffer.
[0092] Optionally, the method further includes:
[0093] When all data segments in the data buffer have been successfully read and no new data segments have been written, the data buffer is cleared.
[0094] According to another embodiment of this application, a business data transmission apparatus is provided, deployed at a data sender, wherein the apparatus includes:
[0095] The first module is used to create and initiate an MLCP connection with the data receiver;
[0096] The second module is used to generate heartbeat data packets with MLCP frame structure based on the heartbeat keep-alive sending interval, and to encapsulate the business data to be sent into several business data packets with MLCP frame structure based on the business data sending request.
[0097] The third module is used to split the heartbeat data packet and each service data packet into several data segment packets based on the first data length;
[0098] The fourth module is used to sequentially send heartbeat data packets and several data segments corresponding to each service data packet to the data receiver via Socket.
[0099] According to another embodiment of another aspect of this application, a business data receiving apparatus is provided, deployed at a data receiver, wherein the apparatus includes:
[0100] The fifth module is used to create and initiate an MLCP connection with the data sender;
[0101] The sixth module is used to initialize the data buffer, receive data sent sequentially by the data sender via Socket, and read data according to the second data length based on the first data reading interval to obtain data segments and write them into the data buffer;
[0102] The seventh module is used to read several data segments from the data buffer based on the second data reading interval and assemble them into a data packet with an MLCP frame structure, wherein the data packet is a heartbeat keep-alive data packet or a service data packet;
[0103] The ninth module is used to acquire service data based on the MLCP frame structure of service data packets.
[0104] According to another aspect of this application, a business data transmission system is provided, wherein the system includes:
[0105] The data sender is used to create and initiate an MLCP connection with the data receiver, generate heartbeat data packets with MLCP frame structure based on the heartbeat keep-alive sending interval, encapsulate the business data to be sent into several business data packets with MLCP frame structure based on the business data sending request, split the heartbeat data packets and each business data packet into several data segment packets based on the first data length, and sequentially send the heartbeat data packets and several data segments corresponding to each business data packet to the data receiver through Socket.
[0106] The data receiver is used to create and initiate an MLCP connection with the data sender, initialize a data buffer, receive data sequentially sent by the data sender via a socket, and read data according to a second data length based on a first data reading interval to obtain data segments and write them into the data buffer. Based on the second data reading interval, it reads several data segments from the data buffer and assembles them into a data packet with an MLCP frame structure. The data packet is a heartbeat keep-alive data packet or a service data packet. Based on the service data packet with the MLCP frame structure, it obtains service data.
[0107] Compared with existing technologies, this application provides a service data sending method, receiving method, apparatus, system, and device. The method includes: at the data sender, creating and initiating an MLCP connection with the data receiver; generating a heartbeat data packet with an MLCP frame structure based on a heartbeat keep-alive sending interval, and encapsulating the service data to be sent into several service data packets with an MLCP frame structure based on a service data sending request; splitting the heartbeat data packet and each service data packet into several data segments based on a first data length; and sequentially sending the heartbeat data packet and the several data segments corresponding to each service data packet to the data receiver via a Socket. At the data receiver, an MLCP connection with the data sender is created and initiated, a data buffer is initialized, and data sequentially sent by the data sender is received via a Socket. Based on a first data reading interval and a second data length, data is read to obtain data segments and written to the data buffer. Based on the second data reading interval, several data segments are read from the data buffer and assembled into a data packet with an MLCP frame structure. The data packet is either a heartbeat keep-alive data packet or a service data packet. Service data is obtained based on the service data packet with the MLCP frame structure. This method establishes a long MLCP connection between the data sender and receiver, flexibly splitting business data into custom data segments for transmission. This improves the flexibility of data encapsulation and bandwidth utilization, enhances transmission efficiency, and reduces the number of framework layers, making the code lightweight and reducing CPU, memory, and other resource overhead. Attached Figure Description
[0108] Other features, objects, and advantages of the invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:
[0109] Figure 1 This illustration shows a flowchart of a business data transmission method applied to a data sender, according to one embodiment of one aspect of this application.
[0110] Figure 2 A flowchart illustrating another embodiment of this application of a business data receiving method applied to a data receiver is shown.
[0111] Figure 3 A schematic diagram of a service data transmission apparatus deployed at a data sender, illustrating another embodiment of this application;
[0112] Figure 4 A schematic diagram of a service data receiving device deployed at a data receiver, illustrating another embodiment of another aspect of this application;
[0113] Figure 5 A schematic diagram of a business data transmission system according to another aspect of this application is shown;
[0114] The same or similar reference numerals in the accompanying drawings represent the same or similar parts. Detailed Implementation
[0115] The present invention will now be described in further detail with reference to the accompanying drawings.
[0116] In a typical configuration of various embodiments of this application, each trusted party of the device, system and / or each module of the apparatus may include one or more processors (CPU), input / output interfaces, network interfaces and memory, as well as related software to ensure that the relevant functions are implemented.
[0117] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0118] Computer-readable media include both permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include non-transitory computer-readable media, such as modulated data signals and carrier waves.
[0119] Existing long-connection communication protocols used for byte stream data communication, such as WebSocket and HTTP, either suffer from excessive framework layers and multiple encapsulations, inflexible packet header formats, high bandwidth consumption, and high overhead, leading to high resource utilization; or they provide few callback entry points, making it impossible to customize the connection process, for example, the provided connection callbacks cannot distinguish between connection start, connection in progress, and connection completion nodes; or the parameters related to sending, receiving, and heartbeat keep-alive cannot be customized, resulting in low configurability and scalability. Some even lack heartbeat keep-alive functionality, requiring implementation at the business application level; they cannot record relevant logs for necessary nodes in the connection process, making effective and detailed tracking and offline analysis impossible. When anomalies occur, only the anomaly is recorded, but the specific logical node names are not recorded, making it impossible to determine the root cause of the anomaly. In addition, although most mobile devices use the Android system, there are many versions, requiring consideration of compatibility.
[0120] To address the aforementioned issues, this application provides a byte stream data transmission solution based on MLCP (Multi-frame (Micro) LongConnect Protocol), which can be written in Java. It features a newly designed long-connection protocol and encapsulation method, achieving high bandwidth resource utilization and lightweight code. It does not restrict the data sender or receiver; any device that can provide data transmission services and supports the MLCP protocol is acceptable. Specifically,
[0121] It enables lightweight code and encapsulates necessary core functional classes and auxiliary utility classes. It can customize heartbeat keep-alive data packets according to different network types, provide heartbeat keep-alive mechanisms, customize MLCP frame size, and split MLCP frames according to the custom data segment size before transmitting via Socket. This can reduce resource consumption, reduce packet size and memory usage, and improve transmission efficiency, so that it can be applied to devices that are sensitive to binary file size and have precious running memory resources, such as smartphones, wearable devices or IoT devices, or computer virtual machines.
[0122] It provides atomic logging, which enables finer-grained connection process logging, expands the coverage of key nodes, and facilitates debugging, anomaly tracking, and offline log analysis.
[0123] Improve the extensibility and configurability of callback interfaces so that core variables and parameters can be configured specifically for different system versions, devices, and network environments.
[0124] Customizing the frame format of MLCP packets increases flexibility, allowing for full utilization of bandwidth and reduced overhead during the transmission of data of different magnitudes. It can also reduce CPU, memory, and bandwidth usage during large-volume data transmission.
[0125] This reduces system version dependencies and improves portability, making it applicable to any version of Android system or Android virtual machine that supports Socket communication. The Android system or Android virtual machine must include at least the following core dependencies: java.io.IOException, java.io.InputStream, java.io.OutputStream, java.io.ByteArrayOutputStream, java.io.BufferedWriter, java.io.File, java.io.FileWriter, java.io.IOException, java.io.InputStream, java.util.Enumeration, java.util.Vector, java.net.Socket, java.net.SocketException, java.net.InetAddress, java.net.NetworkInterface, java.net.SocketException, android.content.Context, android.util.Log, android.net.ConnectivityManager, android.net.NetworkInfo, and android.telephony.TelephonyManager.
[0126] Like WebSocket, HTTP / HTTPS, and other long-lived connection protocols, MLCP operates at the application layer in the network architecture, above the Socket interface of the transport layer. An MLCP connection is based on a Socket connection with MLCP protocol encapsulation and a series of protocol control logic, communicating with the transport layer through the Socket. Unlike other long-lived connection protocols, MLCP uses a new encapsulation format to encapsulate application data before communicating with the Socket.
[0127] In this application, the data sender and data receiver are computer devices supporting Socket and MLCP communication and / or JVM-based smart terminal devices supporting network communication. The computer devices include, but are not limited to, personal computers, laptops, industrial computers, network hosts, single network servers, and sets of multiple network servers; the smart terminal devices include, but are not limited to, smartphones, tablets, wearable smart devices, and IoT devices. Here, the computer devices and / or smart terminal devices are merely examples; other existing or future devices and / or resources applicable to this application should also be included within the scope of protection of this application, and are hereby incorporated by reference.
[0128] To further illustrate the technical means adopted and the effects achieved in this application, the technical solution of this application will be clearly and completely described below in conjunction with the accompanying drawings and preferred embodiments.
[0129] Figure 1 The diagram illustrates a flow chart of a data transmission method applied to a data sender according to an embodiment of one aspect of this application, wherein the method includes:
[0130] S101 creates and initiates an MLCP connection with the data receiver;
[0131] S102 generates heartbeat data packets with MLCP frame structure based on the heartbeat keep-alive sending interval, and encapsulates the service data to be sent into several service data packets with MLCP frame structure based on the service data sending request.
[0132] S103, based on the first data length, splits the heartbeat data packet and each service data packet into several data segments respectively;
[0133] S104 sequentially sends heartbeat data packets and several data segments corresponding to each service data packet to the data receiver via Socket.
[0134] This method is applied to the data sender 100. In this embodiment, when a relevant business application in the data sender 100 needs to send business data, an MLCP connection with the data receiver 200 is created and initiated in step S101.
[0135] MLCP employs a lightweight framework and a streamlined hierarchical structure, implementing relevant functionalities by defining and encapsulating related classes.
[0136] Optionally, MLCP includes:
[0137] The MLCPSocket class corresponds to the Socket operation layer in the MLCP hierarchy. It is used to manage Socket connections, send data, and receive data through the Socket interface of the transport layer.
[0138] The MLCPSocketControl class corresponds to the MLCP control layer in the MLCP hierarchical architecture. It inherits from the MLCPSocket class and is used to implement Socket requests with the Socket interface of the transport layer and control the MLCP long connection logic.
[0139] The MLCP class corresponds to the MLCP interface layer in the MLCP hierarchy. It inherits from the MLCPSocketControl class and is used to implement the external public interface.
[0140] The MLCPInterface class is used to provide a callback function interface;
[0141] The MLCPCallBack class is used for callback function management;
[0142] The MLCPLogUtil class provides logging tools.
[0143] The MLCP architecture consists of three layers: the MLCP interface layer that interfaces with the business layer, the MLCP control layer in the middle, and the Socket operation layer that interfaces with the transport layer. MLCP includes classes such as MLCPSocket, MLCPSocketControl, MLCP, MLCPInterface, and MLCPCallBack, which provide core functionalities, and MLCPLogUtil, which provides atomic operation logging functionality.
[0144] In MLCP, the following classes are defined to implement the core functionality:
[0145] The MLCPSocket class corresponds to the Socket operation layer in the MLCP hierarchical architecture. It is used to manage Socket connections, send data, and receive data between the data exchange party (data receiver or data sender) through the Socket interface of the transport layer. The Socket operation layer mainly consists of the following modules:
[0146] The connection management module enables the creation and closure of Socket connections.
[0147] The data transmission module implements the segmentation and transmission of data packets in the MLCP frame structure.
[0148] The data receiving module is responsible for receiving data and managing the receiving buffer, including creating, writing, clearing, and destroying it.
[0149] The MLCPSocketControl class corresponds to the MLCP control layer in the MLCP hierarchical architecture. It inherits from the MLCPSocket class and is used to implement Socket requests and MLCP long connection logic control.
[0150] The MLCP control layer mainly consists of the following modules:
[0151] The configuration item management module, MLCP defines a series of constants and configurable items, which are set to the optimal value by default, and provides a configuration entry point for custom settings.
[0152] The connection management module manages the lifecycle, state, and callbacks of MLCP connections, including creating, closing, and reconnecting Socket connections with data interaction parties through the Socket interface of the transport layer; and managing the lifecycle, state, and callbacks of the heartbeat keep-alive thread to implement MLCP long-connection functionality.
[0153] The data sending management module manages the lifecycle of the data sending thread, the data sending status, and callbacks.
[0154] The data receiving management module manages the lifecycle of the data receiving thread, the data receiving status, and callbacks.
[0155] The MLCP class, corresponding to the MLCP interface layer in the MLCP hierarchy, inherits from the MLCPSocketControl class and is used to implement the external public interface. It provides easy-to-understand and use public methods, callbacks, and configuration entry points.
[0156] The MLCPInterface class is used to provide a callback function interface.
[0157] The MLCPCallBack class is used for callback function management.
[0158] The MLCPLogUtil class provides logging tools.
[0159] Optionally, the MLCPSocket class includes:
[0160] The Socket connection creation interface is used to initialize the Socket connection, initialize the data buffer, and call the data receiving interface to start the data receiving process.
[0161] The Socket connection close interface is used to destroy the data buffer, destroy the data connection thread, and destroy the Socket connection.
[0162] The first data transmission interface is used to split the data packets of the MLCP frame structure into several data segments, and send the corresponding data segments of the data packets of the MLCP frame structure in sequence through the Socket.
[0163] The data receiving interface is used to sequentially receive several data segments corresponding to data packets of the MLCP frame structure via Socket and write the data segments into the data buffer.
[0164] The data buffer management interface is used to initialize, write to, read from, get the length of the data buffer, and clear the data buffer.
[0165] The MLCPSocket class in MLCP is used to manage socket connections and provides the following interfaces:
[0166] 1.1 The Socket connection creation interface can perform the following functions: initialize the Socket connection, initialize the data buffer, and call the data receiving interface to start the data receiving process.
[0167] The 1.2 Socket connection closing interface can perform the following functions: destroy the data buffer, destroy the data connection thread, and destroy the Socket connection.
[0168] 1.3 The first data transmission interface can perform the following functions: split the data packets of the MLCP frame structure into several data segments, and send the corresponding data segments of the data packets of the MLCP frame structure sequentially through the system socket.
[0169] 1.4 The data receiving interface can perform the following functions: sequentially receive several data segments corresponding to data packets with MLCP frame structure through the system Socket, and write the data segments into the data buffer.
[0170] The 1.5 data buffer management interface can perform the following functions: initialize data buffer, write to data buffer, read from data buffer, get data buffer length, and clear data buffer.
[0171] Optionally, the Socket connection creation interface, the Socket connection closing interface, the first data sending interface, and the data receiving interface are further used for:
[0172] Exception handling and logging.
[0173] The MLCPSocket class includes interfaces such as Socket connection creation, Socket connection closure, first data sending, and data receiving. It can also capture and log exceptions in atomic operations such as interface calls, or record changes in key nodes such as network or data transmission status, so as to achieve more granular recording of operation logs for traceability and offline analysis.
[0174] Optionally, the MLCPSocketControl class includes:
[0175] The first initialization interface is used to set the connection name, context object, and logging switch;
[0176] The first setting callback interface is used to initialize the MLCPCallBack class and call the setting callback interface of the MLCPCallBack class;
[0177] The connection interface is started to set parameters such as connection URL, port, heartbeat keep-alive time interval, and disconnection reconnection interval. The Socket connection creation interface is called to create an MLCP connection, a read thread is started to read data from the data buffer, a callback interface is used to return data, the heartbeat keep-alive interface is called to start the heartbeat keep-alive thread, and disconnection reconnection is enabled.
[0178] The heartbeat keep-alive interface is used to send heartbeat keep-alive data packets and reconnect after a disconnection.
[0179] The reconnection port is used to call the Socket connection closing interface to close the MLCP connection and to call the connection starting interface to start the MLCP connection.
[0180] The second data sending interface is used for callback interfaces to call the first data sending interface to send data and reconnect after disconnection.
[0181] The first connection closing interface is used to call the data buffer management interface to clear the data buffer, call the Socket connection closing interface to close the MLCP connection, and destroy the data reading thread.
[0182] The first interface for obtaining connection status is used to return the MLCP connection status.
[0183] The first data clearing interface is used to call the data buffer management interface to clear the data buffer.
[0184] The MLCPSocketControl class in MLCP is used to implement socket connection establishment and MLCP long connection logic control. It inherits from the MLCPSocket class and is a subclass of it. Methods and interfaces included in the MLCPSocket class can be directly referenced without redefining, or they can be overridden to implement new functionality. The MLCPSocketControl class provides the following interfaces:
[0185] 2.1 The Socket connection creation interface can implement the following functions: setting the connection name, context object, and log on / off switch.
[0186] 2.2 The first setting callback interface can achieve the following functions: initialize the MLCPCallBack class and call the setting callback interface of the MLCPCallBack class.
[0187] 2.3 The connection startup interface can perform the following functions: set parameters such as connection URL, port, heartbeat keep-alive interval, and disconnection reconnection interval; call the Socket connection creation interface of the MLCPSocket class to create an MLCP connection; start a read thread to read data from the data buffer; call a callback interface to return data; call the heartbeat keep-alive interface to start the heartbeat keep-alive thread; and disconnection reconnection.
[0188] 2.4 The heartbeat keep-alive interface can implement the following functions: sending heartbeat keep-alive data packets and reconnecting after disconnection. Among them, the MLCP heartbeat keep-alive function allows for custom MLCP frame structure heartbeat keep-alive data packets and allows sending heartbeat keep-alive data packets at custom time intervals, which is handled by calling the callback processing interface of the MLCPInterface class.
[0189] The 2.5 reconnection interface can perform the following functions: call the Socket connection close interface of the MLCPSocket class to close the MLCP connection, and call the above-mentioned connection start interface to start the MLCP connection.
[0190] 2.6 The second data sending interface can implement the following functions: callback interface, calling the first data sending interface of the MLCPSocket class to send data, and reconnection after disconnection.
[0191] 2.7 The first connection closure interface can perform the following functions: call the data buffer management interface of the MLCPSocket class to clear the data buffer, call the Socket connection closure interface of the MLCPSocket class to close the MLCP connection, and destroy the data reading thread.
[0192] 2.8 The first interface for obtaining connection status can achieve the following function: return the MLCP connection status.
[0193] 2.9 The first data clearing interface can achieve the following function: call the data buffer management interface of the MLCPSocket class to clear the data buffer.
[0194] Optionally, the connection initiation interface, the heartbeat keep-alive interface, the reconnection interface, the second data transmission interface, and the first connection termination interface are further used for:
[0195] Exception handling and logging.
[0196] The MLCPSocketControl class includes a connection start interface, a heartbeat keep-alive interface, a reconnection interface, a second data sending interface, and a first connection close interface. It can also capture and log exceptions in atomic operations such as interface calls, enabling finer-grained recording of operation logs for traceability and offline analysis.
[0197] Optionally, the MLCP class includes:
[0198] The second initialization interface is used to call the first initialization interface;
[0199] The second setting callback interface is used to call the first setting callback interface;
[0200] A connection interface, used to call the startup connection interface;
[0201] A data sending interface is used to call the second data sending interface;
[0202] The second interface for obtaining connection status is used to call the first interface for obtaining connection status.
[0203] The second data clearing interface is used to call the first data clearing interface;
[0204] The second close connection interface is used to call the first close connection interface.
[0205] The MLCP class provides the public interface within MLCP. It inherits from the MLCPSocketControl class and is a subclass of MLCPSocketControl. Methods and interfaces included in the MLCPSocketControl class can be directly referenced without redefining, or they can be overridden to implement new functionality. The MLCP class provides the following interfaces:
[0206] 3.1 The second initialization interface can perform the following functions: call the first initialization interface of the MLCPSocketControl class.
[0207] 3.2 The second setting callback interface can achieve the following function: call the first setting callback interface of the MLCPSocketControl class.
[0208] 3.3 The connection interface can achieve the following functions: call the start connection interface of the MLCPSocketControl class.
[0209] 3.4 The data sending interface can perform the following functions: call the second data sending interface of the MLCPSocketControl class.
[0210] 3.5 The second interface for obtaining connection status can achieve the following function: call the first interface for obtaining connection status of the MLCPSocketControl class.
[0211] 3.6 The second clear data interface can realize the following function: call the first clear data interface of the MLCPSocketControl class.
[0212] 3.7 The second connection closing interface can achieve the following function: call the first connection closing interface of the MLCPSocketControl class.
[0213] In this application, the MLCPSocketControl, MLCPSocket, and MLCP classes have an inheritance relationship. The MLCPSocketControl class inherits from the MLCPSocket class and is a subclass of MLCPSocket; correspondingly, the MLCPSocket class is the parent class of the MLCPSocketControl class. Similarly, the MLCP class inherits from the MLCPSocketControl class and is a subclass of MLCPSocketControl; correspondingly, the MLCPSocketControl class is the parent class of the MLCP class. Subclasses can override methods of the parent classes, such as setting environment parameters or variable parameters as needed. When a subclass method is called, it will recursively call the atomic operation of the parent class. For example, the clear data buffer function of the MLCPSocket class's data buffer management interface is the actual atomic operation for clearing the data buffer. When the first close connection interface or the first clear data interface of the MLCPSocketControl class is used to clear the data buffer, the data buffer management interface of the MLCPSocket class will be called. The MLCP class, a subclass of the MLCPSocketControl class, can override the first clear data interface of the MLCPSocketControl class, serving as the second clear data interface of the MLCP class for use by business applications. Therefore, in this application, when a business application needs to clear the data buffer, it needs to first call the second clear data interface of the MLCP class, then call the first clear data interface of the MLCPSocketControl class through the second clear data interface of the MLCP class, and then call the data buffer management interface of the MLCPSocket class through the first clear data interface of the MLCPSocketControl class.
[0214] Optionally, the MLCPCallBack class includes:
[0215] The third step is to set up a callback interface to receive parameters from the MLCPInterface class.
[0216] The callback interface is used to call the callback function of the MLCPInterface class, passing in the business application type, MLCP instance name, connection status and business data, or returning these parameters to the business application.
[0217] The MLCPCallBack class is used for callback function management in MLCP. The MLCPCallBack class provides the following interfaces:
[0218] 4.1 The third setting callback interface can achieve the following function: set the callback interface to receive parameters of the MLCPInterface class.
[0219] 4.2 The callback interface can achieve the following functions: call the callback function of the MLCPInterface class to pass parameters such as business application type, MLCP instance name, connection status and business data from the business application, or return these parameters to the business application.
[0220] Optionally, the MLCPInterface class includes:
[0221] A callback function, wherein the parameters of the callback function include the business application type, MLCP instance name, connection status, and context object.
[0222] In MLCP, the MLCPInterface class provides an interface for calling callback functions. The MLCPInterface class can provide the following function declarations:
[0223] 5.1 Callback functions, such as the SocketNotify function, can take parameters including the business application type, MLCP instance name, connection status, and context object.
[0224] The context object can be business data encapsulated in MLCP, where the business data can be binary data such as strings or images, and its type is not limited.
[0225] The MLCP encapsulation classes MLCPCallBack and MLCPInterface enhance the extensibility of the callback interface and the configurability of related parameters, allowing for the configuration of corresponding variables and / or parameters for different Android system versions, devices, and network environments. Throughout the MLCP long-connection lifecycle, each key node—such as connection establishment, heartbeat keep-alive, data sending, data receiving, connection exceptions, and connection closure—related to network and data transmission status, invokes a unified callback interface. This interface passes the MLCP long-connection instance name, connection status, and context object, allowing business applications to extend their functionality within the callbacks. Configuration items can be set to optimal default values for most devices, and configuration entry points can be provided for user adjustments based on application environment, device and / or business application performance, and network environment. For example, business applications can override callback function methods, read relevant parameters from the callback function method, and execute extended business logic based on the obtained parameters.
[0226] Optionally, the MLCPLogUtil class includes:
[0227] The management log switch interface is used to set and retrieve the log switch status.
[0228] The information log interface is used to print information type logs, and the save log to file interface is called to save the information type logs to a file;
[0229] The debug log recording interface is used to print debug type logs, and the save log to file interface is called to save the debug type logs to a file;
[0230] The warning log interface is used to print warning type logs, and the save log to file interface is called to save the warning type logs to a file;
[0231] The exception logging interface is used to print exception type logs, and the save log to file interface is called to save the exception type logs to a file;
[0232] The interface for saving logs to files is used to create directories, create files, and write files.
[0233] The delete log file interface is used to retrieve expired log files and delete them.
[0234] The MLCPLogUtil class in MLCP provides logging tools. The MLCPLogUtil class provides the following interfaces:
[0235] 6.1 The management log switch interface can achieve the following functions: setting the log switch status and getting the log switch status.
[0236] 6.2 The information log interface can achieve the following functions: print information type logs, and call the save log to file interface to save information type logs to files.
[0237] 6.3 The debug log recording interface can achieve the following functions: print debug type logs, and call the save log to file interface to save debug type logs to a file.
[0238] The 6.4 warning log interface can perform the following functions: print warning type logs, and call the save log to file interface to save warning type logs to a file.
[0239] The 6.5 exception log interface can perform the following functions: print exception type logs, and call the save log to file interface to save exception type logs to a file.
[0240] The 6.6 Save Logs to File interface can perform the following functions: create a log directory, create log files, and write logs of relevant types to the corresponding log files.
[0241] The 6.7 Log File Deletion Interface can perform the following functions: retrieve expired log files and delete them.
[0242] Existing long-connection protocols lack tracking of operational anomalies or state changes at key nodes during long-connection communication, and lack related logs, making offline analysis of these nodes impossible. MLCP, however, divides its framework into classes, interfaces / methods, and atomic operations / functions, providing logging at the atomic operation / function level. For example, log entries can be formatted as "MLCP instance name_time_function_[custom information]", and recorded to files according to the specified format (e.g., log filename format "MLCP instance name_date_serial number"). The log file size can also be set; if the size is exceeded, the logs can be split into multiple files, and a serial number can be added to the filename for identification. Therefore, MLCP supports atomic logging of long-connection processes, expanding the coverage of key nodes in the logs. Logging can be set within each key atomic operation, enabling fine-grained traceability of operation logs. Log entries are persistently stored, supporting offline log analysis.
[0243] Optionally, in step S101, creating and initiating an MLCP connection with the data receiver includes:
[0244] Using the MLCP class, set the first core parameter, which includes: context object, MLCP instance name, and logging switch;
[0245] Using the MLCPSocketControl and MLCPInterface classes, a callback function and a second core parameter are set. The parameters of the callback function include the current MLCP instance name, connection status, and context object. The second core parameter includes: the connection URL, port, heartbeat keep-alive sending interval, disconnection reconnection interval, and data buffer size.
[0246] Based on the second core parameter, create and start an MLCP connection.
[0247] During MLCP initialization, the MLCP class's callback interface is used to set the first core parameters related to the callback function. These first core parameters include: the context object (mlcpContext), the MLCP instance name (mlcpSocketName), and the log switch (logFlag). The MLCPSocketControl and MLCPInterface classes are used to set the callback function and second core parameters. The callback function parameters include the current MLCP instance name, connection status, and context object. The second core parameters include: the connection URL (mlcpUrl), port (mlcpPort), heartbeat keep-alive sending interval (heartGap), reconnection interval (reConnectGap), and data buffer size (SOCKET_BUFLIST_MAX_LEN). Then, based on the second core parameters, an MLCP connection is created and started.
[0248] In MLCP, through callback functions, each operation of each sub-process can promptly send the MLCP instance name, connection status, and context object back to the custom operation class. Business applications using MLCP long-connection communication can listen to the callback functions in a timely manner and complete the business data transmission according to the actual needs of the business application.
[0249] When creating an MLCP connection, the connection interface of the MLCP class is used to set parameters such as the connection URL and port in the second core parameters. Based on the available resources on the device, parameters such as the heartbeat keep-alive sending interval, disconnection reconnection interval, and data buffer size in the second core parameters are also set. For example, default values for these parameters can be set based on the general availability of device resources. After establishing an MLCP connection with the data receiver based on the connection URL, port, and other parameters, the allocated data buffer is initialized according to the data buffer size parameter, and the data receiving sub-process, data reading sub-process, and heartbeat keep-alive sub-process are started simultaneously.
[0250] The public interfaces of the MLCP class in this application ultimately call the interfaces in the MLCPSocketControl and / or MLCPSocket classes. An example initialization interface definition written in Java is shown in Table 1 below.
[0251] Table 1
[0252]
[0253] The callback interface definition can be set as shown in Table 2 below.
[0254] Table 2
[0255]
[0256] The startup connection interface definition is shown in Table 3 below.
[0257] Table 3
[0258]
[0259]
[0260] The data sending interface is defined as shown in Table 4 below.
[0261] Table 4
[0262]
[0263] The data interface definition can be cleared as shown in Table 5 below.
[0264] Table 5
[0265] use Clear data Interface definition void cleanReceiveData() use Clear received data Return value type Return value description void
[0266] The interface for obtaining connection status is defined as shown in Table 6 below.
[0267] Table 6
[0268] Interface name Get connection status Interface definition int getMLCPSocketStatus() use Get the current connection status Return value type Return value description int Connection status, corresponding to Table 8
[0269] An example callback handling interface definition, including a callback handling function for sending MLCP Socket notifications, can be found in Table 7 below.
[0270] Table 7
[0271]
[0272]
[0273] One example connection state may include the states shown in Table 8.
[0274] Table 8
[0275]
[0276] Optionally, if the MLCP connection with the data receiver fails, the data transmission method further includes:
[0277] Based on the disconnection and reconnection interval, restart the MLCP connection with the data receiver.
[0278] After an MLCP connection is established, network anomalies may occur over time, causing the established MLCP connection to break. Therefore, it is usually necessary to check the network connection or the MLCP connection itself before sending business data through the MLCP connection. For example, the relevant interfaces of the MLCPNetUtil class can be used to determine if the network connection is abnormal, and the MLCP heartbeat keep-alive mechanism can be used to determine if the MLCP connection is normal. If the network connection or the MLCP connection is abnormal, data transmission will fail.
[0279] If the MLCP connection fails to start for any reason, a callback function is called to obtain the relevant parameters. After the disconnection and reconnection interval is met, the MLCP connection with the data receiver is re-established based on the relevant parameters.
[0280] Optionally, MLCP further includes:
[0281] The MLCPNetUtil class is used to provide network management;
[0282] The MLCPSysUtil class is used to provide system management;
[0283] The MLCPVerUtil class is used to provide version management.
[0284] MLCP also includes the MLCPNetUtil, MLCPSysUtil, and MLCPVerUtil classes, which provide auxiliary tools.
[0285] Optionally, the MLCPNetUtil class includes:
[0286] The interface for obtaining network connection type is used to retrieve the network type.
[0287] The interface for obtaining network connection status is used to call the underlying system interface to determine the network status and to call the interface for obtaining network connection type to obtain the network type.
[0288] The MLCPNetUtil class in MLCP provides network management functionality. The MLCPNetUtil class provides the following interfaces:
[0289] 7.1 The interface for obtaining network connection type can achieve the following functions: Based on the network information provided by the underlying system interface, obtain the network connection type, such as the type of network on which the MLCP connection between the two parties is based, such as 2G / 3G / 4G / WIFI / other network types.
[0290] 7.2 The interface for obtaining network connection status can achieve the following functions: determine whether the network connection is normal based on the network information provided by the underlying system interface.
[0291] Typically, the process involves first calling the "Get Network Connection Status" interface to determine if the network connection is normal. If the connection is normal, the "Get Network Connection Type" interface is then called to obtain the network type.
[0292] Optionally, the MLCPSysUtil class includes:
[0293] Get IP address interface;
[0294] Interface for obtaining SIM card status;
[0295] The first data type conversion interface is used to convert int to byte array;
[0296] The second data type conversion interface is used to convert byte arrays to int;
[0297] The third data type conversion interface is used to convert input streams into byte arrays;
[0298] A byte array truncation interface for byte array truncation operations;
[0299] The byte array concatenation interface is used for byte array concatenation operations.
[0300] The MLCPSysUtil class in MLCP provides system management functions. The MLCPSysUtil class provides the following interfaces:
[0301] The 8.1 IP address acquisition interface can achieve the following function: acquire the IP address of the data sender.
[0302] 8.2 The SIM card status acquisition interface can achieve the following functions: If the data sending device establishes an MLCP connection with the data receiving device through a mobile network to transmit service data, the SIM card status in the data sending device can be obtained through the SIM card status acquisition interface.
[0303] 8.3 The first data type conversion interface can perform the following function: convert int type data into a byte array.
[0304] 8.4 Second data type conversion interface, which can realize the following function: convert byte arrays into int type data.
[0305] The 8.5 Third Data Type Conversion Interface can perform the following function: converting an input stream into a byte array.
[0306] The 8.6 byte array truncation interface can perform the following functions: byte array truncation operations.
[0307] The 8.7 byte array concatenation interface can perform the following function: byte array concatenation operation.
[0308] Optionally, the MLCPVerUtil class includes:
[0309] The version number retrieval interface is used to obtain the version number of the currently used MLCP.
[0310] The MLCPVerUtil class in MLCP provides version management functionality. The MLCPVerUtil class provides the following interfaces:
[0311] The 9.1 version number retrieval interface can achieve the following function: retrieve the version number of MLCP currently used by the connecting party.
[0312] Continuing in this embodiment, in step S102, the data sender 100 generates a heartbeat data packet with an MLCP frame structure according to a preset heartbeat keep-alive transmission interval, and encapsulates the service data to be sent into several service data packets with an MLCP frame structure according to the service data transmission request of the service application.
[0313] Optionally, the MLCP frame structure includes:
[0314] Compression method field, encryption method field, total frame number field, current frame field, key field, payload length bit width field, payload length field, payload field.
[0315] The MLCP frame structure includes the following fields: compression method, encryption method, total number of frames, current frame, key, payload length (bit width), payload length, and payload. Users can define these fields according to their application scenarios and business needs.
[0316] An exemplary MLCP frame structure is shown in Table 9 below.
[0317] Table 9
[0318]
[0319] The descriptions of each field are as follows:
[0320] 1. Compression method field, occupying 4 bits, where,
[0321] 0: Indicates no compression
[0322] Non-zero values indicate the use of the corresponding compression format (e.g., 1 indicates gzip compression; 2 indicates deflate compression; 3 indicates brotli compression; 4 indicates zlib compression; 5-15: reserved).
[0323] 2. Encryption method, occupying 4 bits, of which,
[0324] 0: Indicates no encryption
[0325] Non-zero: indicates the use of the corresponding compression format (e.g., 1: indicates SHA256; 2-15: reserved).
[0326] 3. Total number of frames, occupying 4 bits, unsigned, represents the total number of MLCP frames encapsulated in the business data, with a maximum of 15 (each bit is 1) and a minimum of 1 (0 is meaningless).
[0327] 4. Current frame number, occupying 4 bits, unsigned, indicating which MLCP frame is the current frame, with a maximum of 15 and a minimum of 1.
[0328] 5. The key should correspond to the largest bit length among the supported encryption methods. For example, if the largest bit length among the supported encryption methods is SHA256, then this field should occupy 256 bits.
[0329] When the value of the encryption method field is 0: this field is empty.
[0330] When the value of the encryption method field is not 0, the key is transmitted in the corresponding field in the first MLCP frame, and it is not necessary to transmit the key in the corresponding field in subsequent MLCP frames. For example, if the total frame number field value is 8 (i.e., the service data is transmitted in 8 MLCP frames), and encrypted transmission is used, then in the first MLCP frame, the value of the encryption method field is 0001, and the key is transmitted in the key field. In the subsequent MLCP frames 2 to 8, the encryption method field and key field can be empty, and the data receiver will ignore the encryption method field and key field in the MLCP frames 2 to 8.
[0331] 6. Payload length bit width, occupying 2 bits, indicates the width of payload data that can be transmitted at one time. The default unit is bytes. It can be identified by N, with a minimum value of 0 and a maximum value of 3.
[0332] 7. Payload length: Set according to the payload length bit width mentioned above, in bytes. Minimum is 0 (payload length bit width is 0), maximum is (2 bytes). 24 -1).
[0333] 8. Payload: The actual service data transmitted in each MLCP frame, determined by the payload length.
[0334] In this example, the maximum supported payload length for a single MLCP frame is (2 24-1) bytes, approximately 16MB, means that the maximum payload that a business application can transmit in a single request is 240MB (16MB * 15 = 240MB). Data sender 100 and data receiver 200 can set the data compression method in the compression method field according to their agreement, and can also set the data encryption method in the encryption method field according to their agreement. Furthermore, they can combine the total number of frames in the MLCP frame with the current frame field to determine whether the MLCP frame needs to be retransmitted and whether the transmission is complete. Through the payload length bit width field, an appropriate bit width can be selected based on the actual application scenario and business needs, combined with the amount of data to be transmitted.
[0335] In the existing WebSocket protocol, the WebSocket frame structure also includes a payload length field, but it also includes an extended payload length field. The payload length field occupies 7 bits. When its value is 0-125, it represents the maximum transmittable payload length, i.e., a maximum of 125 bytes. When its value is 126, the following 2 bytes (16 bits) of the field represent the length of the transmittable payload (the highest bit must be 0), with a maximum of (2...). 15 -1) bytes, which actually occupy (7+16) bits to represent the payload length; when its value is 127, the following 8 bytes (64 bits) of the unsigned integer value are the length of the transmittable payload, with a maximum of (2 63 -1) bytes, which actually occupy (7+64) bits to represent the payload length.
[0336] In the aforementioned exemplary MLCP frame structure, if the transmitted payload does not exceed 256 bytes, the payload length field occupies 8 bits, and the payload length width field occupies 2 bits, so the actual length representation requires (8+2) bits; if the transmitted payload exceeds 256 bytes but does not exceed (2... 16 -1) bytes of payload, the actual length of which requires (16+2) bits; if the transmission exceeds (2) bytes, the actual payload length will be used to occupy (16+2) bits; 16 -1) bytes but not exceeding (2) 24 -1) bytes of payload, the actual length of the payload requires (24+2) bits.
[0337] Therefore, when transmitting large amounts of data, MLCP is more efficient in terms of bandwidth utilization than WebSocket. Furthermore, business applications running on mobile devices and other mobile internet platforms typically involve large data transfers during their interactions, making MLCP more suitable than existing long-connection protocols.
[0338] The MLCP provided in this application allows for customization of the MLCP frame structure according to the application scenario and the amount of business data to be transmitted, which improves the flexibility of data encapsulation and bandwidth utilization, enhances transmission efficiency, and reduces the number of framework layers, lightweight code, and lowers the resource overhead such as CPU and memory.
[0339] Continuing in this embodiment, in step S103, the data sender 100 further splits the heartbeat data packet and service data packet encapsulated into MLCP frames into several data segments according to a preset first data length.
[0340] In this case, the application layer of the data sender can combine the Socket state to split the data packets of the MLCP frame structure into several data segments according to the preset first data length, so that each MLCP frame of the heartbeat data packet and the service data packet can be split into several data segments by itself.
[0341] Optionally, in step S103, when splitting the heartbeat data packet or each service data packet into several data segments, if the length of the last actual remaining data is less than the first data length, then the length of the last data segment is the length of the actual remaining data.
[0342] When splitting each MLCP frame of the heartbeat data packet and the service data packet into several data segments, if the length of the last actual remaining data is less than the first data length, the length of the last data segment can be the length of the actual remaining data.
[0343] Continuing in this embodiment, in step S104, the data sender 100 sequentially sends heartbeat data packets and several data segments corresponding to each service data packet to the data receiver via a Socket.
[0344] When the heartbeat data packet or service data packet of the MLCP frame structure is split into several data segments and sent to the Socket, the heartbeat data packet and several data segments corresponding to each service data packet are sent to the data receiver sequentially through the Socket channel between the data sender 100 and the data receiver 200.
[0345] Once all business data packets have been sent, heartbeat data packets will continue to be sent if the business application does not send a disconnect signal. If the business application no longer sends data, the MLCP connection can be closed to release resources.
[0346] Figure 2 The diagram illustrates a flowchart of a business data receiving method applied to a data receiver according to another embodiment of one aspect of this application, wherein the method includes:
[0347] S201 creates and initiates an MLCP connection with the data sender;
[0348] S202 initializes the data buffer, receives data sequentially sent by the data sender via the Socket, and reads data according to the second data length based on the first data reading interval to obtain data segments and write them into the data buffer;
[0349] S203 reads several data segments from the data buffer based on the second data reading interval and assembles them into a data packet with an MLCP frame structure, wherein the data packet is a heartbeat keep-alive data packet or a service data packet;
[0350] S205 acquires service data based on the MLCP frame structure of service data packets.
[0351] This method is applied to the data receiver 200. In this embodiment, when the data receiver 200 receives an MLCP connection request from the data sender 100, in step S201, it creates and initiates an MLCP connection with the data sender 100. The process of creating and initiating the MLCP connection for the data receiver 200 is the same as or similar to that for the data sender, and will not be described again here.
[0352] Continuing in this embodiment, after the MLCP connection with the data sender 100 is established and started, in step S202, the data receiver 200 initializes the data buffer, receives the data sent sequentially by the data sender 100 through the Socket, and reads the data according to the second data length based on the first data reading interval to obtain the data segment and write it into the data buffer.
[0353] In this process, the data receiver 200 first initializes the data buffer to allocate a data buffer for receiving Socket data segments, sets up a data receiving queue, and then creates a data receiving sub-process. Through the Socket, it receives data sequentially sent by the data sender 100, and periodically reads the sequentially received data according to a preset first data reading interval, placing it into the queue and storing it in the data buffer. Each time, data is read sequentially according to a preset second data length to obtain data segments and write them to the data buffer. The preset first and second data lengths can be different to meet different data read / write control granularities.
[0354] Continuing in this embodiment, in step S203, the data receiver creates a data reading sub-process, reads several data segments sequentially from the data buffer according to the preset second data reading interval and the first-in-first-out principle, and assembles them into a data packet with an MLCP frame structure, wherein the data packet is a heartbeat keep-alive data packet or a service data packet.
[0355] For example, at the data sender 100, based on the amount of business data sent, assuming an MLCP frame includes a 5MB payload and a preset first data length of 512KB, an MLCP frame will be split into 10 data segments and sent sequentially via a socket. At the data receiver, based on a preset first data read interval and assuming a preset second data length of 256KB, data is received sequentially via a socket, and 20 data segments are read and stored in a data buffer. These 20 data segments are then sequentially read from the data buffer, and the resulting MLCP frame also has a 5MB payload. Thus, the transmission and reception of this 5MB of data are completed via the MLCP connection.
[0356] Specifically, if the payload of each MLCP frame of a data packet is empty, then the data packet is a heartbeat keep-alive data packet; if the payload of at least one MLCP frame in the corresponding data packet is not empty, then the data packet is a service data packet.
[0357] Continuing in this embodiment, in step S205, the data receiver sends back the valid data in the service data packet of the MLCP frame structure to the service application, so that the service application can obtain the service data and complete the reception of the service data.
[0358] Optionally, the data receiving method further includes:
[0359] S204 After successfully reading a data segment from the data buffer, delete the data segment from the data buffer.
[0360] In order to avoid reading already read data repeatedly, save storage resources, and improve the efficiency of data buffer usage, in step S203, after a data segment is successfully read from the data buffer, the data segment can be deleted from the data buffer.
[0361] Optionally, the data receiving method further includes:
[0362] S206 When all data segments in the data buffer have been successfully read and no new data segments have been written, the data buffer is cleared.
[0363] When no new data segments are written to the data buffer and all data segments in the data buffer have been successfully read, the data receiver can use the aforementioned clear data interface to clear the data buffer and release storage space.
[0364] If the business application will no longer send data, after clearing the data, the MLCP connection can be closed and the data receiving sub-process destroyed.
[0365] Figure 3The illustration shows a schematic diagram of a service data transmission apparatus deployed at a data sender, according to another embodiment of this application, wherein the apparatus includes:
[0366] The first module 310 is used to create and initiate an MLCP connection with the data receiver;
[0367] The second module 320 is used to generate heartbeat data packets with MLCP frame structure based on the heartbeat keep-alive sending interval, and to encapsulate the service data to be sent into several service data packets with MLCP frame structure based on the service data sending request.
[0368] The third module 330 is used to split the heartbeat data packet and each service data packet into several data segment packets based on the first data length;
[0369] The fourth module 340 is used to sequentially send heartbeat data packets and several data segments corresponding to each service data packet to the data receiver via Socket.
[0370] In this embodiment, the device is integrated into the data sender device. The hardware and software environment of this data sender device is the same as that of the data sender 100 in the aforementioned method embodiments and / or optional embodiments.
[0371] In this embodiment, when a relevant business application in the data sender 100 needs to send business data, the first module 310 of the device creates and initiates an MLCP connection with the data receiver. Then, the second module 320 of the device generates a heartbeat data packet with an MLCP frame structure according to a preset heartbeat keep-alive sending interval. Based on the business data sending request of the business application, the business data to be sent is encapsulated into several business data packets with an MLCP frame structure. Then, the third module 330 of the device splits the heartbeat data packet and business data packet encapsulated into MLCP frames into several data segments according to a preset first data length. Finally, the fourth module 340 of the device sends the data segments to the Socket. Through the Socket, the heartbeat data packet and several data segments corresponding to each business data packet are sequentially sent to the data receiver.
[0372] In the various embodiments and / or optional embodiments of the above-described device, the parts of the method steps performed by each module of the device that are not mentioned are the same as those in the aforementioned related method embodiments, and will not be repeated here.
[0373] Figure 4 The illustration shows another embodiment according to another aspect of this application, providing a schematic diagram of a service data receiving apparatus deployed at a data receiver, wherein the apparatus includes:
[0374] Module 5, 410, is used to create and initiate an MLCP connection with the data sender;
[0375] The sixth module 420 is used to initialize the data buffer, receive data sent sequentially by the data sender via the Socket, and read data according to the second data length based on the first data reading interval to obtain data segments and write them into the data buffer;
[0376] The seventh module 430 is used to read several data segments from the data buffer based on the second data reading interval and assemble them into a data packet with an MLCP frame structure, wherein the data packet is a heartbeat keep-alive data packet or a service data packet;
[0377] Module 450 is used to acquire service data based on the MLCP frame structure of service data packets.
[0378] In this embodiment, the device is integrated into the data receiver device. The hardware and software environment of this data receiver device is the same as that of the data receiver device in the aforementioned method embodiments and / or optional embodiments.
[0379] In this embodiment, when the data receiver 200 receives the MLCP connection request from the data sender 100, it creates and initiates an MLCP connection with the data sender 100 through the fifth module 410 of the device. Then, through the sixth module 420 of the device, it initializes the data buffer, receives the data sent sequentially by the data sender 100 through the Socket, and reads the data according to the second data length based on the first data reading interval, obtains data segments, and writes them into the data buffer. Then, through the seventh module 430 of the device, it creates a data reading sub-process, reads several data segments sequentially from the data buffer according to the preset second data reading interval and the first-in-first-out principle, and assembles them into a data packet of MLCP frame structure. The data packet is a heartbeat keep-alive data packet or a service data packet. Finally, through the ninth module 450 of the device, it sends the valid data in the service data packet of MLCP frame structure back to the service application, so that the service application can obtain the service data and complete the reception of the service data.
[0380] In order to save storage resources and improve the efficiency of data buffer usage, the device may also include an eighth module 440. After the seventh module 330 successfully reads a data segment from the data buffer, the eighth module 440 can delete the data segment from the data buffer.
[0381] The device may also include a tenth module 460, which clears the data buffer when all data segments in the data buffer have been successfully read and no new data segments have been written.
[0382] In the various embodiments and / or optional embodiments of the above-described device, the parts of the method steps performed by each module of the device that are not mentioned are the same as those in the aforementioned related method embodiments, and will not be repeated here.
[0383] Figure 5 The diagram illustrates an embodiment of a business data transmission system according to another aspect of this application, wherein the system 10 includes:
[0384] The data sender 100 is used to create and initiate an MLCP connection with the data receiver, generate a heartbeat data packet with an MLCP frame structure based on the heartbeat keep-alive sending interval, encapsulate the business data to be sent into several business data packets with an MLCP frame structure based on the business data sending request, split the heartbeat data packet and each business data packet into several data segment packets based on the first data length, and sequentially send the heartbeat data packet and several data segments corresponding to each business data packet to the data receiver via a Socket.
[0385] The data receiver 200 is used to create and initiate an MLCP connection with the data sender, initialize a data buffer, receive data sequentially sent by the data sender via a socket, and read data according to a second data length based on a first data reading interval to obtain data segments and write them into the data buffer. It also reads several data segments from the data buffer based on the second data reading interval and assembles them into a data packet with an MLCP frame structure. The data packet is either a heartbeat keep-alive data packet or a service data packet. The service data packet with the MLCP frame structure is used to obtain service data.
[0386] In this embodiment, the system includes a data sender 100 and a data receiver 200, whose hardware and software environments are the same as those of the data receiver 100 and data receiver 200 in the aforementioned method embodiments and / or optional embodiments. The data sender 100 and the data receiver 200 transmit data via a network.
[0387] Specifically, when a relevant business application in the data sender 100 needs to send business data, it will create and start an MLCP connection with the data receiver. Then, based on the heartbeat keep-alive sending interval, it will generate a heartbeat data packet with an MLCP frame structure. Based on the business data sending request, it will encapsulate the business data to be sent into several business data packets with an MLCP frame structure. Then, based on the first data length, it will split the heartbeat data packet and each business data packet into several data segment packets. Finally, it will send the heartbeat data packet and several data segments corresponding to each business data packet to the data receiver sequentially through a Socket to complete the sending of the business data.
[0388] When the data receiver 200 receives an MLCP connection request from the data sender 100, it creates and initiates an MLCP connection with the data sender. Then, it initializes the data buffer, receives the data sent sequentially by the data sender through a socket, and reads the data according to the second data length based on the first data reading interval to obtain data segments and write them into the data buffer. Then, based on the second data reading interval, it reads several data segments from the data buffer and assembles them into a data packet with an MLCP frame structure. The data packet is either a heartbeat keep-alive data packet or a service data packet. Then, based on the service data packet with the MLCP frame structure, it obtains service data to complete the reception of service data.
[0389] According to another aspect of this application, a computer-readable medium is also provided, the computer-readable medium storing computer-readable instructions that can be executed by a processor to implement the foregoing method embodiments.
[0390] It should be noted that the method embodiments and / or optional embodiments in this application do not strictly limit the order of execution of each step, as long as each method embodiment can solve the defects existing in the prior art, achieve the inventive purpose of this application, and obtain beneficial effects. The method embodiments in this application can be implemented in software and / or a combination of software and hardware. The software program involved in this application can be executed by a processor to implement the steps or functions of the above embodiments. Similarly, the software program of this application (including related data structures) can be stored in a computer-readable recording medium.
[0391] Furthermore, part or all of this application can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to this application through the operation of the computer. The program instructions invoking the methods of this application may be stored in a fixed or removable recording medium, and / or transmitted via data streams in broadcast or other signal carrying media, and / or stored in the working memory of a computer device operating according to the program instructions.
[0392] According to another aspect of this application, an apparatus for business data transmission is provided. The apparatus includes: a memory for storing computer program instructions and a processor for executing the program instructions, wherein when the computer program instructions are executed by the processor, the apparatus is triggered to run the methods and / or technical solutions of the foregoing embodiments.
[0393] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the invention. Therefore, the embodiments should be considered illustrative and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within the present invention. No reference numerals in the claims should be construed as limiting the scope of the claims. Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices recited in the apparatus claims may also be implemented by a single unit or device through software and / or hardware. The terms "first," "second," etc., are used to indicate names and do not indicate any particular order.
Claims
1. A method for sending business data, applied to a data sender, characterized in that, The method includes: Create and initiate an MLCP connection with the data receiver. MLCP includes: the MLCPSocket class, corresponding to the Socket operation layer in the MLCP hierarchy, used for Socket connection management, data sending, and data receiving; the MLCPSocketControl class, corresponding to the MLCP control layer in the MLCP hierarchy, inheriting from the MLCPSocket class, used for Socket requests and MLCP long connection logic control; the MLCP class, corresponding to the MLCP interface layer in the MLCP hierarchy, inheriting from the MLCPSocketControl class, used for implementing the external public interface; the MLCPInterface class, used to provide callback function interfaces; the MLCPCallBack class, used for callback function management; and the MLCPLogUtil class, used to provide logging tools. Based on the heartbeat keep-alive sending interval, generate heartbeat data packets with MLCP frame structure, and based on the service data sending request, encapsulate the service data to be sent into several service data packets with MLCP frame structure. Based on the first data length, the heartbeat data packet and each service data packet are split into several data segments respectively; Heartbeat data packets and several data segments corresponding to each service data packet are sequentially sent to the data receiver via Socket.
2. The method according to claim 1, characterized in that, The MLCP also includes: The MLCPNetUtil class is used to provide network management; The MLCPSysUtil class is used to provide system management; The MLCPVerUtil class is used to provide version management.
3. The method according to claim 1, characterized in that, The MLCPSocket class includes: The Socket connection creation interface is used to initialize the Socket connection, initialize the data buffer, and call the data receiving interface to start the data receiving process. The Socket connection close interface is used to destroy the data buffer, destroy the data connection thread, and destroy the Socket connection. The first data transmission interface is used to split the data packets of the MLCP frame structure into several data segments, and send the corresponding data segments of the data packets of the MLCP frame structure in sequence through the Socket. The data receiving interface is used to sequentially receive several data segments corresponding to data packets of the MLCP frame structure via Socket and write the data segments into the data buffer. The data buffer management interface is used to initialize, write to, read from, get the length of the data buffer, and clear the data buffer.
4. The method according to claim 3, characterized in that, The socket connection creation interface, the socket connection closing interface, the first data sending interface, and the data receiving interface are also used for: Exception handling and logging.
5. The method according to claim 3, characterized in that, The MLCPSocketControl class includes: The first initialization interface is used to set the connection name, context object, and logging switch; The first setting callback interface is used to initialize the MLCPCallBack class and call the setting callback interface of the MLCPCallBack class; The connection interface is started to set parameters such as connection URL, port, heartbeat keep-alive time interval, and disconnection reconnection interval. The Socket connection creation interface is called to create an MLCP connection, a read thread is started to read data from the data buffer, a callback interface is used to return data, the heartbeat keep-alive interface is called to start the heartbeat keep-alive thread, and disconnection reconnection is enabled. The heartbeat keep-alive interface is used to send heartbeat keep-alive data packets and reconnect after a disconnection. The reconnection port is used to call the Socket connection closing interface to close the MLCP connection and to call the connection starting interface to start the MLCP connection. The second data sending interface is used for callback interfaces to call the first data sending interface to send data and reconnect after disconnection. The first connection closing interface is used to call the data buffer management interface to clear the data buffer, call the Socket connection closing interface to close the MLCP connection, and destroy the data reading thread. The first interface for obtaining connection status is used to return the MLCP connection status. The first data clearing interface is used to call the data buffer management interface to clear the data buffer.
6. The method according to claim 5, characterized in that, The connection initiation interface, the heartbeat keep-alive interface, the reconnection port, the second data transmission interface, and the first connection termination interface are further used for: Exception handling and logging.
7. The method according to claim 5, characterized in that, The MLCP class includes: The second initialization interface is used to call the first initialization interface; The second setting callback interface is used to call the first setting callback interface; A connection interface, used to call the startup connection interface; A data sending interface is used to call the second data sending interface; The second interface for obtaining connection status is used to call the first interface for obtaining connection status. The second data clearing interface is used to call the first data clearing interface; The second close connection interface is used to call the first close connection interface.
8. The method according to claim 7, characterized in that, The MLCPCallBack class includes: The third step is to set up a callback interface to receive parameters from the MLCPInterface class. The callback interface is used to call the callback function of the MLCPInterface class, passing in the business application type, MLCP instance name, connection status and business data, or returning these parameters to the business application.
9. The method according to claim 8, characterized in that, The MLCPInterface class includes: A callback function, wherein the parameters of the callback function include the business application type, MLCP instance name, connection status, and context object.
10. The method according to claim 9, characterized in that, The MLCPLogUtil class includes: The management log switch interface is used to set and retrieve the log switch status. The information log interface is used to print information type logs, and the save log to file interface is called to save the information type logs to a file; The debug log recording interface is used to print debug type logs, and the save log to file interface is called to save the debug type logs to a file; The warning log interface is used to print warning type logs, and the save log to file interface is called to save the warning type logs to a file; The exception logging interface is used to print exception type logs, and the save log to file interface is called to save the exception type logs to a file; The interface for saving logs to files is used to create directories, create files, and write files. The delete log file interface is used to retrieve expired log files and delete them.
11. The method according to claim 10, characterized in that, Creating and initiating an MLCP connection with the data receiver includes: Using the MLCP class, set the first core parameter, which includes: context object, MLCP instance name, and logging switch; Using the MLCPSocketControl and MLCPInterface classes, a callback function and a second core parameter are set. The parameters of the callback function include the current MLCP instance name, connection status, and context object. The second core parameter includes: the connection URL, port, heartbeat keep-alive sending interval, disconnection reconnection interval, and data buffer size. Based on the second core parameter, create and start an MLCP connection.
12. The method according to claim 11, characterized in that, If the MLCP connection with the data receiver fails, the method further includes: Based on the disconnection and reconnection interval, restart the MLCP connection with the data receiver.
13. The method according to claim 2, characterized in that, The MLCPNetUtil class includes: The interface for obtaining network connection type is used to retrieve the network type. The interface for obtaining network connection status is used to call the underlying system interface to determine the network status and to call the interface for obtaining network connection type to obtain the network type.
14. The method according to claim 2, characterized in that, The MLCPSysUtil class includes: Get IP address interface; Interface for obtaining SIM card status; The first data type conversion interface is used to convert int to byte array; The second data type conversion interface is used to convert byte arrays to int; The third data type conversion interface is used to convert input streams into byte arrays; A byte array truncation interface for byte array truncation operations; The byte array concatenation interface is used for byte array concatenation operations.
15. The method according to claim 2, characterized in that, The MLCPVerUtil class includes: The version number retrieval interface is used to obtain the version number of the currently used MLCP.
16. The method according to claim 1, characterized in that, The MLCP frame structure includes: Compression method field, encryption method field, total frame number field, current frame field, key field, payload length bit width field, payload length field, payload field.
17. The method according to claim 1, characterized in that, In step C, when splitting the heartbeat data packet or each service data packet into several data segments, if the length of the last actual remaining data is less than the first data length, then the length of the last data segment is the length of the actual remaining data.
18. A method for receiving business data, applied to a data receiver, characterized in that, The method includes: Create and initiate an MLCP connection with the data sender. MLCP includes: the MLCPSocket class, corresponding to the Socket operation layer in the MLCP hierarchy, used for Socket connection management, data sending, and data receiving; the MLCPSocketControl class, corresponding to the MLCP control layer in the MLCP hierarchy, inheriting from the MLCPSocket class, used for Socket requests and MLCP long connection logic control; the MLCP class, corresponding to the MLCP interface layer in the MLCP hierarchy, inheriting from the MLCPSocketControl class, used for implementing the external public interface; the MLCPInterface class, used to provide callback function interfaces; the MLCPCallBack class, used for callback function management; and the MLCPLogUtil class, used to provide logging tools. Initialize the data buffer, receive data sent sequentially by the data sender via Socket, and read data according to the second data length based on the first data reading interval to obtain data segments and write them into the data buffer; Based on the second data reading interval, several data segments are read from the data buffer and assembled into a data packet with an MLCP frame structure, wherein the data packet is a heartbeat keep-alive data packet or a service data packet; Business data is obtained from service data packets based on the MLCP frame structure.
19. The method according to claim 18, characterized in that, The method further includes: Once a data segment is successfully read from the data buffer, the data segment is deleted from the data buffer.
20. The method according to claim 19, characterized in that, The method further includes: When all data segments in the data buffer have been successfully read and no new data segments have been written, the data buffer is cleared.
21. A business data transmission device, deployed at a data sender, characterized in that, The device includes: The first module is used to create and initiate an MLCP connection with the data receiver. MLCP includes: the MLCPSocket class, corresponding to the Socket operation layer in the MLCP hierarchy, used for Socket connection management, data sending, and data receiving; the MLCPSocketControl class, corresponding to the MLCP control layer in the MLCP hierarchy, inheriting from the MLCPSocket class, used for Socket requests and MLCP long connection logic control; the MLCP class, corresponding to the MLCP interface layer in the MLCP hierarchy, inheriting from the MLCPSocketControl class, used for implementing the external public interface; the MLCPInterface class, used to provide callback function interfaces; the MLCPCallBack class, used for callback function management; and the MLCPLogUtil class, used to provide logging tools. The second module is used to generate heartbeat data packets with MLCP frame structure based on the heartbeat keep-alive sending interval, and to encapsulate the business data to be sent into several business data packets with MLCP frame structure based on the business data sending request. The third module is used to split the heartbeat data packet and each service data packet into several data segment packets based on the first data length; The fourth module is used to sequentially send heartbeat data packets and several data segments corresponding to each service data packet to the data receiver via Socket.
22. A business data receiving device, deployed at a data receiver, characterized in that, The device includes: The fifth module is used to create and initiate MLCP connections with the data sender. MLCP includes: the MLCPSocket class, corresponding to the Socket operation layer in the MLCP hierarchy, used for Socket connection management, data sending, and data receiving; the MLCPSocketControl class, corresponding to the MLCP control layer in the MLCP hierarchy, inheriting from the MLCPSocket class, used for Socket requests and MLCP long connection logic control; the MLCP class, corresponding to the MLCP interface layer in the MLCP hierarchy, inheriting from the MLCPSocketControl class, used for implementing the external public interface; the MLCPInterface class, used to provide callback function interfaces; the MLCPCallBack class, used for callback function management; and the MLCPLogUtil class, used to provide logging tools. The sixth module is used to initialize the data buffer, receive data sent sequentially by the data sender via Socket, and read data according to the second data length based on the first data reading interval to obtain data segments and write them into the data buffer; The seventh module is used to read several data segments from the data buffer based on the second data reading interval and assemble them into a data packet with an MLCP frame structure, wherein the data packet is a heartbeat keep-alive data packet or a service data packet; The ninth module is used to acquire service data based on the MLCP frame structure of service data packets.
23. A business data transmission system, characterized in that, The system includes: The data sender is responsible for creating and initiating an MLCP connection with the data receiver, generating heartbeat data packets with an MLCP frame structure based on the heartbeat keep-alive sending interval, encapsulating the business data to be sent into several business data packets with an MLCP frame structure based on the business data sending request, splitting the heartbeat data packets and each business data packet into several data segment packets based on a first data length, and sequentially sending the heartbeat data packets and several data segments corresponding to each business data packet to the data receiver via a Socket. MLCP includes: an MLCPSocket class, corresponding to the Socket operation layer in the MLCP hierarchy, used for Socket connection management, data sending, and data receiving; an MLCPSocketControl class, corresponding to the MLCP control layer in the MLCP hierarchy, inheriting from the MLCPSocket class, used for Socket requests and MLCP long connection logic control; an MLCP class, corresponding to the MLCP interface layer in the MLCP hierarchy, inheriting from the MLCPSocketControl class, used for implementing the external public interface; an MLCPInterface class, used to provide callback function interfaces; an MLCPCallBack class, used for callback function management; and an MLCPLogUtil class, used to provide logging tools. The data receiver is used to create and initiate an MLCP connection with the data sender, initialize a data buffer, receive data sequentially sent by the data sender via a socket, and read data according to a second data length based on a first data reading interval to obtain data segments and write them into the data buffer. Based on the second data reading interval, it reads several data segments from the data buffer and assembles them into a data packet with an MLCP frame structure. The data packet is a heartbeat keep-alive data packet or a service data packet. Based on the service data packet with the MLCP frame structure, it obtains service data.
24. A computer-readable medium, characterized in that, It stores computer-readable instructions that are executed by a processor to implement the method as described in any one of claims 1 to 20.
25. A device for transmitting business data, characterized in that, The device includes: One or more processors; and A memory storing computer-readable instructions, which, when executed, cause the processor to perform the operations of the method as described in any one of claims 1 to 20.
Citation Information
Patent Citations
Socket-based client cross-platform network communication method based and related equipment thereof
CN112671760A
Distributed service response method, system and device and storage medium
CN112769776A
