One-to-many communication service system and method based on TCP protocol

By establishing a TCP long connection and cache mechanism on the server side, a one-to-many communication service system is implemented, which solves the problem that the TCP protocol cannot achieve one-to-many communication and improves the reliability and efficiency of data transmission.

CN120378472APending Publication Date: 2025-07-25HAINAN MEDICAL UNIV
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410483343.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2024-04-18
Filing Date
2024-04-22
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

The existing TCP protocol cannot realize one-to-many reliable communication, resulting in data transmission delay and server pressure that cannot meet the needs of one-to-many and many-to-many instant communication.

Method used

By establishing a long TCP connection on the server side, cacheing client data, and actively pushing it to all connected clients, and simultaneously performing message cleaning and resource recycling, a one-to-many communication service system based on the TCP protocol is realized.

Benefits of technology

It realizes multi-device compatible access based on TCP protocol, ensures the reliability and timeliness of data transmission and reception, meets one-to-many and many-to-many communication needs, and reduces server pressure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120378472A_ABST
    Figure CN120378472A_ABST
Patent Text Reader

Abstract

The invention relates to a one-to-many communication service system and method based on a TCP protocol, the system comprises clients and a server, the clients and the server establish TCP long connection, and the server is used for establishing a message list and caching data sent by all the clients; meanwhile, the received data is actively pushed to all connected clients; and the server carries out cleaning and resource recovery on the messages pushed by all the clients. Compatible access of various devices is realized based on the TCP by sharing software algorithms such as a system cache, message insertion, thread processing and the like, and one-to-many and many-to-many communication is realized, so that the reliability of data receiving and transmitting is ensured, and the timeliness of data receiving and transmitting is also considered.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of communication technologies, and particularly relates to a one-to-many communication service system and method based on the TCP protocol. Background Art

[0002] With the continuous progress of technology, the application scenarios of computer data transmission are expanding rapidly. This includes various fields such as streaming media transmission and online games, to communication between Internet of Things devices, and then to real-time data transmission such as financial transactions and medical sensors. In these scenarios, data transmission needs to meet specific requirements, such as timeliness, reliability, diversity, and functions such as multicast and broadcast.

[0003] Currently, the common computer communication protocols are TCP and UDP. Among them, TCP mainly realizes one-to-one reliable communication, while UDP realizes one-to-many and many-to-many unreliable communication. Socket is a virtual layer built on these two protocols, providing corresponding APIs for developers to use these two communication protocols for computer communication. Currently, most game server application scenarios use UDP communication, while websites, chats, and web conferences mostly use the TCP protocol.

[0004] Currently, reliable transmission mostly uses the TCP protocol. Due to its single transmission characteristic, each transmission requires re-handshaking to establish a connection, which will consume a large amount of system resources during this process. At the same time, each TCP transmission will occupy a system port, and TCP transmission itself does not support functions such as multicast and broadcast.

[0005] In current computer communication, one-to-many and many-to-many instant messaging mostly uses the UDP protocol, but the UDP protocol has the risk of unreliable transmission. Although the TCP protocol ensures the reliability of data transmission, it only provides a one-to-one communication method and cannot meet the one-to-many usage scenario. Currently, the reliable transmission method mostly uses the data caching method, that is, the sender sends the data to the server, and the server caches it, and then the receiver queries the cache cyclically. This method has certain problems:

[0006] 1. There is a certain cycle in polling, resulting in data delay.

[0007] 2. Increasing the polling frequency alleviates the data delay to a certain extent, but brings a considerable amount of pressure to the server. Summary of the Invention

[0008] The purpose of the present invention is to overcome the deficiencies of the prior art and propose a one-to-many communication service system and method based on the TCP protocol, which can maintain the stable operation of the power grid, can quickly and accurately give the optimal load transfer scheme, greatly improve the work efficiency of dispatchers, and ensure the safe and stable operation of the power grid.

[0009] The present invention solves its technical problems by adopting the following technical solutions:

[0010] A one-to-many communication service system based on the TCP protocol, including a client and a server. The client establishes a long TCP connection with the server. The server is used to establish a message list and cache all the data sent by the clients. At the same time, the received data is actively pushed to all connected clients. And the server clears and recovers resources for the messages that have been pushed to all clients.

[0011] Moreover, the client includes a desktop terminal, a mobile terminal, a background management terminal, an electrocardiogram sensor, an image collector, and an instruction execution mechanism.

[0012] A communication service method for a one-to-many communication service system based on the TCP protocol, including the following steps:

[0013] Step 1: Start the server and begin to listen on the TCP port;

