Full-response non-blocking implementation method based on Internet of Things

By using non-blocking sockets and non-blocking IO methods in the Internet of Things, the problems of network delay and resource waste in traditional communication technology are solved, efficient Internet of Things communication is achieved, and system resource utilization and communication quality are improved.

CN118714083APending Publication Date: 2024-09-27山东浪潮智慧建筑科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410796860.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-19
Publication Date
2024-09-27

AI Technical Summary

Technical Problem

Traditional communication technology in the Internet of Things has problems such as high network latency, large data transmission delay, limited communication bandwidth, and resource waste caused by synchronization blocking. It cannot meet the needs of efficiently utilizing system resources and improving communication quality.

Method used

Adopting a fully responsive non-blocking implementation method based on the Internet of Things, by establishing a non-blocking socket and non-blocking IO to implement the server, multiple IoT clients are allowed to communicate with each other and scheduled through the server to avoid current thread blocking and improve resources. Utilization.

Benefits of technology

It achieves improved system resource utilization, improved communication quality and efficiency in Internet of Things communications, and is suitable for application scenarios with high real-time requirements and large-scale data transmission.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118714083A
    Figure CN118714083A
Patent Text Reader

Abstract

The invention discloses a full-response non-blocking implementation method based on the Internet of Things, and relates to the technical field of network communication, and the method comprises the steps: building a socket, and setting the socket to be in a non-blocking state; a server is realized in combination with the socket and the non-blocking IO, and the server is connected with a plurality of Internet of Things clients; and when the plurality of Internet of Things clients carry out data communication, scheduling of data communication is realized through the server. According to the method, the server is realized by adopting the socket in the non-blocking state and the non-blocking IO, and when a plurality of Internet of Things clients communicate, if the Internet of Things clients cannot immediately obtain communication results, the server does not block the current thread. The released communication resources can be polled, and the service process is searched for the Internet of Things client needing communication, so that the utilization rate of the system resources is realized, and the communication quality and efficiency are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of network communication technology, and in particular to a full-response non-blocking implementation method based on the Internet of Things. Background Art

[0002] With the rapid development of Internet of Things technology, the Internet of Things has been widely used in all aspects of modern life. In order to improve the quality of IoT intelligent services, more and more IoT communication devices play an important role. With the increase of communication devices, the communication quality between devices is particularly important. Only high-quality communication quality can ensure the normal communication between multiple communication devices.

[0003] However, traditional communication technologies face many challenges in the Internet of Things. On the one hand, the high network latency leads to a large delay in data transmission, which is not suitable for IoT systems with high real-time requirements. On the other hand, the communication bandwidth is limited and cannot meet the application scenarios of large-scale data transmission and high bandwidth requirements. In addition, traditional communication technologies usually use synchronous blocking to transmit data, which leads to waste of system resources and inefficient use.

[0004] Therefore, how to improve the utilization of system resources to improve communication quality and efficiency is a technical problem that needs to be solved urgently in the field of physical network communications. Summary of the invention

[0005] In order to solve the above technical problems, this application proposes the following technical solutions:

[0006] In a first aspect, an embodiment of the present application provides a fully responsive non-blocking implementation method based on the Internet of Things, including:

[0007] Create a socket and set the socket to non-blocking state;

[0008] Combining the socket and non-blocking IO to implement a server, the server is connected to multiple IoT clients;

[0009] When a plurality of the IoT clients perform data communication, the data communication is scheduled through the server.

[0010] In a possible implementation, establishing a socket and setting the socket to a non-blocking state includes:

[0011] Set the file descriptor fcntl of the socket;

[0012] Define the structure of the socket struct flcok;

[0013] The socket is created by combining the file descriptor fcntl and the structure struct flcok.

[0014] In a possible implementation, setting the file descriptor fcntl of the socket includes:

[0015] Determine the file descriptor fd and setting function cmd that need to be set for the socket;

[0016] Set the file description word status flag, which is the parameter flags of the function open();

[0017] Get the file lock status of the file descriptor;

[0018] The file lock state is set, and the type value of the lock structure is F_RDLCK or F_WRLCK;

[0019] If the lock cannot be established, the error code EACCES is returned, and the lock is repeatedly attempted until it is successful.

[0020] In a possible implementation, the structure struct flcok defining the socket includes:

[0021] Determine the beginning position of the lock area of ​​the structure struct flcok, the size of the lock area and the lock action process;

[0022] Establish a lock for reading and a lock for writing and delete previously established locks;

[0023] Define the beginning of the file, the current file read / write position, or the end of the file as the starting position of the new lock.

[0024] In a possible implementation, the combination of the socket and non-blocking IO to implement a server includes:

[0025] Defining and declaring the address structure of the server;

[0026] Configure the IP and port number information of the server;

[0027] Set the server listening socket to non-blocking attribute.

[0028] In a possible implementation manner, the defining and declaring the address structure of the server includes:

[0029] Set up a structure to save the descriptor of each online IoT client to record the current online IoT client;

