DHCP (Dynamic Host Configuration Protocol) client lease renewing method, system and terminal

By stopping the process in the DHCP client and managing the renewal process using the renewal timer, the resource consumption and connection stability issues are solved, and efficient renewal management and fault tolerance are achieved.

CN119094500APending Publication Date: 2024-12-06深圳开鸿数字产业发展有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411057137.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-02
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

The traditional DHCP client remains active while waiting for renewal time, resulting in unnecessary CPU and memory resource consumption, making it difficult to deal with changes in connection status, which may lead to failure to renewal and affect network connection stability.

Method used

After the DHCP client successfully applies for IP, stop the process, create a renewal timer, calculate the renewal waiting time based on the lease period, and check the connection status when the waiting state ends to decide whether to renew the lease, reduce resource waste and improve fault tolerance.

Benefits of technology

Manage the renewal process through timers to reduce resource consumption, improve network connection stability and renewal success rate, and enhance fault tolerance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119094500A_ABST
    Figure CN119094500A_ABST
Patent Text Reader

Abstract

The invention discloses a DHCP (Dynamic Host Configuration Protocol) client lease renewal method, system and terminal, the DHCP client lease renewal method comprises the following steps: after a DHCP client successfully applies for an IP (Internet Protocol), stopping the process of the DHCP client, and receiving a lease term returned by a DHCP server; creating a DHCP (Dynamic Host Configuration Protocol) lease renewal timer, and calculating lease renewal waiting time according to the Transmitting the lease renewal waiting time to the DHCP lease renewal timer, and enabling the DHCP lease renewal timer to enter a waiting state according to the lease renewal waiting time; and after the waiting state is ended, checking the connection state of the current STA, and starting the DHCP client according to the connection state to carry out lease renewal. According to the method and the device, the lease renewal time is determined by setting the timer, and the lease renewal thread is created at the preset time point for lease renewal, so that resource waste caused by long-time operation of the DHCP client is reduced, and the lease renewal process can be managed more efficiently.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of network communication technology, and in particular to a DHCP client lease renewal method, system, terminal and computer-readable storage medium. Background Art

[0002] In computer networks, DHCP (Dynamic Host Configuration Protocol) is an automated network protocol used to assign IP addresses and other network configuration parameters to computing devices. The core function of DHCP is to dynamically allocate and manage IP address leases for network devices to ensure that network devices can continue to connect to the network effectively. During the lease period, the DHCP client needs to periodically send renewal requests to the DHCP server to extend the lease time of the IP address.

[0003] However, the traditional DHCP client renewal method still has some shortcomings. For example, the DHCP client remains in operation during the entire lease period. Since the DHCP client remains active while waiting for the renewal time to arrive, it causes unnecessary CPU and memory resource consumption. In addition, it is difficult to effectively respond to changes in the client connection status. If the DHCP client loses network connection during the renewal period, it may cause renewal failure, thereby affecting the stability of the network connection.

[0004] Therefore, the prior art still needs to be improved and developed. Summary of the invention

[0005] The main purpose of the present invention is to provide a DHCP client renewal method, system, terminal and computer-readable storage medium, aiming to solve the technical problem in the prior art that the DHCP client remains active while waiting for the renewal time to arrive, resulting in unnecessary CPU and memory resource consumption, making it difficult to effectively respond to changes in the client connection state. If the DHCP client loses the network connection during the renewal period, the renewal may fail, thereby affecting the stability of the network connection.

[0006] To achieve the above object, the present invention provides a DHCP client lease renewal method, the DHCP client lease renewal method comprising the following steps:

[0007] After the DHCP client successfully applies for an IP, the process of the DHCP client is stopped, and the lease returned by the DHCP server is received;

[0008] Create a DHCP renewal timer and calculate the renewal waiting time according to the lease period;

[0009] Passing the renewal waiting time to the DHCP renewal timer, and making the DHCP renewal timer enter a waiting state according to the renewal waiting time;

[0010] When the waiting state ends, the connection state of the current STA is checked, and the DHCP client is started to renew the lease according to the connection state.

[0011] Optionally, the DHCP client lease renewal method, wherein after the DHCP client successfully applies for an IP address, stopping the process of the DHCP client and receiving the lease period returned by the DHCP server, specifically includes:

[0012] After the DHCP client receives the IP address allocation response from the DHCP server, stopping the process of the DHCP client and releasing related resources;

[0013] Receive a DHCP ACK message returned by the DHCP server, parse the DHCP ACK message, and extract the lease period.

[0014] Optionally, the DHCP client renewal method, wherein the step of creating a DHCP renewal timer and calculating the renewal waiting time according to the lease period, specifically includes:

[0015] Create a DHCP renewal timer and initialize parameters of the DHCP renewal timer;

[0016] The renewal waiting time is calculated according to the lease period based on a preset algorithm.

[0017] Optionally, the DHCP client renewal method, wherein the passing of the renewal waiting time to the DHCP renewal timer, and causing the DHCP renewal timer to enter a waiting state according to the renewal waiting time, specifically includes:

[0018] The renewal waiting time is passed as a parameter to the DHCP renewal timer, the DHCP renewal timer is started and enters a waiting state according to the waiting time, and the current waiting time is recorded.

[0019] Optionally, the DHCP client lease renewal method, wherein after the waiting state ends, checking the connection state of the current STA, and starting the DHCP client to renew the lease according to the connection state, further includes:

[0020] Write the creation function in STA;

[0021] When the current waiting time reaches the renewal waiting time, creating a DHCP renewal thread according to the creation function;

[0022] Initialize parameters of the DHCP lease renewal thread and set the priority of the DHCP lease renewal thread.

[0023] Optionally, the DHCP client lease renewal method, wherein the checking of the connection status of the current STA and starting the DHCP client to renew the lease according to the connection status, specifically includes:

[0024] In the DHCP lease renewal thread, the local network interface is called to check the connection status of the current STA;

[0025] If it is detected that the STA is in a disconnected hotspot state, recalculate the renewal waiting time and continue to enter the waiting state or directly terminate the DHCP renewal thread;

[0026] If it is detected that the STA is in a hotspot connection state, when the current waiting time reaches the renewal waiting time, the DHCP renewal timer is stopped, the DHCP client is started, and a DHCP renewal request is sent to the DHCP server for renewal according to the DHCP renewal thread. After the renewal is successful, the lease information is updated and the DHCP renewal timer is initialized.

[0027] Optionally, the DHCP client lease renewal method, wherein the step of starting the DHCP client to renew the lease according to the connection state, further comprises:

[0028] If the STA reconnects to a different hotspot, the DHCP client process is immediately started and a renewal request is initiated;

[0029] If the renewal fails, record the error message generated and try to renew the lease.

[0030] In addition, to achieve the above object, the present invention further provides a DHCP client lease renewal system, wherein the DHCP client lease renewal system comprises:

[0031] The receiving module is used to stop the process of the DHCP client after the DHCP client successfully applies for an IP address, and receive the renewal time returned by the DHCP server;

[0032] A creation module is used to create a DHCP renewal timer and calculate a renewal waiting time according to the renewal time;

[0033] A waiting module, used for transferring the renewal waiting time to the DHCP renewal timer, and making the DHCP renewal timer enter a waiting state according to the renewal waiting time;

[0034] The renewal module is used to check the connection status of the current STA after the waiting state ends, and start the DHCP client to renew the lease according to the connection status.

[0035] In addition, to achieve the above-mentioned purpose, the present invention also provides a terminal, wherein the terminal includes: a memory, a processor, and a DHCP client lease renewal program stored in the memory and executable on the processor, wherein the DHCP client lease renewal program implements the steps of the DHCP client lease renewal method described above when executed by the processor.

[0036] In addition, to achieve the above purpose, the present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a DHCP client lease renewal program, and when the DHCP client lease renewal program is executed by a processor, the steps of a DHCP client lease renewal method as described above are implemented.