[0014] Step 2: When the first client accesses, the server creates a new cache pool, a cache maintenance thread, a receiving thread, and a sending thread;

[0015] Step 3: When the second client accesses, determine whether it carries the previous group code. If it carries the previous group code, the server stores the ID of this device in the cache pool of this group and creates a receiving thread and a sending thread for this accessing client. Otherwise, it is recognized as the first client, and return to Step 2 to traverse all clients in turn;

[0016] Step 4: The client sends a broadcast message data packet to the server. The data packet contains the data type and valid data;

[0017] Step 5: The server receives the broadcast message packet, stores the message in the cache pool, and sends a notification to all the sending threads of this group;

[0018] Step 6: The sending threads of this group receive the notification, start and search for the information to be sent. After finding the message, send the message to the corresponding client, and at the same time mark the status of this to-be-sent in the cache pool as sent;

[0019] Step 7: The cache maintenance thread scans and finds that the status of the to-be-sent data is marked as sent, then clears the data;

[0020] Step 8: The client sends a logout request to the server;

[0021] Step 9: The cache maintenance thread scans and finds that all devices have logged out, then clears the cache and closes this thread.

[0022] Moreover, the specific implementation method of step 2 is as follows: When the first client accesses, since there is no group code, the server side defaults to creating an independent group for this client, including creating a new cache pool and a cache maintenance thread, which are used to detect changes in the cache and release the cache information that cannot be used respectively; at the same time, a receiving thread and a sending thread are created for the accessed client, which are used for independent sending and independent receiving respectively, and the two threads are in a blocked state waiting.

[0023] Moreover, the specific implementation method of step 3 is as follows: When the second client accesses, if it carries the previous group code, the server will store the ID of this device in the cache pool of this group. At the same time, a receiving thread and a sending thread are created for the accessed client, which are used for independent sending and independent receiving respectively, and the two threads are in a blocked state waiting.

[0024] Moreover, the cache pool in step 5 is used to store the cache data during the communication process. It is a variable of the ArrayList list type. Each device accessing this group is one piece of information, and each piece of information is a variable of HashMap<String, Object>, which contains: port number, IP address, message queue, etc. information. Among them, the message queue is of the ArrayList list type, and each message is a variable of HashMap<String, Object>, which contains: message type, message body, length, hash check value, device ID that has completed pushing, etc. content.

[0025] Moreover, the cache maintenance thread is used to check whether there is expired data or data that has been completed in the cache pool and clean up this data.

[0026] Moreover, the receiving thread is used to start executing when a message sent by the client is received, store the data in the cache pool, and notify the cache maintenance thread that there is a new message entering and request to send a broadcast.

[0027] Moreover, in step 4, the data type TYPE is of string type; the valid data is the content after the actual payload is converted into a binary stream.

[0028] The advantages and positive effects of the present invention are:

[0029] The present invention includes a client and a server. The client establishes a long TCP connection with the server. The server is used to establish a message list, cache all the data sent by the clients, and at the same time actively push the received data to all connected clients. In addition, the server clears and recycles the resources of the messages that have been pushed to all clients. Through software algorithms such as sharing a system cache, message insertion, and thread processing, the present invention realizes compatible access of multiple devices based on TCP, realizes one-to-many and many-to-many communications, ensures the reliability of data sending and receiving, and also takes into account the timeliness of data sending and receiving. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 is the system framework diagram of the present invention;

[0031] Figure 2 is the flowchart of the communication service method of the present invention;

[0032] Figure 3 is the software architecture diagram for implementing the communication service method of the present invention;

[0033] Figure 4 is the schematic diagram of the cache pool definition of the present invention;

[0034] Figure 5 is the schematic diagram of the structure of the cache pool of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0035] The present invention will be further described in detail below with reference to the accompanying drawings.

[0036] In order to solve the limitations of the existing data transmission scheme, the present invention will conduct a comprehensive research and development on the data transmission platform, explore new transmission mechanisms and algorithms to improve the transmission efficiency and stability. Through experimental verification and performance testing, the performance of the platform in different application scenarios will be evaluated, and it will be compared and analyzed with the existing solutions. The ultimate goal is to provide a comprehensive, efficient, and reliable multi-terminal low-latency communication platform to provide strong support for data transmission applications in some special fields (such as medical, financial, etc.).