[0030] The socket connected to the structure is first set to a non-blocking state.

[0031] In a possible implementation, setting the socket connected to the structure to a non-blocking state first includes:

[0032] Get the properties of the socket descriptor connect_fd;

[0033] Set the attribute information and add the non-blocking state;

[0034] Set the configured properties back to the descriptor connect_fd;

[0035] Update and save the descriptors of the newly connected clients one by one.

[0036] In a possible implementation, configuring the IP and port number information of the server includes:

[0037] Set the server address htonl(INADDR_ANY), where INADDR_ANY refers to any address in the local machine;

[0038] Use the IPV4 protocol cluster to set the server port number to 65000;

[0039] Bind the address information of the server, including IP, port number and protocol cluster.

[0040] In a possible implementation, setting the server listening socket to a non-blocking attribute includes:

[0041] Get the attributes of the listening socket descriptor sock_fd;

[0042] Set the attribute information and add the non-blocking state;

[0043] Return the set attribute information to the descriptor sock_fd.

[0044] In a possible implementation, when the plurality of IoT clients perform data communication, the server implements the scheduling of data communication, including:

[0045] The listening socket descriptor sock_fd is set to a non-blocking attribute and starts at -1. If the descriptor becomes a number greater than 0, there is an IoT client connected for communication;

[0046] Poll newly connected IoT clients for data arrival;

[0047] If data from a newly connected IoT client is received, the data transmission process in the sleeping state is awakened to serve the data transmission.

[0048] In the second aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored program, wherein when the program is running, the device where the computer-readable storage medium is located is controlled to execute the method described in any possible implementation method of the first aspect.

[0049] In the embodiment of the present application, a non-blocking socket and non-blocking IO are used to implement the server. When multiple IoT clients communicate, if the IoT client cannot get the communication result immediately, the server will not block the current thread. It will poll the released communication resources to find the service process for the IoT client that needs to communicate, thereby realizing the utilization of system resources and improving the communication quality and efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 A flowchart of a fully responsive non-blocking implementation method based on the Internet of Things provided in an embodiment of the present application;

[0051] Figure 2 Schematic diagram of data communication scheduling for multiple IoT clients implemented by the server. DETAILED DESCRIPTION

[0052] The present solution is described below in conjunction with the accompanying drawings and specific implementation methods.

[0053] See also Figure 1 , the fully responsive non-blocking implementation method based on the Internet of Things provided in this embodiment includes:

[0054] S101, establish a socket and set the socket to a non-blocking state.

[0055] Socket is an abstraction of the endpoint for two-way communication between application processes on different hosts in the network. A socket is one end of the process communication on the network, providing a mechanism for application layer processes to exchange data using network protocols. In terms of its position, the socket is connected to the application process at the top and the network protocol stack at the bottom. It is the interface for the application to communicate through the network protocol and the interface for the application to interact with the network protocol stack.

[0056] In this embodiment, the file descriptor fcntl of the socket is set; the structure struct flcok of the socket is defined; and the socket is created by combining the file descriptor fcntl and the structure struct flcok.

[0057] Specifically, the setting of the file descriptor fcntl of the socket includes: determining the file descriptor fd and setting function cmd that need to be set for the socket; setting the file descriptor status flag, which is the parameter flags of the function open(); obtaining the file lock status of the file descriptor; setting the file lock status, at which time the type value of the lock structure is F_RDLCK or F_WRLCK; if the lock cannot be established, returning an error code EACCES, and then repeatedly trying to lock until the lock is successful.

[0058] The structure struct flcok of the socket is defined, including: determining the beginning position of the lock area of ​​the structure struct flcok, the size of the lock area and the lock action process; establishing a lock for reading and a lock for writing and deleting the previously established lock; defining the beginning of the file, the current file read and write position or the end of the file as the starting position of the new lock.

[0059] S102, combining the socket and non-blocking IO to implement a server, wherein the server is connected to multiple IoT clients.

[0060] Specifically, the address structure of the server is defined and declared; the IP and port number information of the server is configured; and the listening socket of the server is set to a non-blocking attribute.

[0061] In this embodiment, the address structure of the server is defined and declared, including: setting a structure to save the descriptor of each online Internet of Things client to record the current online Internet of Things client; setting the socket connected to the structure to a non-blocking state first.

[0062] The socket connected to the structure is first set to a non-blocking state, including: obtaining the attributes of the socket descriptor connect_fd; setting the attribute information and adding a non-blocking state; setting the configured attributes back to the descriptor connect_fd; and updating and saving the descriptors of the newly connected client in sequence.

[0063] In this embodiment, configuring the IP and port number information of the server includes: setting the server address htonl (INADDR_ANY), where INADDR_ANY refers to any address in the local machine; using the IPV4 protocol cluster to set the server port number to 65000; binding the address information of the server, including the IP, port number and protocol cluster.