[0037] In the present invention, after the DHCP client successfully applies for an IP, the process of the DHCP client is stopped, and the lease returned by the DHCP server is received; a DHCP renewal timer is created, and the renewal waiting time is calculated according to the lease; the renewal waiting time is passed to the DHCP renewal timer, and the DHCP renewal timer enters a waiting state according to the renewal waiting time; when the waiting state ends, the connection state of the current STA is checked, and the DHCP client is started to renew the lease according to the connection state. The present invention reduces the waste of resources caused by the long-term operation of the DHCP client by setting a timer to determine the renewal time, and creates a renewal thread at a preset time point for renewal, which can more efficiently manage the renewal process, and can automatically adjust the renewal strategy when the renewal fails or the connection state changes, thereby improving fault tolerance and recovery capabilities. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 It is a flow chart of a preferred embodiment of a DHCP client lease renewal method of the present invention;

[0039] Figure 2 It is a schematic diagram of the principle of a preferred embodiment of a DHCP client lease renewal system of the present invention;

[0040] Figure 3 Schematic diagram of the operating environment of a preferred embodiment of the terminal of the present invention. DETAILED DESCRIPTION

[0041] In order to make the purpose, technical solution and advantages of the present invention clearer and more specific, the present invention is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0042] A DHCP client lease renewal method according to a preferred embodiment of the present invention is as follows: Figure 1 As shown, the DHCP client lease renewal method includes the following steps:

[0043] Step S10: After the DHCP client successfully applies for an IP address, the process of the DHCP client is stopped, and a lease returned by the DHCP server is received.

[0044] Specifically, in the DHCP client, the application and renewal process of the IP address is a continuous operation, which will cause the continuous occupation of system resources and affect the performance of other applications. By stopping the DHCP client process after successfully applying for the IP address and restarting the process before the lease expires, the purpose of saving resources can be achieved.

[0045] Further, after the DHCP client successfully applies for an IP address, the process of the DHCP client is stopped, and a lease returned by the DHCP server is received, which specifically includes:

[0046] After the DHCP client receives the IP address allocation response from the DHCP server, the process of the DHCP client is stopped and related resources are released.

[0047] Receive a DHCP ACK message returned by the DHCP server, parse the DHCP ACK message, and extract the lease period.

[0048] After the DHCP client successfully applies for an IP address, it first stops the process of the DHCP client and receives the lease returned by the DHCP server. Specifically, after the DHCP client is started, it sends a DHCP DISCOVER message to the DHCP server to request an IP address. The message contains the client's hardware address and other necessary configuration information. After receiving the request, the server returns a DHCPOFFER message, which contains information such as the allocated IP address, subnet mask, gateway address, and renewal time to provide an IP address. After receiving the DHCPOFFER message, the client sends a DHCPREQUEST message to confirm that it accepts the IP address. The message can also include other parameter requests from the client, such as the DNS server address. After receiving the DHCPREQUEST message, the DHCP server confirms and locks the IP address, and then sends a DHCP ACK message to the client, which confirms that the IP address is successfully allocated and provides detailed information about the lease. After receiving the DHCP ACK message, the client parses the message to extract the lease, and immediately stops its own process to release system resources to ensure efficient use of system resources.

[0049] In a specific embodiment, in a home network environment, when a user's smart device (such as a smart TV) is started, the DHCP client program will automatically run to request an IP address from the router (DHCP server). After receiving the request, the router returns an IP address (e.g., 192.168.1.100) and a renewal time (e.g., 3600 seconds). After receiving the DHCP ACK message, the smart device parses the lease period and stops the DHCP client process, so that the device can keep the allocated IP address for use within the next 1 hour.

[0050] Step S20: Create a DHCP renewal timer, and calculate the renewal waiting time according to the lease period.

[0051] Specifically, after stopping the DHCP client process, the system needs to create a DHCP renewal timer for regularly triggering the renewal operation, and calculate the renewal waiting time based on the last lease period to determine the time point for creating a new thread to process the renewal task.

[0052] Further, the creating of the DHCP renewal timer and calculating the renewal waiting time according to the lease period specifically includes:

[0053] A DHCP renewal timer is created and parameters of the DHCP renewal timer are initialized.

[0054] The renewal waiting time is calculated according to the lease period based on a preset algorithm.