[0037] A one-to-many communication service system based on the TCP protocol, as Figure 1 shown, includes a client and a server. The client establishes a long TCP connection with the server. The server is used to establish a message list, cache all the data sent by the clients, and at the same time actively push the received data to all connected clients. In addition, the server clears and recycles the resources of the messages that have been pushed to all clients. The client includes a desktop terminal, a mobile terminal, a background management terminal, an electrocardiogram sensor, an image collector, and an instruction execution mechanism.

[0038] As Figure 3Shown is the software architecture carried on the communication service system, developed based on the JAVA language and environment. Its main dependencies include: classes such as Socket and Thread; including the main thread, software management thread, and communication thread:

[0039] 1. The main thread establishes a listening service for the Socket Tcp protocol, waiting for access requests from devices.

[0040] 2. The software management thread includes managing the status of access threads and providing a common database.

[0041] 3. The communication thread is established after the main thread receives a device request. Each thread corresponds to an access device. The thread is responsible for monitoring the device status and data transmission and reception between the device and the server. Each communication thread can actively disconnect the connection, or the management thread can force a disconnection.

[0042] 1) Server-side code (the main server thread, used to clean the cache, wait for client connections, and establish corresponding threads and services for the connected clients).

[0043]

[0044]

[0045] 2) Client-side code (for each client, a thread needs to be established (the specific class of the service, which contains the definitions of the sending thread, receiving thread, and the content that each client needs to maintain regularly, such as detecting disconnection and automatically closing the port to release resources after disconnection, etc.).

[0046]

[0047]

[0048]

[0049]

[0050]

[0051] 3) Tool code (the class for operating on the main cache. The client needs to call this class to access the unified cache in order to achieve unified, standardized reading and writing. The main thread also needs to call this class to create the cache and clean the cache information code).

[0052]

[0053]

[0054]

[0055] A communication service method for a one-to-many communication service system based on the TCP protocol, as Figure 2 shown, includes the following steps:

[0056] Step 1: Start the server side and start listening on the TCP port;

[0057] Step 2: When the first client accesses, the server side creates a new cache pool, a cache maintenance thread, a receiving thread, and a sending thread;

[0058] When the first client accesses, since there is no group code, the server side defaults to creating an independent group for this client, including creating a new cache pool and a cache maintenance thread, which are respectively used to detect changes in the cache and release unavailable cache information; at the same time, a receiving thread and a sending thread are created for the accessing client, which are respectively used for independent sending and independent receiving (here, the receiving thread and the sending thread of the second client are different from those of the first client, and the server will create two threads for each client accessing the platform, namely the receiving thread and the sending thread. When the receiving thread of any client in this group receives data, after caching the received data, it will wake up the sending threads of other clients to achieve the effect of message distribution.), and the two threads are in a blocked state waiting.

[0059] As Figure 4 and Figure 5 shown, the cache pool is used to store cache data during the communication process. It is an ArrayList list type variable. Each device accessing this group is one piece of information, and each piece of information is a HashMap<String, Object> variable, which contains: port number, IP address, message queue, etc. information. Among them, the message queue is an ArrayList list type, and each message is a HashMap<String, Object> variable, which contains: message type, message body, length, hash check value, device ID that has completed pushing, etc. content.

[0060] The cache maintenance thread is used to check whether there is expired data or data that has been completed for sending in the cache pool, and clean up this data.

[0061] The receiving thread is used to start executing when receiving a message sent by the client, store the data in the cache pool, and notify the cache maintenance thread that new messages have entered and request to send a broadcast.

[0062] Step 3: The second client accesses. Determine whether it carries the previous group code. If it carries the group code, the server stores the ID of the device in the cache pool of this group, and creates a receiving thread and a sending thread for the accessed client. Otherwise, it is considered the first client, and the system will assign a new group code to it;

[0063] The second client accesses. Determine whether it carries the previous group code. If it carries the group code, the server stores the ID of the device in the cache pool of this group, and creates a receiving thread and a sending thread for the accessed client for independent sending and independent receiving, and the two threads are in a blocked state waiting.

[0064] Step 4: The client sends a broadcast message data packet to the server. The data packet contains the data type and the valid data;

[0065] The data type TYPE is of string type, including but not limited to: Text, Zip, Doc, Xls, Hex, Bin, etc. The valid data is the content after converting the actual payload into a binary stream.

[0066] Step 5: The server receives the broadcast message packet, stores the message in the cache pool, and sends a notification to all the sending threads in this group;

[0067] Step 6: The sending thread receives the notification, starts and searches for the information to be sent. After finding the message, it sends the message to the corresponding client, and at the same time marks the status of this pending send in the cache pool as sent;

[0068] Step 7: The cache maintenance thread scans and finds that the status of the data to be sent is marked as sent, then clears the data;