[0064] Setting the server listening socket to a non-blocking attribute includes: obtaining the attribute of the listening socket descriptor sock_fd; setting the attribute information and adding a non-blocking state; and returning the set attribute information to the descriptor sock_fd.

[0065] S103, when a plurality of the IoT clients perform data communication, the server implements the scheduling of the data communication.

[0066] The listening socket descriptor sock_fd is set to the non-blocking attribute and starts at -1. If the descriptor becomes a number greater than 0, there is an IoT client connected for communication; poll the newly connected IoT client for data arrival; if data from the newly connected IoT client is received, wake up the data transmission process in the sleeping state to provide data transmission services, such as Figure 2 shown.

[0067] Corresponding to the above embodiment, the embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium may store a program, wherein when the program is running, the device where the computer-readable storage medium is located may be controlled to perform some or all of the steps in the above method embodiment. In a specific implementation, the computer-readable storage medium may be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).

[0068] Corresponding to the above-mentioned embodiment, the embodiment of the present application further provides a computer program product, which includes executable instructions. When the executable instructions are executed on a computer, the computer executes some or all of the steps in the above-mentioned method embodiment.

[0069] In the embodiments of the present application, "at least one" refers to one or more, and "plurality" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent the existence of A alone, the existence of A and B at the same time, and the existence of B alone. Among them, A and B can be singular or plural. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship. "At least one of the following" and similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b and c can be represented by: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple.

[0070] The above is only a specific implementation of the present application. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. The protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A fully responsive non-blocking implementation method based on the Internet of Things, characterized in that: include: Create a socket and set the socket to non-blocking state; Combining the socket and non-blocking IO to implement a server, the server is connected to multiple IoT clients; When a plurality of the IoT clients perform data communication, the data communication is scheduled through the server.

2. The method for realizing full response and non-blocking based on the Internet of Things according to claim 1 is characterized in that: The step of establishing a socket and setting the socket to a non-blocking state comprises: Set the file descriptor fcntl of the socket; Define the structure of the socket struct flcok; The socket is created by combining the file descriptor fcntl and the structure struct flcok.

3. The method for realizing full response and non-blocking based on the Internet of Things according to claim 2 is characterized in that: The file descriptor fcntl of the socket is set, including: Determine the file descriptor fd and setting function cmd that need to be set for the socket; Set the file description word status flag, which is the parameter flags of the function open(); Get the file lock status of the file descriptor; The file lock state is set, and the type value of the lock structure is F_RDLCK or F_WRLCK; If the lock cannot be established, the error code EACCES is returned, and the lock is repeatedly attempted until it is successful.

4. The method for realizing full response and non-blocking based on the Internet of Things according to claim 2 is characterized in that: The structure struct flcok defining the socket includes: Determine the beginning position of the lock area of ​​the structure struct flcok, the size of the lock area and the lock action process; Establish a lock for reading and a lock for writing and delete previously established locks; Define the beginning of the file, the current file read / write position, or the end of the file as the starting position of the new lock.

5. The method for realizing full response and non-blocking based on the Internet of Things according to claim 3 is characterized in that: The combination of the socket and non-blocking IO implements a server, including: Defining and declaring the address structure of the server; Configure the IP and port number information of the server; Set the server listening socket to non-blocking attribute.

6. The method for realizing full response and non-blocking based on the Internet of Things according to claim 5 is characterized in that: The defining and declaring of the address structure of the server includes: Set up a structure to save the descriptor of each online IoT client to record the current online IoT client; The socket connected to the structure is first set to a non-blocking state.

7. The method for realizing full response and non-blocking based on the Internet of Things according to claim 6 is characterized in that: The step of setting the socket connected to the structure to a non-blocking state first includes: Get the properties of the socket descriptor connect_fd; Set the attribute information and add the non-blocking state; Set the configured properties back to the descriptor connect_fd; Update and save the descriptors of the newly connected clients one by one.

8. The method for realizing full response and non-blocking based on the Internet of Things according to claim 5 is characterized in that: The configuration of the IP and port number information of the server includes: Set the server address htonl(INADDR_ANY), where INADDR_ANY refers to any address in the local machine; Use the IPV4 protocol cluster to set the server port number to 65000; Bind the address information of the server, including IP, port number and protocol cluster.

9. The method for realizing full response and non-blocking based on the Internet of Things according to claim 5, characterized in that: The setting of the server listening socket to a non-blocking attribute includes: Get the attributes of the listening socket descriptor sock_fd; Set the attribute information and add the non-blocking state; Return the set attribute information to the descriptor sock_fd.

10. The method for realizing full response and non-blocking based on the Internet of Things according to claim 6, 8 or 9, characterized in that: When the plurality of IoT clients perform data communication, the server implements the scheduling of data communication, including: The listening socket descriptor sock_fd is set to a non-blocking attribute and starts at -1. If the descriptor becomes a number greater than 0, there is an IoT client connected for communication; Poll newly connected IoT clients for data arrival; If data from a newly connected IoT client is received, the data transmission process in the sleeping state is awakened to serve the data transmission.