[0055] Specifically, a DHCP renewal timer is created, and after receiving the renewal time returned by the DHCP server, the renewal waiting time is calculated by a preset algorithm. The preset algorithm can be calculated based on half of the renewal time. For example, if the renewal time is T, the renewal waiting time is T / 2. If the lease period is 600 seconds, the renewal waiting time is 300 seconds. The purpose of calculating the renewal waiting time based on the lease period is to initiate a renewal request when the lease period is halfway through, leaving enough time to handle possible renewal failures and other issues.

[0056] Step S30: passing the lease renewal waiting time to the DHCP lease renewal timer, and making the DHCP lease renewal timer enter a waiting state according to the lease renewal waiting time.

[0057] Specifically, in the traditional method, the DHCP client needs to run continuously to monitor the expiration time of the lease, resulting in a waste of system resources. When the lease is about to expire, if the DHCP client fails to renew the lease in time, it may cause network connection interruption and affect user experience. Therefore, in the DHCP renewal thread, the renewal waiting time is calculated according to the preset algorithm to ensure that the renewal operation is completed before the lease expires. By introducing the on-demand DHCP renewal thread, the DHCP client is automatically activated when renewal is required, reducing system resource usage and improving network stability and user experience.

[0058] Further, the transferring the renewal waiting time to the DHCP renewal timer, and making the DHCP renewal timer enter a waiting state according to the renewal waiting time, specifically includes:

[0059] The renewal waiting time is passed as a parameter to the DHCP renewal timer, the DHCP renewal timer is started and enters a waiting state according to the waiting time, and the current waiting time is recorded.

[0060] Specifically, the renewal waiting time is passed as a parameter to the DHCP renewal timer, and the waiting state is entered according to the calculated renewal waiting time. The setting of the DHCP renewal timer can be implemented through a standard timer library in a programming language, for example, using the sleep function in C language or the time.sleep function in Python. After the timer is set, it enters the waiting state and records the current waiting time. During the waiting state, the running status of the DHCP client can be checked regularly by checking the timer to ensure that it can be properly awakened after the specified waiting time is reached. By cyclically checking the status of the DHCP client, a DHCP renewal thread can be created when the waiting time is reached to perform a renewal operation. This step realizes an automated renewal waiting process, reduces the complexity of manual operations, improves the simplicity and efficiency of operations, and at the same time, through reasonable waiting time calculation, further enhances the stability of the network connection and user experience.

[0061] Step S40: After the waiting state ends, check the connection state of the current STA, and start the DHCP client to renew the lease according to the connection state.

[0062] Specifically, when the current waiting time recorded by the timer reaches the preset renewal waiting time, a callback function will be triggered to execute the subsequent steps of the renewal operation. In the callback function, the connection status of the current STA (Station, i.e., network device) needs to be checked first to determine whether renewal is required. STA can be the state of a wireless device (such as a smart phone, laptop, etc.) connected to a wireless network. The connection status information of the current STA is obtained by calling a local network interface function or using a system API. Specifically, the connection status of the STA can be determined by checking whether it is still connected to the original hotspot (AP, Access Point), and the corresponding renewal operation is taken according to the checked STA connection status.

[0063] Further, after the waiting state ends, the connection state of the current STA is checked, and the DHCP client is started to renew the lease according to the connection state, which also includes:

[0064] Write the creation function in STA;

[0065] When the current waiting time reaches the renewal waiting time, creating a DHCP renewal thread according to the creation function;

[0066] Initialize parameters of the DHCP lease renewal thread and set the priority of the DHCP lease renewal thread.

