A tcp connection-based state adjustment method and device
By judging the idle state of the TCP connection, releasing and creating a new socket, the problem of resource waste caused by maintaining the TCP connection for a long time is solved, and the concurrent processing capability of the TCP connection is improved.
Patent Information
- Application Number
- CN202211585775.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-09
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2042-12-09
AI Technical Summary
Maintaining TCP connections for a long time causes a waste of system resources and reduces the concurrent processing capabilities of TCP connections of the server and proxy processes.
By judging the idle state of the TCP connection, releasing the TCP connection sockets in the server and proxy processes, and creating a new timewait socket, the TCP connection state adjustment is optimized.
It reduces the memory usage of TCP connections, improves the concurrent processing capability of TCP connections, and improves the efficiency of system resource utilization.
Smart Images

Figure CN115941768B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a method and device for adjusting the state of a TCP connection. Background Art
[0002] Currently, when using the TCP protocol for client-server communication, there are two memory bottlenecks that can affect the concurrent processing capacity of TCP connections. However, in practice, it has been found that when a client initiates a request to establish a TCP connection with a server process, the connection between them is not automatically closed. After the client sends a request, the connection state remains for a long time without sending a second request. This persistent TCP connection wastes system resources and reduces the concurrent processing capacity of the server process. In addition, when a server, acting as a proxy process, receives a client request and initiates a request to establish a TCP connection with an upstream server, if the upstream server responds slowly, the connection state is maintained for a long time, which can significantly reduce the concurrent processing capacity of the proxy process. Summary of the Invention
[0003] The purpose of the embodiments of the present application is to provide a state adjustment method and device based on TCP connection, which can automatically identify the working state of TCP connection, so that the idle TCP connection can automatically reserve performance for the connected TCP connection, thereby improving the concurrency capability of TCP connection.
[0004] A first aspect of an embodiment of the present application provides a state adjustment method based on a TCP connection, comprising:
[0005] When receiving a TCP connection establishment request sent by the client, establishing a TCP connection between the client and the server;
[0006] Determining whether a subsequent TCP connection request sent by the client based on the TCP connection is received;
[0007] When no subsequent request for the TCP connection sent by the client based on the TCP connection is received, determining whether the TCP connection is in an idle state;
[0008] When the TCP connection is not in the idle state, setting the TCP connection to the idle state;
[0009] Release the TCP connection socket in the server process, and create a new TCP waiting socket in the server process.
[0010] In the above implementation, the method can prioritize establishing a TCP connection between the client and the server upon receiving a TCP connection establishment request from the client. This method can establish a corresponding TCP connection based on the client's TCP connection request, thereby ensuring a reliable basis for establishing the TCP connection and, in turn, ensuring the reliability of the TCP connection. The method can then determine whether a subsequent TCP connection request from the client based on the TCP connection has been received. Furthermore, if no subsequent TCP connection request from the client based on the TCP connection has been received, the method can determine whether the TCP connection is in an idle state. This method can detect subsequent TCP connection requests in real time and use this to determine whether to check the working state of the TCP connection. When there are persistent TCP connection requests, the method avoids unnecessary state checks, thereby ensuring accurate adjustment reason and state basis for TCP state adjustment, thereby improving the effectiveness of TCP connection state adjustment. Furthermore, when the TCP connection is not in an idle state, the TCP connection is set to an idle state. This method can automatically convert the TCP working state to an idle state when the TCP connection is not in an idle state but has no subsequent TCP requests, thereby achieving automatic adjustment of the TCP connection state. Finally, the method releases the TCP connection socket in the server process and creates a new TCP waiting socket in the server process. This shows that when the method determines that the TCP working state is idle, it automatically releases the corresponding TCP connection socket and creates a TCP waiting socket that consumes almost no resources. This frees up more resources for parallel processing tasks, thereby achieving better TCP connection concurrency and improving TCP connection concurrency.
[0011] Furthermore, the method further comprises:
[0012] When the TCP connection is in the idle state, the step of determining whether a subsequent TCP connection request sent by the client based on the TCP connection is received is triggered.
[0013] In the above implementation process, the method can automatically detect whether there is a subsequent request for the TCP connection when detecting that the TCP connection is in an idle state, thereby ensuring the standby working capability, avoiding the interruption of the TCP connection, and at the same time improving the connection concurrency capability of the TCP connection.
[0014] Furthermore, the method further comprises:
[0015] When receiving the TCP connection subsequent request sent by the client based on the TCP connection, determining whether the TCP connection is in an idle state;
[0016] When the TCP connection is in the idle state, setting the TCP connection to a connected state;
[0017] Releases a tcp wait socket in a server process and resumes a tcp connection socket in the server process.
[0018] In the above implementation process, the method can determine whether the TCP connection is in an idle state when receiving a subsequent TCP connection request sent by the client based on the TCP connection; it can be seen that the method can detect the working status of the TCP connection at any time, wherein the method can recover the TCP connection for which there is a request but the TCP connection is in an idle state, thereby enabling the free release and recovery of working resources. Specifically, the method can set the TCP connection to a connected state when the TCP connection is in an idle state; and further release the TCP waiting socket in the server process, and restore the TCP connection socket in the server process. It can be seen that the method can convert the TCP connection from an idle state to a connected state, and further adjust the socket based on this state, thereby achieving the state adjustment effect of the TCP connection.
[0019] Furthermore, the method further comprises:
[0020] When the TCP connection is not in the idle state, a corresponding operation is performed based on a subsequent request of the TCP connection.
[0021] In the above implementation process, the method can also perform corresponding operations based on subsequent requests of the TCP connection when the TCP connection is not in an idle state, thereby ensuring the normal use of the TCP connection in a connected state.
[0022] Furthermore, the method further comprises:
[0023] When the TCP connection is not in an idle state, sending a TCP connection proxy request to the host computer;
[0024] Determine whether the response information fed back by the host computer is received;
[0025] When the response information is not received, the TCP connection socket in the server process is released, and a new TCP waiting socket is created in the server process.
[0026] In the above implementation process, the method can also send a TCP connection proxy request to the host computer when the TCP connection is not in an idle state; it can be seen that the method can use multiple servers to make one of the servers become a proxy server to execute the proxy process, so that the method can be applied to a nested application environment, and the number of nesting is not limited. Then, the method can determine whether the response information fed back by the host computer is received; and when the response information is not received, the TCP connection socket in the server process is released, and a new TCP waiting socket is created in the server process. It can be seen that the method can create a new TCP waiting socket in the proxy process, so that the server as a proxy process can respond to the host computer in real time, thereby achieving timely response.
[0027] Furthermore, the method further comprises:
[0028] When the response information is received, determining whether there is a TCP waiting socket in the server process;
[0029] When the server process has the tcp waiting socket, the tcp waiting socket in the server process is released, and the tcp connection socket is restored in the server process.
[0030] In the above implementation process, the method can also determine whether there is a TCP waiting socket in the server process when receiving the response information; and if there is a TCP waiting socket in the server process, release the TCP waiting socket in the server process and restore the TCP connection socket in the server process. It can be seen that this method can adjust the TCP socket in time when the server receives the response from the host computer, so that the working state of the TCP connection can be adjusted in time, thereby achieving a better state adjustment effect of the TCP connection.
[0031] Furthermore, the method further comprises:
[0032] When the server process does not have the TCP waiting socket, a TCP connection is established between the server and the host computer.
[0033] In the above implementation process, the method can also establish a TCP connection between the server and the host computer when there is no TCP waiting socket in the server process. It can be seen that the method can automatically establish a TCP connection between the proxy process and the host computer when the TCP status is normal, thereby achieving an effective proxy connection effect.
[0034] A second aspect of an embodiment of the present application provides a state adjustment device based on a TCP connection, the state adjustment device based on a TCP connection comprising:
[0035] An establishing unit, configured to establish a TCP connection between the client and the server upon receiving a TCP connection establishment request sent by the client;
[0036] A first determining unit is configured to determine whether a subsequent TCP connection request sent by the client based on the TCP connection is received;
[0037] A second judging unit is configured to judge whether the TCP connection is in an idle state when no subsequent TCP connection request sent by the client based on the TCP connection is received;
[0038] A setting unit, configured to set the TCP connection to the idle state when the TCP connection is not in the idle state;
[0039] The regulating unit is used for releasing the TCP connection socket in the server process and creating a new TCP waiting socket in the server process.
[0040] In the above implementation process, the device can establish a TCP connection between the client and the server through the establishment unit when receiving a TCP connection establishment request sent by the client; then, the first judgment unit is used to judge whether a subsequent TCP connection request sent by the client based on the TCP connection is received; and the second judgment unit is used to judge whether the TCP connection is in an idle state when the subsequent TCP connection request sent by the client based on the TCP connection is not received; then, the setting unit is used to set the TCP connection to the idle state when the TCP connection is not in the idle state; finally, the adjustment unit is used to release the TCP connection socket in the server process and create a new TCP waiting socket in the server process. It can be seen that the device can automatically identify the working status of the TCP connection, so that the TCP connection in the idle state can automatically reserve performance for the TCP connection in the connected state, thereby improving the concurrency capability of the TCP connection.
[0041] Furthermore, the first judgment unit is specifically configured to, when the TCP connection is in the idle state, determine whether a subsequent TCP connection request sent by the client based on the TCP connection is received.
[0042] Furthermore, the second judging unit is further configured to, when receiving the TCP connection subsequent request sent by the client based on the TCP connection, judge whether the TCP connection is in an idle state;
[0043] The setting unit is further configured to set the TCP connection to a connected state when the TCP connection is in the idle state;
[0044] The adjusting unit is further configured to release the tcp waiting socket in the server process and restore the tcp connection socket in the server process.
[0045] Further, the tcp connection state adjustment device further comprises:
[0046] The communication unit is configured to perform corresponding operations based on the subsequent request of the tcp connection when the tcp connection is not in the idle state.
[0047] Further, the tcp connection state adjustment device further comprises:
[0048] The sending unit is configured to send a tcp connection agent request to the upper computer when the tcp connection is not in the idle state.
[0049] The third judging unit is configured to judge whether the response information fed back by the upper computer is received.
[0050] The adjusting unit is further configured to release the tcp connection socket in the server process and newly create a tcp waiting socket in the server process when the response information is not received.
[0051] Further, the third judging unit is further configured to judge whether the server process has the tcp waiting socket when the response information is received.
[0052] The adjusting unit is further configured to release the tcp waiting socket in the server process and restore the tcp connection socket in the server process when the server process has the tcp waiting socket.
[0053] Further, the communication unit is further configured to establish the tcp connection between the server and the upper computer when the server process does not have the tcp waiting socket.
[0054] The third aspect of the embodiment of the present application provides an electronic device, comprising a memory and a processor, the memory is used for storing a computer program, and the processor runs the computer program to make the electronic device execute the tcp connection state adjustment method in any one of the first aspect of the embodiment of the present application.
[0055] The fourth aspect of the embodiment of the present application provides a computer readable storage medium, which stores computer program instructions, when the computer program instructions are read and run by a processor, the tcp connection state adjustment method in any one of the first aspect of the embodiment of the present application is executed. BRIEF DESCRIPTION OF DRAWINGS
[0056] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the embodiments of the present application will be briefly introduced as follows. It should be understood that the following drawings only show some of the embodiments of the present application, and therefore should not be regarded as a limitation on the scope, and for those of ordinary skill in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.
[0057] Figure 1 A flowchart of a state adjustment method based on a TCP connection provided by the embodiment of the present application is shown in the figure.
[0058] Figure 2 A flowchart of another state adjustment method based on a TCP connection provided by the embodiment of the present application is shown in the figure.
[0059] Figure 3 A structural diagram of a state adjustment device based on a TCP connection provided by the embodiment of the present application is shown in the figure.
[0060] Figure 4 An example diagram of a server process provided by the embodiment of the present application is shown in the figure.
[0061] Figure 5 An example diagram of a proxy process provided by the embodiment of the present application is shown in the figure. DETAILED DESCRIPTION
[0062] The technical solutions in the embodiments of the present application will be described in detail below with reference to the drawings in the embodiments of the present application.
[0063] It should be noted that: similar reference numerals and letters represent similar items in the following drawings, and therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. Meanwhile, in the description of the present application, the terms "first", "second", etc. are only used for distinguishing description, and cannot be understood as indicating or implying relative importance.
[0064] Embodiment 1
[0065] Please refer to Figure 1 , Figure 1 A flowchart of a state adjustment method based on a TCP connection provided by the embodiment is shown in the figure. The state adjustment method based on a TCP connection includes:
[0066] S101, when receiving a TCP connection establishment request sent by a client, establishing a TCP connection between the client and a server.
[0067] S102, judging whether a TCP connection subsequent request sent by the client based on the TCP connection is received, if yes, executing step S106; if no, executing step S103.
[0068] S103: Determine whether the TCP connection is in an idle state. If so, execute step S102; if not, execute steps S104 to S105.
[0069] S104: Set the TCP connection to an idle state.
[0070] S105: Release the TCP connection socket in the server process, create a new TCP waiting socket in the server process, and execute step S102.
[0071] S106. Determine whether the TCP connection is in an idle state. If so, execute steps S107 to S109; if not, execute step S109.
[0072] S107: Set the TCP connection to a connected state.
[0073] S108: Release the TCP waiting socket in the server process, and restore the TCP connection socket in the server process.
[0074] S109: Perform corresponding operations based on subsequent requests of the TCP connection.
[0075] In this embodiment, the method provides a method for reducing the memory usage of TCP long connections in the server process by creating a new timewait socket (socket in timewait state) to reduce the memory usage of TCP long connections in the server process and maintain the connection state to improve the TCP connection concurrency capability of the server process.
[0076] For example, the method provided by this method to reduce the memory usage of TCP long connection includes: Figure 3 The 3 steps shown are:
[0077] (1) Release the TCP socket;
[0078] (2) Create a new socket (timewait state);
[0079] (3) When the client request arrives, the TCP socket is restored and the TimeWaitSocket is released.
[0080] Specifically, the client can send a request to the server process to establish a TCP connection, which remains idle when the client has no new requests to send. Then, the TCP socket of the server process is released and a timewait socket is created. Finally, when the client sends a new request to the server process, the TCP socket is restored and the timewait socket is released.
[0081] It can be seen that this method can achieve the effect of reducing memory usage while maintaining the TCP connection state through the operations of the above steps, thereby achieving the effect of improving TCP connection concurrency.
[0082] In this embodiment, the execution subject of the method may be a computing device such as a computer or a server, and this is not limited in this embodiment.
[0083] In this embodiment, the execution subject of the method may also be a smart device such as a smart phone, a tablet computer, etc., which is not limited in this embodiment.
[0084] It can be seen that the implementation of the state adjustment method based on the TCP connection described in this embodiment can reduce the memory usage of the socket when the TCP connection is idle. Specifically, the method can propose a method in which, when the TCP is in the idle state, a new timewait socket (a socket in the timewait state) is created and the TCP socket (a socket in the TCP state) is released. Because the timewait socket occupies much less memory than the TCP socket, the memory usage of the socket can be reduced when the TCP connection is in the idle state, thereby achieving the effect of improving the concurrency of the TCP connection, thereby improving the concurrency of the TCP connection. At the same time, it is also possible to create a new TCP socket (TCP socket) when data arrives on the connection, and release the timewait socket (a socket in the timewait state) to process the data. It can be seen that the method can solve the problem of memory bottlenecks affecting the concurrency of TCP connections through optimization processing.
[0085] Example 2
[0086] Please see Figure 2 , Figure 2 A flow chart of a method for adjusting the state of a TCP connection is provided for this embodiment. The method for adjusting the state of a TCP connection includes:
[0087] S201, when receiving the tcp connection establishment request sent by the client, establishing the tcp connection between the client and the server.
[0088] S202, judging whether the tcp connection is in idle state, if yes, ending the flow; if no, executing steps S203-S204.
[0089] S203, sending the tcp connection agent request to the upper computer.
[0090] S204, judging whether the response information fed back by the upper computer is received, if yes, executing step S206; if no, executing step S205.
[0091] S205, releasing the tcp connection socket in the server process, newly building the tcp waiting socket in the server process, and executing step S204.
[0092] S206, judging whether the tcp waiting socket in the server process is possessed, if yes, executing steps S207-S208; if no, executing step S208.
[0093] S207, releasing the tcp waiting socket in the server process, and restoring the tcp connection socket in the server process.
[0094] S208, establishing the tcp connection between the server and the upper computer.
[0095] In the embodiment, the method provided is a method for reducing the memory occupation of the tcp long connection of the agent process. The method can reduce the memory occupation of the tcp long connection of the agent process by newly building the timewait socket (the socket in the timewait state), and keep the connection state, thereby improving the tcp connection concurrency capability of the agent process.
[0096] For example, the method provided for reducing the memory occupation of the tcp long connection includes the following 3 steps as shown in the figure: Figure 5
[0097] (1) releasing the tcp socket (tcp socket);
[0098] (2) newly building the timewait socket (the socket in the timewait state);
[0099] (3) when the server response arrives, restoring the tcp socket (tcp socket), and releasing the timewait socket (the socket in the timewait state).
[0100] Specifically, the client sends a request to the proxy process and establishes a TCP connection with the proxy process; then, after receiving the client's request, the proxy process initiates a request to the upstream server to establish a TCP connection. When the server responds slowly or times out, the proxy process creates a new timewait socket (socket in timewait state), maintains the connection with the server, and releases the TCP socket (TCP socket); finally, when the server response arrives, the proxy process restores the TCP socket (creates a new TCP socket) to process the server's response content and closes the timewait socket (socket in timewait state).
[0101] It can be seen that this method can achieve the effect of reducing the memory usage of TCP connections in the proxy process while maintaining the TCP connection state through the operations in the above steps, thereby achieving the effect of improving TCP connection concurrency.
[0102] In this embodiment, the execution subject of the method may be a computing device such as a computer or a server, and this is not limited in this embodiment.
[0103] In this embodiment, the execution subject of the method may also be a smart device such as a smart phone, a tablet computer, etc., which is not limited in this embodiment.
[0104] It can be seen that the implementation of the state adjustment method based on the TCP connection described in this embodiment can reduce the memory usage of the socket when the TCP connection is idle. Specifically, the method can propose a method in which, when the TCP is in the idle state, a new timewait socket (a socket in the timewait state) is created and the TCP socket (a socket in the TCP state) is released. Because the timewait socket occupies much less memory than the TCP socket, the memory usage of the socket can be reduced when the TCP connection is in the idle state, thereby achieving the effect of improving the concurrency of the TCP connection, thereby improving the concurrency of the TCP connection. At the same time, it is also possible to create a new TCP socket (TCP socket) when data arrives on the connection, and release the timewait socket (a socket in the timewait state) to process the data. It can be seen that the method can solve the problem of memory bottlenecks affecting the concurrency of TCP connections through optimization processing.
[0105] Example 3
[0106] Please see Figure 3 , Figure 3 This is a schematic diagram of the structure of a state adjustment device based on TCP connection provided in this embodiment. Figure 3As shown, the state adjustment device based on TCP connection includes:
[0107] The establishing unit 310 is configured to establish a TCP connection between the client and the server upon receiving a TCP connection establishment request sent by the client;
[0108] The first determining unit 320 is configured to determine whether a subsequent TCP connection request sent by the client based on the TCP connection is received;
[0109] The second determining unit 330 is configured to determine whether the TCP connection is in an idle state when no subsequent TCP connection request sent by the client based on the TCP connection is received;
[0110] The setting unit 340 is configured to set the TCP connection to an idle state when the TCP connection is not in an idle state;
[0111] The adjustment unit 350 is used to release the TCP connection socket in the server process and create a new TCP waiting socket in the server process.
[0112] As an optional implementation manner, the first determining unit 320 is specifically configured to determine whether a subsequent TCP connection request sent by the client based on the TCP connection is received when the TCP connection is in an idle state.
[0113] As an optional implementation manner, the second determining unit 330 is further configured to determine whether the TCP connection is in an idle state when receiving a TCP connection subsequent request sent by the client based on the TCP connection;
[0114] The setting unit 340 is further configured to set the TCP connection to a connected state when the TCP connection is in an idle state;
[0115] The regulating unit 350 is further configured to release the TCP waiting socket in the server process and restore the TCP connection socket in the server process.
[0116] As an optional implementation manner, the state adjustment device based on TCP connection further includes:
[0117] The communication unit 360 is configured to perform corresponding operations based on subsequent requests of the TCP connection when the TCP connection is not in an idle state.
[0118] As an optional implementation manner, the state adjustment device based on TCP connection further includes:
[0119] The sending unit 370 is used to send a TCP connection proxy request to the host computer when the TCP connection is not in an idle state;
[0120] The third judgment unit 380 is used to judge whether the response information fed back by the host computer is received;
[0121] The adjustment unit 350 is further configured to release the TCP connection socket in the server process and create a new TCP waiting socket in the server process when no response information is received.
[0122] As an optional implementation manner, the third determination unit 380 is further configured to determine whether there is a TCP waiting socket in the server process when receiving the response information;
[0123] The regulating unit 350 is further configured to release the TCP waiting socket in the server process when there is a TCP waiting socket in the server process, and to restore the TCP connection socket in the server process.
[0124] As an optional implementation, the communication unit 360 is further configured to establish a TCP connection between the server and the host computer when the server process does not have a TCP waiting socket.
[0125] In this embodiment, the explanation of the state adjustment device based on TCP connection can refer to the description in embodiment 1 or embodiment 2, and will not be repeated in this embodiment.
[0126] It can be seen that the implementation of the state adjustment device based on the TCP connection described in this embodiment can reduce the memory usage of the socket when the TCP connection is idle. Specifically, the method can propose a method in which, when the TCP is in the idle state, a new timewait socket (a socket in the timewait state) is created and the TCP socket (a socket in the TCP state) is released. Because the memory usage of the timewait socket is much less than that of the TCP socket, the memory usage of the socket can be reduced when the TCP connection is in the idle state, thereby achieving the effect of improving the concurrency of the TCP connection, thereby improving the concurrency of the TCP connection. At the same time, it is also possible to create a new TCP socket (a TCP socket) when data arrives on the connection, and release the timewait socket (a socket in the timewait state) to realize data processing. It can be seen that the method can solve the problem of memory bottleneck affecting the concurrency of TCP connections through optimization processing.
[0127] An embodiment of the present application provides an electronic device, including a memory and a processor, wherein the memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute the state adjustment method based on TCP connection in embodiment 1 or embodiment 2 of the present application.
[0128] The embodiment of the present application provides a computer readable storage medium, which stores computer program instructions, and when the computer program instructions are read and run by a processor, the state adjustment method based on a tcp connection in the embodiment 1 or the embodiment 2 of the present application is executed.
[0129] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can also be implemented by other manners. The apparatus embodiment described above is only schematic, for example, the flow chart and block diagram in the drawings show the possible implementation architecture, function and operation of the apparatus, method and computer program product according to the embodiments of the present application. In this regard, each block in the flow chart or block diagram can represent a module, a program segment or a part of code, which contains one or more executable instructions for implementing the specified logic function. It should also be noted that, in some alternative implementation manners, the functions noted in the blocks can also occur in different order from that noted in the drawings. For example, two consecutive blocks can actually be executed substantially in parallel, and sometimes they can also be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flow chart, and the combination of blocks in the block diagram and / or flow chart, can be implemented by a dedicated hardware-based system for implementing the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0130] In addition, the function modules in the embodiments of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0131] When the functions are realized in the form of software function modules and sold or used as independent products, the functions can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product, and the computer software product is stored in a storage medium, and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.
[0132] The foregoing is merely an embodiment of the present application and is not intended to limit the scope of protection of the present application. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included within the scope of protection of the present application. It should be noted that similar reference numerals and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined or explained in subsequent figures.
[0133] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.
[0134] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.
Claims
1. A state adjustment method based on TCP connection, characterized in that: include: When receiving a TCP connection establishment request sent by the client, establishing a TCP connection between the client and the server; Determining whether a subsequent TCP connection request sent by the client based on the TCP connection is received; When no subsequent request for the TCP connection sent by the client based on the TCP connection is received, determining whether the TCP connection is in an idle state; When the TCP connection is not in the idle state, setting the TCP connection to the idle state; Release the TCP connection socket in the server process and create a new TCP waiting socket in the server process; The method further comprises: When the TCP connection is in the idle state, the step of determining whether a subsequent TCP connection request sent by the client based on the TCP connection is received is triggered.
2. The method for adjusting the state of a TCP connection according to claim 1, wherein: The method further comprises: When receiving the TCP connection subsequent request sent by the client based on the TCP connection, determining whether the TCP connection is in an idle state; When the TCP connection is in the idle state, setting the TCP connection to a connected state; Releases a tcp wait socket in a server process and resumes a tcp connection socket in the server process.
3. The method for adjusting the state of a TCP connection according to claim 2, wherein: The method further comprises: When the TCP connection is not in the idle state, a corresponding operation is performed based on a subsequent request of the TCP connection.
4. The method for adjusting the state of a TCP connection according to claim 1, wherein: The method further comprises: When the TCP connection is not in an idle state, sending a TCP connection proxy request to the host computer; Determine whether the response information fed back by the host computer is received; When the response information is not received, the TCP connection socket in the server process is released, and a new TCP waiting socket is created in the server process.
5. The method for adjusting the state of a TCP connection according to claim 4, wherein: The method further comprises: When the response information is received, determining whether there is a TCP waiting socket in the server process; When the server process has the tcp waiting socket, the tcp waiting socket in the server process is released, and the tcp connection socket is restored in the server process.
6. The method for adjusting the state based on TCP connection according to claim 5, characterized in that: The method further comprises: When the server process does not have the TCP waiting socket, a TCP connection is established between the server and the host computer.
7. A state adjustment device based on TCP connection, characterized in that: The state adjustment device based on TCP connection includes: An establishing unit, configured to establish a TCP connection between the client and the server upon receiving a TCP connection establishment request sent by the client; A first determining unit is configured to determine whether a subsequent TCP connection request sent by the client based on the TCP connection is received; A second judging unit is configured to judge whether the TCP connection is in an idle state when no subsequent TCP connection request sent by the client based on the TCP connection is received; A setting unit, configured to set the TCP connection to the idle state when the TCP connection is not in the idle state; The regulating unit is used to release the TCP connection socket in the server process and create a new TCP waiting socket in the server process; The first judgment unit is specifically configured to judge whether a subsequent TCP connection request sent by the client based on the TCP connection is received when the TCP connection is in an idle state.
8. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to perform the state adjustment method based on TCP connection according to any one of claims 1 to 6.
9. A readable storage medium, characterized in that The readable storage medium stores computer program instructions, and when the computer program instructions are read and executed by a processor, the state adjustment method based on TCP connection according to any one of claims 1 to 6 is executed.
Citation Information
Patent Citations
Router configuration method and device and storage medium
CN109951308A