[0069] Step 8: The client sends a logout request to the server;

[0070] Step 9: The cache maintenance thread scans and finds that all devices have logged out, then clears the cache and closes this thread.

[0071] It should be emphasized that the embodiments described in the present invention are illustrative rather than restrictive. Therefore, the present invention includes but is not limited to the embodiments described in the specific implementation manners. Any other implementation manners obtained by those skilled in the art according to the technical solutions of the present invention also fall within the scope of protection of the present invention.

Claims

1. A one-to-many communication service system based on the TCP protocol, characterized in that: It includes a client and a server. The client establishes a long TCP connection with the server. The server is used to create a message list and cache all the data sent by the clients. At the same time, it actively pushes the received data to all connected clients. And the server clears and reclaims resources for the messages that have been pushed to all clients.

2. The one-to-many communication service system based on the TCP protocol according to claim 1, wherein: The client includes a desktop terminal, a mobile terminal, a background management terminal, an electrocardiogram sensor, an image collector, and an instruction execution mechanism.

3. A communication service method for a one-to-many communication service system based on the TCP protocol as described in any one of claims 1 and 2, characterized in that: It includes the following steps: Step 1: Start the server and begin to listen on the TCP port. Step 2: The first client accesses. The server creates a new cache pool, a cache maintenance thread, a receiving thread, and a sending thread. Step 3: The second client accesses. Judge whether it carries the previous group code. If it carries the previous group code, the server stores the ID of this device in the cache pool of this group and creates a receiving thread and a sending thread for this accessing client. Otherwise, it is regarded as the first client, and return to Step 2, and traverse all clients in turn. Step 4: The client sends a broadcast message data packet to the server. The data packet contains the data type and the valid data. Step 5: The server receives the broadcast message packet, stores the message in the cache pool, and sends a notification to all sending threads in this group. Step 6: The sending threads in this group receive the notification, start and search for the information to be sent. After finding the message, send the message to the corresponding client, and at the same time mark the status of this pending sending in the cache pool as sent. Step 7: The cache maintenance thread scans and finds that the status of the pending sending data is marked as sent, then clears the data. Step 8: The client sends a logout request to the server. Step 9: The cache maintenance thread scans and finds that all devices have logged out, then clears the cache and closes this thread.

4. The communication service method of a one-to-many communication service system based on the TCP protocol according to claim 3, characterized in that: The specific implementation method of Step 2 is as follows: When the first client accesses, since there is no group code, the server defaults to creating an independent group for this client, including creating a new cache pool and a cache maintenance thread, which are respectively used to detect changes in the cache and release the cache information that cannot be used. At the same time, a receiving thread and a sending thread are created for this accessing client, which are respectively used for independent sending and independent receiving, and the two threads are in a blocked state waiting.

5. The communication service method of a one-to-many communication service system based on the TCP protocol according to claim 3, characterized in that: The specific implementation method of Step 3 is as follows: When the second client accesses, if it carries the previous group code, the server stores the ID of this device in the cache pool of this group, and at the same time creates a receiving thread and a sending thread for this accessing client, which are used for independent sending and independent receiving, and the two threads are in a blocked state waiting.

6. The communication service method of a one-to-many communication service system based on the TCP protocol according to claim 4, characterized in that: In step 5, the cache pool is used to store cache data during the communication process. It is a variable of the ArrayList list type. Each device accessing this group is one piece of information, and each piece of information is a variable of HashMap<String, Object>, which contains information such as port number, IP address, message queue, etc. The message queue is of the ArrayList list type, and each message is a variable of HashMap<String, Object>, which contains content such as message type, message body, length, hash check value, device ID that has completed pushing, etc.

7. The communication service method of a one-to-many communication service system based on the TCP protocol according to claim 4, characterized in that: The cache maintenance thread is used to check whether there is expired data or data that has been sent in the cache pool and clean up this data.

8. The communication service method of a one-to-many communication service system based on the TCP protocol according to claim 4, characterized in that: The receiving thread is used to start executing when a message sent by the client is received, store the data in the cache pool, and notify the cache maintenance thread that new messages have entered and request to send a broadcast.

9. The communication service method of a one-to-many communication service system based on the TCP protocol according to claim 3, characterized in that: In step 4, the data type TYPE is of the string type; the valid data is the content after the actual payload is converted into a binary stream.

Citation Information

Cited By

  • Data transmission method and system for single-terminal multi-GNSS (Global Navigation Satellite System) equipment

    CN121814188A

  • A data transmission method and system for single-terminal multi-GNSS device

    CN121814188B