[0067] Specifically, in the software architecture of STA(, a function for creating a DHCP renewal thread is written. The purpose of this function is to create and initialize a new DHCP renewal thread according to the parameters passed in. Inside the creation function, the system thread library is used to create a new thread. When creating, the parameters of the thread need to be initialized, including the renewal time and other necessary operating parameters. Furthermore, the message of the last successful IP request of the DHCP client can also be persisted and saved, and sent directly to the DHCP server for renewal when the next renewal request is made. After the thread is created, the priority of the DHCP renewal thread needs to be set to ensure that the renewal operation can be executed in time, and then the DHCP renewal thread is started to enter the running state. After the renewal waiting time is reached, the DHCP renewal thread is activated by the timer and the renewal task is executed.

[0068] In a specific embodiment, in the STA code, a function for creating a DHCP renewal thread is written, named createDHCPRenewThread. This function is responsible for creating and initializing the renewal thread. Inside the createDHCPRenewThread function, a structure or variable is defined to store thread parameters, and a new thread is created using the thread library function provided by the system (such as pthread_create or CreateThread). At the same time, the priority of the renewal thread is set using the system function to ensure that the renewal operation can be executed in time. Finally, the thread is started at the agreed time point, so that it enters the running state and executes the task. By setting the priority of the renewal thread, it can be ensured that the renewal operation can be executed in time, avoiding the problem of network connection interruption caused by renewal delay.

[0069] Further, the checking of the connection status of the current STA and starting the DHCP client to renew the lease according to the connection status specifically includes:

[0070] In the DHCP lease renewal thread, the local network interface is called to check the connection status of the current STA;

[0071] If it is detected that the STA is in a disconnected hotspot state, recalculate the renewal waiting time and continue to enter the waiting state or directly terminate the DHCP renewal thread;

[0072] If it is detected that the STA is in a hotspot connection state, when the current waiting time reaches the renewal waiting time, the DHCP renewal timer is stopped, the DHCP client is started, and a DHCP renewal request is sent to the DHCP server for renewal according to the DHCP renewal thread. After the renewal is successful, the lease information is updated and the DHCP renewal timer is initialized.

[0073] Specifically, the DHCP renewal thread calls the local network interface (for example, the network management interface or network library provided by the operating system) to obtain the current STA's connection status. These interfaces can provide information about whether the device is connected to the network and the stability of the connection. Based on the inspection results, the renewal thread decides whether to start the DHCP client for renewal. If the device's current connection status is normal, the thread will continue to execute the renewal request; if the connection status is abnormal, the thread may recalculate the renewal waiting time, or terminate the renewal operation and wait for the device to reconnect before renewing.

[0074] During the DHCP client renewal process, the STA's connection status will directly affect the execution of the renewal request. If the STA is currently disconnected from the network, the renewal request will not be successfully sent or received. Therefore, before deciding whether to renew the lease, you first need to confirm the STA's connection status. First, a mechanism is needed to dynamically handle the STA's connection status and decide whether to continue the renewal operation. This mechanism helps optimize the renewal process, improve the success rate of renewal, and reduce invalid renewal requests. In the renewal thread, detecting the STA's current connection status is a key step.

[0075] The DHCP renewal thread will call the local network interface or status check function to obtain the connection status of the STA, and usually return a flag indicating the connection status, such as "connected" or "disconnected". If the STA is in a disconnected state, the renewal operation cannot be successfully performed. In this case, the renewal thread will recalculate a new renewal waiting time. It can estimate a reasonable waiting time based on the current network status and the preset algorithm, and make the DHCP renewal thread continue to enter the waiting state until the STA reconnects to the network. After reconnecting, the thread will check the connection status again and decide whether to continue the renewal operation. If the STA's disconnected state lasts for a long time or exceeds the preset number of retries, you can also choose to directly end the DHCP renewal thread and no longer try to renew the lease to avoid invalid renewal requests and waste of resources.

[0076] If the STA is in a connected state, the renewal request can be sent normally. At this time, when the current waiting time reaches the renewal waiting time, that is, the connection time exceeds the DHCP renewal timer, the DHCP renewal timer is stopped, and the DHCP client program is started through the DHCP renewal thread. If the DHCP client is not running yet, it will be initialized and ready to send a renewal request, requesting the DHCP server to renew the current IP address. If the renewal request is successful, the DHCP server will respond to the renewal request, update the lease information and synchronize it to the DHCP client, and reinitialize the DHCP renewal timer to prepare for the next round of renewal to ensure that the device can continue to use the same IP address. Through the above steps, the DHCP client renewal method can flexibly adjust the renewal strategy when facing changes in the device network status, thereby improving the stability of the system and the renewal success rate, and can take into account the optimization of automatic renewal and resource scheduling.

[0077] Further, the step of starting the DHCP client to renew the lease according to the connection state further includes:

[0078] If the STA reconnects to a different hotspot, the DHCP client process is immediately started and a renewal request is initiated.

[0079] If the renewal fails, record the error message generated and try to renew the lease.

[0080] Specifically, in a wireless network environment, a STA may switch from one hotspot to another. In this case, the STA may need to reapply for an IP address to ensure the continuity of the network connection. At the same time, during the renewal process, a renewal failure may occur, and an effective error handling mechanism is required to ensure the stability of the network connection.

[0081] When a STA switches from one hotspot to another, the original IP address may no longer be valid. To ensure the continuity of the network connection, the DHCP renewal thread will detect whether the STA is reconnected to a different hotspot. For example, this can be achieved by checking the connection status of the STA and the hotspot information of the current connection. If it is detected that the STA is connected to a different hotspot, the renewal thread will immediately start the DHCP client process, which includes initializing the DHCP client and preparing to send a new renewal request. The started DHCP client will send a renewal request to the DHCP server of the new hotspot and obtain a new IP address through the DHCP protocol operation to ensure the network connection of the STA on the new hotspot.

[0082] During the renewal process, the renewal may fail due to various reasons. In order to ensure the stability of the network connection, it is necessary to record the error information of the renewal failure and try to renew the lease. When the renewal fails, the DHCP renewal thread will record the generated error information, which may include the error code, error message and the specific reason for the renewal failure, which can be used for subsequent troubleshooting and system debugging. After recording the error information, the DHCP renewal thread will try to renew the lease. The specific strategy for renewing the lease can be configured according to system requirements, such as immediately re-initiating the renewal request or waiting for a period of time before trying to renew the lease. The goal of renewing the lease is to restore the STA's network connection as soon as possible to ensure normal use by users.

[0083] Furthermore, if Figure 2 As shown, based on the above DHCP client renewal method, the present invention also provides a DHCP client renewal system, wherein the DHCP client renewal system includes:

[0084] The receiving module 51 is used to stop the process of the DHCP client after the DHCP client successfully applies for an IP address, and receive the renewal time returned by the DHCP server;

[0085] A creation module 52, used to create a DHCP renewal timer, and calculate a renewal waiting time according to the renewal time;

[0086] A waiting module 53, configured to transfer the renewal waiting time to the DHCP renewal timer, and enable the DHCP renewal timer to enter a waiting state according to the renewal waiting time;

[0087] The renewal module 54 is used to check the connection status of the current STA after the waiting state ends, and start the DHCP client to renew the lease according to the connection status.

[0088] Furthermore, if Figure 3 As shown, based on the above DHCP client lease renewal method and system, the present invention also provides a terminal accordingly, and the terminal includes a processor 10, a memory 20 and a display 30. Figure 3 Only some components of the terminal are shown, but it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.

[0089] In some embodiments, the memory 20 may be an internal storage unit of the terminal, such as a hard disk or memory of the terminal. In other embodiments, the memory 20 may also be an external storage device of the terminal, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc. equipped on the terminal. Further, the memory 20 may also include both an internal storage unit of the terminal and an external storage device. The memory 20 is used to store application software and various types of data installed in the terminal, such as the program code of the installation terminal. The memory 20 may also be used to temporarily store data that has been output or is to be output. In one embodiment, a DHCP client renewal program 40 is stored on the memory 20, and the DHCP client renewal program 40 can be executed by the processor 10, thereby realizing a DHCP client renewal method in the present application.

[0090] In some embodiments, the processor 10 may be a central processing unit (CPU), a microprocessor or other data processing chip, and is used to run the program code or process data stored in the memory 20, such as executing the DHCP client renewal method.

[0091] In some embodiments, the display 30 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, etc. The display 30 is used to display information on the terminal and to display a visual user interface. The components 10-30 of the terminal communicate with each other via a system bus.

[0092] In one embodiment, when the processor 10 executes the DHCP client lease renewal program 40 in the memory 20, the following steps are implemented:

[0093] After the DHCP client successfully applies for an IP, the process of the DHCP client is stopped, and the lease returned by the DHCP server is received;

[0094] Create a DHCP renewal timer and calculate the renewal waiting time according to the lease period;

[0095] Passing the renewal waiting time to the DHCP renewal timer, and making the DHCP renewal timer enter a waiting state according to the renewal waiting time;

[0096] When the waiting state ends, the connection state of the current STA is checked, and the DHCP client is started to renew the lease according to the connection state.

[0097] After the DHCP client successfully applies for an IP address, the process of the DHCP client is stopped, and the lease returned by the DHCP server is received, which specifically includes:

[0098] After the DHCP client receives the IP address allocation response from the DHCP server, stopping the process of the DHCP client and releasing related resources;

[0099] Receive a DHCP ACK message returned by the DHCP server, parse the DHCP ACK message, and extract the lease period.

[0100] The step of creating a DHCP renewal timer and calculating the renewal waiting time according to the lease period specifically includes:

[0101] Create a DHCP renewal timer and initialize parameters of the DHCP renewal timer;

[0102] The renewal waiting time is calculated according to the lease period based on a preset algorithm.

[0103] The step of transferring the renewal waiting time to the DHCP renewal timer and causing the DHCP renewal timer to enter a waiting state according to the renewal waiting time specifically includes:

[0104] The renewal waiting time is passed as a parameter to the DHCP renewal timer, the DHCP renewal timer is started and enters a waiting state according to the waiting time, and the current waiting time is recorded.

[0105] Wherein, after the waiting state ends, the connection state of the current STA is checked, and the DHCP client is started to renew the lease according to the connection state, and the above also includes:

[0106] Write the creation function in STA;

[0107] When the current waiting time reaches the renewal waiting time, creating a DHCP renewal thread according to the creation function;

[0108] Initialize parameters of the DHCP lease renewal thread and set the priority of the DHCP lease renewal thread.

[0109] The checking of the connection status of the current STA and starting the DHCP client to renew the lease according to the connection status specifically includes:

[0110] In the DHCP lease renewal thread, the local network interface is called to check the connection status of the current STA;

[0111] If it is detected that the STA is in a disconnected hotspot state, recalculate the renewal waiting time and continue to enter the waiting state or directly terminate the DHCP renewal thread;

[0112] If it is detected that the STA is in a hotspot connection state, when the current waiting time reaches the renewal waiting time, the DHCP renewal timer is stopped, the DHCP client is started, and a DHCP renewal request is sent to the DHCP server for renewal according to the DHCP renewal thread. After the renewal is successful, the lease information is updated and the DHCP renewal timer is initialized.

[0113] The method of initiating the DHCP client to renew the lease according to the connection state further includes:

[0114] If the STA reconnects to a different hotspot, the DHCP client process is immediately started and a renewal request is initiated;

[0115] If the renewal fails, record the error message generated and try to renew the lease.

[0116] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a DHCP client lease renewal program, and when the DHCP client lease renewal program is executed by a processor, the steps of the DHCP client lease renewal method described above are implemented.

[0117] In summary, the present invention provides a DHCP client renewal method, system, terminal and computer-readable storage medium, the method comprising: after the DHCP client successfully applies for an IP, stopping the process of the DHCP client and receiving the lease returned by the DHCP server; creating a DHCP renewal timer and calculating the renewal waiting time according to the lease; passing the renewal waiting time to the DHCP renewal timer, and making the DHCP renewal timer enter a waiting state according to the renewal waiting time; after the waiting state ends, checking the connection state of the current STA, and starting the DHCP client to renew the lease according to the connection state. The present invention reduces the waste of resources caused by the long-term operation of the DHCP client by setting a timer to determine the renewal time and creating a renewal thread at a preset time point for renewal, which can more efficiently manage the renewal process, and automatically adjust the renewal strategy when the renewal fails or the connection state changes, thereby improving fault tolerance and recovery capabilities.

[0118] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or terminal including the element.

[0119] Of course, those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware (such as a processor, a controller, etc.) through a computer program, and the program can be stored in a computer-readable storage medium that can be read by a computer, and the program can include the processes of the above-mentioned method embodiments when executed. The computer-readable storage medium can be a memory, a disk, an optical disk, etc.

[0120] It should be understood that the application of the present invention is not limited to the above examples. For ordinary technicians in this field, improvements or changes can be made based on the above description. All these improvements and changes should fall within the scope of protection of the claims attached to the present invention.

Claims

1. A DHCP client lease renewal method, characterized in that: The DHCP client lease renewal method comprises: After the DHCP client successfully applies for an IP, the process of the DHCP client is stopped, and the lease returned by the DHCP server is received; Create a DHCP renewal timer and calculate the renewal waiting time according to the lease period; Passing the renewal waiting time to the DHCP renewal timer, and making the DHCP renewal timer enter a waiting state according to the renewal waiting time; When the waiting state ends, the connection state of the current STA is checked, and the DHCP client is started to renew the lease according to the connection state.

2. The DHCP client lease renewal method according to claim 1, characterized in that: After the DHCP client successfully applies for an IP address, the process of the DHCP client is stopped, and the lease returned by the DHCP server is received, which specifically includes: After the DHCP client receives the IP address allocation response from the DHCP server, stopping the process of the DHCP client and releasing related resources; Receive a DHCP ACK message returned by the DHCP server, parse the DHCP ACK message, and extract the lease period.

3. The DHCP client lease renewal method according to claim 1, characterized in that: The step of creating a DHCP renewal timer and calculating the renewal waiting time according to the lease period specifically includes: Create a DHCP renewal timer and initialize parameters of the DHCP renewal timer; The renewal waiting time is calculated according to the lease period based on a preset algorithm.

4. The DHCP client lease renewal method according to claim 1, characterized in that: The step of transferring the renewal waiting time to the DHCP renewal timer and causing the DHCP renewal timer to enter a waiting state according to the renewal waiting time specifically includes: The renewal waiting time is passed as a parameter to the DHCP renewal timer, the DHCP renewal timer is started and enters a waiting state according to the waiting time, and the current waiting time is recorded.

5. The DHCP client lease renewal method according to claim 4, characterized in that: After the waiting state ends, checking the connection state of the current STA, and starting the DHCP client to renew the lease according to the connection state, which also includes: Write the creation function in STA; When the current waiting time reaches the renewal waiting time, creating a DHCP renewal thread according to the creation function; Initialize parameters of the DHCP lease renewal thread and set the priority of the DHCP lease renewal thread.

6. The DHCP client lease renewal method according to claim 5, characterized in that: The checking of the connection status of the current STA and starting the DHCP client to renew the lease according to the connection status specifically includes: In the DHCP lease renewal thread, the local network interface is called to check the connection status of the current STA; If it is detected that the STA is in a disconnected hotspot state, recalculate the renewal waiting time and continue to enter the waiting state or directly terminate the DHCP renewal thread; If it is detected that the STA is in a hotspot connection state, when the current waiting time reaches the renewal waiting time, the DHCP renewal timer is stopped, the DHCP client is started, and a DHCP renewal request is sent to the DHCP server for renewal according to the DHCP renewal thread. After the renewal is successful, the lease information is updated and the DHCP renewal timer is initialized.

7. The DHCP client lease renewal method according to claim 1, characterized in that: The method further comprises starting the DHCP client to renew the lease according to the connection state: If the STA reconnects to a different hotspot, the DHCP client process is immediately started and a renewal request is initiated; If the renewal fails, record the error message generated and try to renew the lease.

8. A DHCP client lease renewal system, characterized in that: The DHCP client lease renewal system comprises: The receiving module is used to stop the process of the DHCP client after the DHCP client successfully applies for an IP address, and receive the renewal time returned by the DHCP server; A creation module is used to create a DHCP renewal timer and calculate a renewal waiting time according to the renewal time; A waiting module, used for transferring the renewal waiting time to the DHCP renewal timer, and making the DHCP renewal timer enter a waiting state according to the renewal waiting time; The renewal module is used to check the connection status of the current STA after the waiting state ends, and start the DHCP client to renew the lease according to the connection status.

9. A terminal, characterized in that: The terminal includes: a memory, a processor, and a DHCP client lease renewal program stored in the memory and executable on the processor. When the DHCP client lease renewal program is executed by the processor, the steps of the DHCP client lease renewal method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a DHCP client lease renewal program, and when the DHCP client lease renewal program is executed by a processor, the steps of the DHCP client lease renewal method according to any one of claims 1 to 7 are implemented.