Method and apparatus for updating device networking state, electronic device, and storage medium
By monitoring device behavior and selecting appropriate detection mechanisms to update device network status, the problem of misjudgment caused by network fluctuations is solved, the accuracy and real-time performance of network status are improved, and the stability of upper-layer services is ensured.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHONGQING LANDIAN AUTOMOBILE TECHNOLOGY CO LTD
- Filing Date
- 2026-03-11
- Publication Date
- 2026-06-05
AI Technical Summary
In existing technologies, when a device fails to send heartbeat packets due to a momentary network outage or signal fluctuation, the server may mistakenly determine that the device is offline, triggering unnecessary disconnection processing. This affects the accuracy and real-time nature of the device's network status, and consequently the reliability of upper-layer services.
By monitoring the devices, their behavior can be determined, and appropriate target detection mechanisms can be selected based on the device behavior, including login status verification, heartbeat update, liveness judgment, duplicate connection detection, idle connection monitoring, and resource cleanup mechanisms, so as to flexibly update the device's network status.
It improves the accuracy and real-time performance of device network status management, ensures the reliable operation of upper-layer services, and avoids misjudgments and unnecessary disconnections caused by network fluctuations.
Smart Images

Figure CN122160253A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet of Things (IoT) technology, and in particular to a method, apparatus, electronic device, and storage medium for updating the network status of a device. Background Technology
[0002] In the Internet of Things (IoT) and various network communication systems, the network status (online / offline) of devices is the foundation of upper-layer business logic. Accurate and real-time sensing of device online status is crucial for message push, data collection, resource scheduling, and other functions.
[0003] In related technologies, existing methods for updating device network status mainly rely on heartbeat mechanisms. Servers periodically receive heartbeat packets from devices to determine their network status and update it accordingly. However, when a device is temporarily unable to send heartbeat packets due to network interruptions or signal fluctuations, but is still functioning normally, the server may mistakenly determine the device is offline due to the lack of heartbeat packets, triggering unnecessary disconnection and status updates. This compromises the accuracy and real-time nature of the device's network status, impacting various upper-layer services that depend on the device's status. Summary of the Invention
[0004] The purpose of this application is to provide a method, apparatus, electronic device, and storage medium for updating the network status of a device. This addresses the technical problem in the prior art where, when a device is temporarily unable to send heartbeat packets due to network interruptions or signal fluctuations, but the device itself is still in normal working order, the server will mistakenly determine that the device is offline due to the lack of heartbeat packets, triggering unnecessary disconnection processing and status updates. This leads to a lack of accuracy and real-time performance of the device's network status, thus affecting various upper-layer services that rely on the device's status. The specific technical solution is as follows: In a first aspect of this application, a method for updating the network status of a device is provided, the method comprising: Monitor the equipment to determine its behavior; Based on the device behavior, a target detection mechanism is determined; Based on the target detection mechanism and the device behavior, the network status of the device is updated.
[0005] In an optional implementation, monitoring the device and determining its behavior includes: If a login event is detected on the device, the device behavior is determined to be a login behavior; If a heartbeat event is detected in the device, then the device behavior is determined to be a heartbeat behavior; If an uplink data event is detected from the device, the device behavior is determined to be a live behavior. If a communication connection establishment event is detected for the device, then the device behavior is determined to be a connection behavior; If a logout event is detected on the device, the device behavior is determined to be a logout behavior.
[0006] In an optional implementation, determining the target detection mechanism based on the device behavior includes: If the device behavior is the login behavior, then the target detection mechanism is determined to be a login state verification mechanism; If the device behavior is the heartbeat behavior, then the target detection mechanism is determined to be a heartbeat update mechanism; If the device behavior is the survival behavior, then the target detection mechanism is determined to be a survival judgment mechanism; If the device behavior is the connection behavior, then the target detection mechanism is determined to be a duplicate connection detection mechanism and / or an idle connection listening mechanism; If the device behavior is the logout behavior, then the target detection mechanism is determined to be a resource cleanup mechanism.
[0007] In an optional implementation, the target detection mechanism is the login status verification mechanism, and the step of updating the network status of the device based on the target detection mechanism and the device behavior includes: Login permission verification is performed on the device behavior based on the login status verification mechanism. If the login permission verification passes, the device's network status will be updated to online.
[0008] In an optional implementation, the target detection mechanism is the heartbeat update mechanism, and the step of updating the network status of the device based on the target detection mechanism and the device behavior includes: Receive the heartbeat packet corresponding to the device behavior; The heartbeat packets corresponding to the device behavior are parsed to obtain the device identifier and / or timestamp information; Based on the heartbeat update mechanism, the device identifier and / or timestamp information are validated to obtain the validation result. If the validity verification result is valid, then the network status of the device will be updated to online; If the validity check result is invalid, then the network status of the device is updated to offline.
[0009] In an optional implementation, the target detection mechanism is the liveness determination mechanism, and the step of updating the network status of the device based on the target detection mechanism and the device behavior includes: Obtain the first timestamp of the device communication; Get the current timestamp; Obtain the time difference threshold from the survival determination mechanism; The absolute difference between the first timestamp and the current timestamp is taken as the time difference; If the time difference is greater than the time difference threshold, the network status of the device is updated to offline; If the time difference is less than or equal to the time difference threshold, then the network status of the device is updated to online.
[0010] In an optional implementation, the target detection mechanism is the duplicate connection detection mechanism, and updating the network status of the device based on the target detection mechanism and the device behavior includes: The device behavior is parsed to obtain the device identifier and connection identifier; Obtain the memory record based on the connection identifier; Based on the duplicate connection detection mechanism, the memory record, and the device identifier, the device behavior is duplicated to obtain a duplicate verification result. If the duplicate verification result is a duplicate connection, then update the network status of the device to online; If the duplicate verification result is no duplicate connection, then the network status of the device is updated to offline.
[0011] In an optional implementation, the target detection mechanism is the idle connection monitoring mechanism, and the step of updating the network status of the device based on the target detection mechanism and the device behavior includes: Obtain the read / write data corresponding to the device behavior; Based on the idle connection monitoring mechanism, idle verification is performed on the read and write data corresponding to the device behavior to obtain the idle verification result. If the idle check result is idle timeout, then the network status of the device is updated to offline.
[0012] In an optional implementation, the target detection mechanism is the resource cleanup mechanism, and updating the network status of the device based on the target detection mechanism and the device behavior includes: The device behavior is parsed to obtain the device identifier and / or logout parameters; The validity of the device identifier and / or logout parameters is verified to obtain the resource cleanup verification result; If the resource cleanup verification result is successful, the network status of the device will be updated to offline.
[0013] In a second aspect of this application, a device for updating its network status is also provided, the device comprising: The monitoring module is used to monitor the equipment and determine its behavior. The detection mechanism determination module is used to determine the target detection mechanism based on the device behavior; The network status update module is used to update the network status of the device based on the target detection mechanism and the device behavior.
[0014] In a third aspect of the embodiments of this application, an electronic device is also provided, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method for updating the network status of the device as described in any of the first aspects above.
[0015] In a fourth aspect of the embodiments of this application, a storage medium is also provided, the storage medium storing instructions that, when run on a computer, cause the computer to execute the device network status update method described in any of the first aspects above.
[0016] In a fifth aspect of the embodiments of this application, a computer program product including instructions is also provided, which, when run on a computer, causes the computer to perform the device network status update method described in any of the first aspects above.
[0017] The technical solution provided in this application monitors the device and determines its behavior; based on the device behavior, a target detection mechanism is determined; and based on the target detection mechanism and the device behavior, the device's network status is updated. This flexible selection of the target detection mechanism based on device behavior to update the device's network status improves the accuracy, real-time performance, and stability of device network status management, ensuring the reliable operation of upper-layer services. It also solves the technical problem in existing technologies where, when a device is temporarily unable to send heartbeat packets due to network interruptions or signal fluctuations, but the device itself is still in normal working order, the server will mistakenly judge the device as offline due to the lack of heartbeat packets, triggering unnecessary disconnection processing and status updates. This results in the inability to guarantee the accuracy and real-time performance of the device's network status, thus affecting various upper-layer services that depend on the device's status. Attached Figure Description
[0018] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0019] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.
[0021] Figure 1 A schematic diagram illustrating the implementation process of a device network status update method provided in this application embodiment; Figure 2 A schematic diagram illustrating the implementation process of another method for updating the network status of a device provided in this application embodiment; Figure 3 This is a schematic diagram illustrating the implementation process of a method for updating the network status of a device based on a heartbeat update mechanism, as provided in an embodiment of this application. Figure 4 This is a schematic diagram illustrating the implementation process of a method for updating the network status of a device based on a liveness determination mechanism, as provided in an embodiment of this application. Figure 5 A schematic diagram of a device network status update apparatus provided in an embodiment of this application; Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0023] The following disclosure provides numerous different embodiments or examples for implementing various structures of this application. To simplify the disclosure, specific examples of components and arrangements are described below. These are merely examples and are not intended to limit the scope of this application. Furthermore, reference numerals and / or letters may be repeated in different examples. Such repetition is for simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or arrangements discussed.
[0024] To address the technical problem in existing technologies where devices are temporarily unable to send heartbeat packets due to network interruptions or signal fluctuations, but are still functioning normally, the server may mistakenly determine the device is offline due to the lack of heartbeat packets, triggering unnecessary disconnection and status updates. This leads to a lack of accuracy and real-time performance in monitoring the device's network status, ultimately impacting various upper-layer services that rely on the device's status. This application provides a method, apparatus, electronic device, and storage medium for updating the device's network status. The method involves monitoring the device to determine its behavior; determining a target detection mechanism based on the device behavior; and updating the device's network status based on the target detection mechanism and the device behavior. This flexible selection of a target detection mechanism based on device behavior for updating the device's network status improves the accuracy, real-time performance, and stability of network status management, ensuring the reliable operation of upper-layer services.
[0025] like Figure 1 The diagram shown is a schematic representation of the implementation process of a device network status update method provided in this application embodiment, which may specifically include the following steps: S101, Monitor the equipment and determine its behavior.
[0026] The aforementioned devices refer to terminal devices that are connected to the Internet of Things (IoT), such as sensors, smart terminals, vehicle-mounted systems, and industrial controllers. These devices can establish connections with servers via TCP (Transmission Control Protocol) to access the IoT.
[0027] The aforementioned monitoring refers to the server continuously listening to and recording the communication activities of access devices, which may include various messages sent by the devices, changes in connection status, etc.
[0028] The aforementioned device behaviors refer to specific events or actions generated by the device during its interaction with the server. These can include: connection behaviors (i.e., the device and server complete a TCP handshake and establish a communication channel), login behaviors (i.e., the device sends authentication information to request access to the system), heartbeat behaviors (i.e., the device periodically sends heartbeat messages to maintain the connection), liveness behaviors (i.e., the device actively reports business data, such as GPS location, status information, sensor readings, etc.), link idle behaviors (i.e., the device does not send any data for a long time and is in a silent state), and logout / disconnection behaviors (i.e., the device actively or passively disconnects from the server).
[0029] In this embodiment, the server can monitor the device and determine its behavior. By continuously monitoring the interaction between the device and the server and capturing the device's behavioral events, raw data can be provided for subsequent judgment of the device's true state, thus avoiding misjudgments caused by relying solely on heartbeat packets.
[0030] Specifically, the server can build an IoT device access service module based on Netty technology, open a TCP communication port and maintain a continuous listening state on the port. Through a built-in communication link listener and message parser, it can monitor the entire communication process of the device in real time. For example, the server captures the link-layer interaction behavior between the device and the server via the TCP protocol, including TCP handshake connection establishment, link data transmission, no data interaction, and TCP link active / passive disconnection, and records link state change events in real time, synchronously generating link behavior logs. The server uses the message parser to capture and identify various application-layer messages sent by the access device, including login authentication messages, heartbeat maintenance messages, business data reporting messages (GPS, sensor, device status, etc.), and active logout messages. It parses and records the sending time, message type, and message content of each type of message, forming a... The server generates device message interaction logs. It associates and merges the connection state changes captured by the link layer with the message interaction information parsed by the application layer. Based on the preset device behavior classification rules, it classifies the merged monitoring data into behaviors and finally determines the specific behavior type currently generated by the device (one or more of the following: connection behavior, login behavior, heartbeat behavior, liveness behavior, link idle behavior, logout / disconnection behavior). The server then binds the device behavior type with the corresponding behavior generation timestamp and associated TCP channel identifier and stores it in the device state management cache in the server's memory. This provides complete and traceable raw data support for the subsequent target detection mechanism.
[0031] S102, Determine the target detection mechanism based on device behavior.
[0032] The aforementioned target detection mechanism refers to a set of status judgment rules or strategies selected based on the current device behavior characteristics. The core execution logic of the server in determining the device's network status can match a single or combined detection mechanism based on the singularity or combination of device behaviors. These target detection mechanisms may include: a login event detection mechanism: directly determining online status based on whether the device has successfully logged in; a heartbeat event detection mechanism: considering the device online upon receiving a heartbeat packet; an uplink data time difference detection mechanism: determining device viability by comparing the difference between the device's most recent uplink data time and the current time; a link idle detection mechanism: using an idle timeout mechanism, determining offline status if the device has not interacted with any data for a set period; and multi-event linkage detection, which can integrate multiple events for status confirmation, such as combining heartbeats and uplink data to maintain status after login.
[0033] In this embodiment, a target detection mechanism is determined based on device behavior. By selecting the most suitable detection mechanism according to the current behavior of the device, accurate device status management can be achieved.
[0034] Specifically, the server has a built-in device behavior-detection mechanism mapping rule library. This rule library pre-establishes unique matching relationships between various device behaviors and corresponding detection mechanisms, and also supports the association configuration of combined device behaviors and multi-event linkage detection mechanisms. The server extracts the device behavior type (single behavior or combined behavior) determined in step S101 from the device status management cache, and performs precise matching in the rule library according to the preset mapping rules to determine the target detection mechanism.
[0035] S103 updates the network status of the device based on the target detection mechanism and device behavior.
[0036] In this embodiment, the device's network status is updated based on the target detection mechanism and device behavior. The network status refers to the device's current online / offline identifier, which can be stored in a server in-memory database (such as Redis) or a local cache. Updating refers to setting or changing the device's network status.
[0037] Based on the above description of the technical solutions provided in the embodiments of this application, the device is monitored to determine the device behavior; based on the device behavior, a target detection mechanism is determined; and based on the target detection mechanism and the device behavior, the network status of the device is updated.
[0038] By flexibly selecting target detection mechanisms based on device behavior to update the device's network status, the accuracy, real-time performance, and stability of device network status management can be improved, ensuring the reliable operation of upper-layer services. This addresses the technical problem in existing technologies where, when a device is temporarily unable to send heartbeat packets due to network interruptions or signal fluctuations, but the device itself is still in normal working order, the server will mistakenly judge the device as offline due to the lack of heartbeat packets, triggering unnecessary disconnection processing and status updates. This leads to a lack of assurance regarding the accuracy and real-time performance of the device's network status, which in turn affects various upper-layer services that depend on the device's status.
[0039] like Figure 2 The diagram shown is a schematic representation of the implementation process of another method for updating the network status of a device provided in this application. Figure 2 exist Figure 1 Based on this, it describes in detail how to determine device behavior and target detection mechanisms, as well as how to update the device's network status, which may include the following: S201, If a login event is detected on the device, the device behavior is determined to be a login behavior.
[0040] The aforementioned login event refers to the authentication request message that the device actively sends to the server after establishing a TCP connection. It may contain information such as device identifier (e.g., device serial number) and key to prove its legitimacy.
[0041] The aforementioned login behavior refers to a login event occurring on the device, indicating that the device is performing identity authentication and requesting access.
[0042] In this embodiment of the application, if a login event of the device is detected, the device behavior is determined to be a login behavior.
[0043] S202, if a heartbeat event is detected in the device, the device behavior is determined to be a heartbeat behavior.
[0044] The aforementioned heartbeat event refers to a heartbeat message that the device actively sends to the server at preset time intervals (such as 30 seconds or 60 seconds) to maintain the connection, informing the server that it is still alive and in a normal communication state.
[0045] The aforementioned heartbeat behavior refers to the occurrence of a heartbeat event by the device, which indicates that the device is performing actions to maintain link liveness.
[0046] In this embodiment, if a heartbeat event is detected in the device, the device behavior is determined to be a heartbeat behavior. Real-time identification of heartbeat events provides behavioral basis for subsequent matching of the heartbeat event detection mechanism, enabling rapid updates to the device's online status.
[0047] S203, if an uplink data event of the device is detected, the device behavior is determined to be a live behavior.
[0048] The aforementioned uplink data events refer to various business data messages that the device actively sends to the server during communication, including but not limited to GPS location information, sensor-collected data, device operating status data, business instruction feedback data, and other uplink data with actual business value.
[0049] The aforementioned survival behavior refers to the occurrence of uplink data events by the device, which indicates that the device is in a communication active state. It can be the core behavior of a device without a heartbeat packet to demonstrate that it is online, and can serve as an effective supplement to the heartbeat behavior.
[0050] In this embodiment of the application, if an uplink data event of the device is detected, the device behavior is determined to be a live behavior.
[0051] S204 If a communication connection establishment event is detected for the device, the device behavior is determined to be a connection behavior.
[0052] The aforementioned communication connection establishment event refers to the network event in which the device and the server complete a TCP three-way handshake, successfully establish a TCP communication link, and realize the construction of the basic communication channel between the device and the server.
[0053] The aforementioned connection behavior refers to the occurrence of a communication connection establishment event by the device, which means that the device has completed the link establishment action with the server.
[0054] In this embodiment of the application, if a communication connection establishment event of the device is detected, the device behavior is determined to be a connection behavior.
[0055] S205, if a device logout event is detected, the device behavior is determined to be a logout behavior.
[0056] The aforementioned logout event refers to a network event in which a device actively sends a disconnection request message to the server during communication, or a network event in which the server detects a passive disconnection of the TCP link between the device and the server. It can include both active and passive logout events.
[0057] The above-mentioned logout behavior refers to the device experiencing a logout event, which means that the device is performing a link disconnection action with the server, and is the core behavior of the device ending communication interaction.
[0058] In this embodiment of the application, if a device logout event is detected, the device behavior is determined to be a logout behavior.
[0059] S206, If the device behavior is a login behavior, then the target detection mechanism is determined to be a login state verification mechanism.
[0060] The aforementioned login status verification mechanism refers to the rules for verifying the legitimacy of device login behavior and determining its status. It is used to verify the validity of the authentication information submitted by the device, in order to determine whether the device has the authority to access the system and update the corresponding network status.
[0061] In this embodiment, if the device behavior is a login behavior, the target detection mechanism is determined to be a login state verification mechanism. By matching a dedicated identity verification rule to the login behavior, precise access control for device access can be achieved, ensuring that only legitimate devices can enter the online state and improving system access security.
[0062] S207, If the device behavior is a heartbeat behavior, then the target detection mechanism is determined to be a heartbeat update mechanism.
[0063] The aforementioned heartbeat update mechanism refers to the link activity determination and status refresh rules formulated for device heartbeat behavior. Based on the heartbeat message received by the server, it confirms in real time that the device communication link is normal and updates and maintains the device's online status.
[0064] In this embodiment, if the device behavior is a heartbeat behavior, then the target detection mechanism is determined to be a heartbeat update mechanism. By matching a dedicated status refresh rule to the heartbeat behavior, it is possible to quickly respond to the device's link liveness feedback and achieve real-time maintenance of the device's online status.
[0065] S208, If the device behavior is a live behavior, then the target detection mechanism is determined to be a liveness judgment mechanism.
[0066] The aforementioned survival determination mechanism refers to the dynamic judgment rule for communication activity based on the device's survival behavior. It can be determined whether the device is in an effective active state by comparing the difference between the time of the device's most recent uplink service data transmission and the current system time, combined with a preset threshold.
[0067] In this embodiment, if the device behavior is a liveness behavior, then the target detection mechanism is determined to be a liveness judgment mechanism. By matching exclusive dynamic judgment rules to liveness behaviors, the device status can be determined based on business data, serving as an effective supplement to the heartbeat mechanism and adapting to the status management needs of devices without heartbeat packets.
[0068] S209, if the device behavior is connection behavior, then determine the target detection mechanism as a duplicate connection detection mechanism and / or an idle connection listening mechanism.
[0069] The aforementioned duplicate connection detection mechanism refers to the login status pre-verification rules formulated for device connection behavior, used to determine whether a device already has a valid login session, and to avoid resource conflicts caused by multiple connections established by the same device.
[0070] The aforementioned idle connection monitoring mechanism refers to the login timeout judgment rules defined for device connection behavior. Its core function is to monitor whether the device initiates a login request within a preset time after establishing a connection, and to promptly clean up invalid connections that have not been logged in.
[0071] In this embodiment, if the device behavior is a connection behavior, the target detection mechanism is determined to be a duplicate connection detection mechanism and / or an idle connection listening mechanism. By matching dedicated rules for connection verification and idle listening to the connection behavior, the validity of device access can be controlled from the source, avoiding invalid connections and duplicate connections from consuming server resources.
[0072] S210, if the device behavior is a logout behavior, then the target detection mechanism is determined to be a resource cleanup mechanism.
[0073] The aforementioned resource cleanup mechanism refers to the status update and server resource reclamation rules formulated for device logout behavior. It is used to synchronously update the device's offline status and clean up the corresponding cache, channels, and other related resources of the device after determining that the device link is disconnected.
[0074] In this embodiment, if the device behavior is a logout behavior, the target detection mechanism is determined to be a resource cleanup mechanism. By matching specific state and resource management rules to the logout behavior, timely synchronization of the device's offline state can be achieved, while efficiently reclaiming server resources and optimizing system resource utilization efficiency.
[0075] S211 updates the network status of the device based on the target detection mechanism and device behavior.
[0076] In this embodiment of the application, the network status of the device is updated based on the target detection mechanism and device behavior.
[0077] Specifically, for a target detection mechanism that is a login status verification mechanism, the network status of the device is updated based on the target detection mechanism and device behavior. This can include the following steps: Step 11: Verify login permissions for device behavior based on the login status verification mechanism.
[0078] In this embodiment, the server extracts core information such as device identifier and key from the authentication request message corresponding to the device login behavior based on the preset verification rules of the login state verification mechanism, and compares it with the server's pre-stored legitimate device information database. If they match, the login permission verification passes; if they do not match, the login verification fails.
[0079] Step 12: If the login permission verification passes, update the device's network status to online.
[0080] In this embodiment of the application, if the login permission verification result is passed, it means that the device identity is legitimate and has system access permission. The server can immediately update the network status of the device to online, initialize the message timestamp of the TCP channel associated with the device, retain the device login success record and mark the link as active, so as to ensure that the device can carry out subsequent communication interactions normally.
[0081] The target detection mechanism is a heartbeat update mechanism. Based on the target detection mechanism and device behavior, the device's network status is updated. For details, please refer to... Figure 3 The method shown. (As illustrated) Figure 3 The diagram shown is a flowchart illustrating an implementation process of a method for updating the network status of a device based on a heartbeat update mechanism, according to an embodiment of this application. Specifically, it may include the following steps: S301, receive the heartbeat packet corresponding to the device's behavior.
[0082] The aforementioned heartbeat packet refers to the link liveness maintenance message sent by the device to the server based on heartbeat behavior. It is a dedicated data message from the device to inform the server that its communication is normal.
[0083] In this embodiment, the server receives heartbeat packets sent by the device's heartbeat behavior in real time through the TCP communication port of the IoT device access service module.
[0084] S302, parse the heartbeat packet corresponding to the device behavior to obtain the device identifier and / or timestamp information.
[0085] In this embodiment, the heartbeat packets corresponding to device behavior are parsed to obtain device identifiers and / or timestamp information. The device identifier uniquely identifies the device sending the heartbeat packet, and the timestamp information is the local or network time at which the device sent the heartbeat packet, used to assist in determining the validity of the device communication timing.
[0086] Specifically, the server performs protocol parsing and data extraction on the received heartbeat packets, obtaining the corresponding device identifier (such as the device serial number) and / or extracting the timestamp information carried within the heartbeat packets. Simultaneously, it can bind the parsed valid information (device identifier and / or timestamp information) with the associated TCP channel identifier, providing accurate device identification and timing data for subsequent validity verification.
[0087] S303, based on the heartbeat update mechanism, performs validity verification on the device identifier and / or timestamp information to obtain the validity verification result.
[0088] The aforementioned validity verification refers to the server determining the legality and timeliness of the parsed device identifier and / or timestamp information according to the preset rules of the heartbeat update mechanism. The verification content may include whether the device identifier is a legal identifier that has been registered with the server, whether the timestamp information is within a reasonable time error range, and whether the device is in a basic logged-in state. The validity verification result can be divided into two types: valid and invalid.
[0089] In this embodiment of the application, the validity of the device identifier and / or timestamp information can be verified based on the heartbeat update mechanism to obtain the validity verification result.
[0090] Specifically, the server can perform multi-dimensional verification of the parsed device identifier and / or timestamp information based on the verification rules of the heartbeat update mechanism, and obtain the corresponding validity verification result after comprehensive judgment. S304 If the validity check result is valid, then update the device's network status to online.
[0091] In this embodiment of the application, if the validity verification result is valid, it means that the device's heartbeat behavior is legal and the communication link is in a normal and active state. The server immediately updates / maintains the device's network status to online and refreshes the timestamp of the last message in the TCP channel associated with the device to mark the link as continuously active, ensuring the timeliness of the device's online status.
[0092] S305, if the validity check result is invalid, then update the device's network status to offline.
[0093] In this embodiment of the application, if the validity verification result is invalid, it means that the device heartbeat behavior is illegal (such as invalid device identifier or abnormal timestamp) or the device has lost its legal communication qualification. The server immediately updates the network status of the device to offline and triggers the link detection process to verify the validity of the associated TCP link of the device, providing a basis for subsequent resource cleanup.
[0094] Specifically, the target detection mechanism is a liveness detection mechanism. Based on the target detection mechanism and device behavior, the network status of the device is updated. For details, please refer to... Figure 4 The method shown. (As illustrated) Figure 4 The diagram shown is a flowchart illustrating the implementation process of a method for updating the network status of a device based on a liveness determination mechanism, according to an embodiment of this application. Specifically, it may include the following steps: S401, obtain the first timestamp of device communication.
[0095] The aforementioned first timestamp refers to the timestamp recorded by the server when the device last performed a live action and sent an uplink business data packet to the server. It can be stored in the TCP channel memory associated with the device and in the server's device status management cache.
[0096] In this embodiment, the server can extract the receiving timestamp of the device's most recent uplink data packet from the memory of the TCP channel bound to the device, and use it as the first timestamp of the device communication.
[0097] S402, Get the current timestamp.
[0098] The current timestamp mentioned above refers to the system's current timestamp when the server executes this step.
[0099] In this embodiment of the application, the server can directly retrieve the current timestamp of its own system to obtain the current timestamp.
[0100] S403, obtain the time difference threshold from the survival judgment mechanism.
[0101] The aforementioned time difference threshold, also known as the preset survival period threshold, is a time threshold set in the survival judgment mechanism to determine whether a device is in an active communication state. It can be flexibly configured according to the device type (such as sensor, vehicle unit, industrial controller) and application scenario, and is stored in the parameter configuration library of the survival judgment mechanism.
[0102] In this embodiment, the server can retrieve a time difference threshold that matches the device type from the preset parameter configuration library of the survival determination mechanism.
[0103] S404 uses the absolute difference between the first timestamp and the current timestamp as the time difference.
[0104] In this embodiment of the application, the absolute difference between the first timestamp and the current timestamp can be used as the time difference.
[0105] S405: If the time difference is greater than the time difference threshold, the device's network status will be updated to offline.
[0106] In this embodiment of the application, if the time difference is greater than the time difference threshold, it indicates that the communication silence duration of the device has exceeded the preset threshold, and the device is determined to be in an inactive state. The server immediately updates the network status of the device to offline and can trigger the link validity verification process to prepare for the subsequent cleanup of invalid connections.
[0107] S406, if the time difference is less than or equal to the time difference threshold, then update the network status of the updated device to online.
[0108] In this embodiment of the application, if the calculated time difference is less than or equal to the time difference threshold in the survival judgment mechanism, it indicates that the communication silence duration of the device is within a reasonable range, and the device is determined to still be in a communication active state. The server immediately updates / maintains the network status of the device to online, and refreshes the latest communication timestamp in the TCP channel associated with the device to ensure the validity of the time base for subsequent status judgment.
[0109] Specifically, for the target detection mechanism being a duplicate connection detection mechanism, the network status of the device is updated based on the target detection mechanism and device behavior, which may include the following steps: Step 21: Analyze the device behavior to obtain the device identifier and connection identifier.
[0110] The aforementioned device identifier refers to the unique information used to identify IoT devices, such as device serial number, device ID (Identity), device MAC (Media Access Control Address), etc. The aforementioned connection identifier refers to the unique link identifier generated after the device and the server establish a TCP connection, such as TCP channel ID, connection session identifier, etc., which is used to uniquely identify the communication link between the device and the server in this instance.
[0111] In this embodiment of the application, the server can perform protocol parsing and data extraction on the connection behavior of the access device, and synchronously parse out the device identifier and the connection identifier corresponding to this connection from the link interaction data of the device establishing a TCP connection.
[0112] Step 22: Obtain memory records based on connection identifiers.
[0113] The aforementioned memory records refer to the connection status records maintained by the server in memory for each valid TCP connection. These records can include core information such as device identifier, connection identifier, login status, connection establishment time, and link activity status, and are used to store the connection and communication status of devices in real time.
[0114] In this embodiment, the server can use the parsed connection identifier as the retrieval basis to perform a precise query in the connection record database of the device status management cache, obtain the complete memory record corresponding to the connection identifier, and provide historical status data for subsequent duplicate connection determination.
[0115] Step 23: Based on the duplicate connection detection mechanism, memory records, and device identifiers, perform duplicate verification on the device behavior to obtain the duplicate verification result.
[0116] The aforementioned duplicate check refers to the process by which the server, based on the preset rules of the duplicate connection detection mechanism, compares the device identifier of the current connection with the device identifier in the memory record and the existing valid connection records of the device to determine whether the current device has established other valid TCP connections. The duplicate check results can be divided into duplicate connections and non-duplicate connections.
[0117] In this embodiment, the server can retrieve all valid connection records of the device in the server's memory based on the verification rules of the duplicate connection detection mechanism, and combine the memory records of the current connection to determine whether the current connection behavior is a duplicate connection operation initiated by the same device. After comprehensive judgment, the corresponding duplicate verification result is obtained.
[0118] Step 24: If the duplicate verification result is a duplicate connection, then update the device's network status to online.
[0119] In this embodiment of the application, if the duplicate verification result is a duplicate connection, it means that the device has a valid login TCP connection in the server and is online. The server will directly update the network status of the device corresponding to this duplicate connection to online, and at the same time close the duplicate TCP connection and remove the corresponding processing logic to avoid resource conflicts caused by multiple channels of the same device.
[0120] Step 25: If the duplicate verification result is "no duplicate connection", then update the device's network status to "offline".
[0121] In this embodiment of the application, if the duplicate verification result is "no duplicate connection", it means that the device is establishing a TCP connection for the first time and has not yet completed login authentication. The server updates the network status of the device to offline and starts the login timeout listening logic to wait for the device to initiate a login request. If the device does not log in within the preset time, the TCP connection will be directly disconnected.
[0122] Specifically, for a target detection mechanism that is an idle connection listening mechanism, the network status of the device is updated based on the target detection mechanism and device behavior, which may include the following steps: Step 31: Obtain the read / write data corresponding to the device behavior.
[0123] The aforementioned read and write data refers to the read and write operation data generated on the communication link after the device and the server establish a TCP connection. This data may include data sending time, data receiving time, data exchange volume, link read and write status, etc., and is used to determine whether the link is in an idle state.
[0124] In this embodiment, the server can use Netty technology to collect TCP link read / write operation data corresponding to device connection behavior in real time, and synchronously record the latest data interaction time and read / write status of the link, thereby obtaining read / write data corresponding to device behavior. Step 32: Based on the idle connection monitoring mechanism, perform idle verification on the read and write data corresponding to the device behavior to obtain the idle verification result.
[0125] The aforementioned idle check refers to the process by which the server, based on the preset rules of the idle connection listening mechanism and combined with the link read and write data, determines whether the device generates valid data interaction (such as sending login requests, business data, etc.) within a preset time after establishing a TCP connection. It is used to determine whether the link is in a continuous idle state. The idle check result is divided into two types: idle timeout and no idle timeout.
[0126] In this embodiment of the application, based on the idle connection monitoring mechanism, idle verification is performed on the read and write data corresponding to the device behavior to obtain the idle verification result.
[0127] Specifically, the server obtains the current system timestamp, determines the absolute difference between the timestamps corresponding to the read and write data of the device behavior, and compares the absolute difference between the timestamps corresponding to the read and write data of the device behavior with the preset idle timeout threshold in the idle connection listening mechanism. If the absolute difference between the timestamps corresponding to the read and write data of the device behavior exceeds the preset idle timeout threshold in the idle connection listening mechanism, the idle check result is determined to be an idle timeout; otherwise, it is determined not to be an idle timeout.
[0128] Step 33: If the idle check result is idle timeout, then update the device's network status to offline.
[0129] In this embodiment of the application, if the idle check result is idle timeout, it means that after the device establishes a TCP connection, no valid data interaction is generated within a preset time. In this case, the connection is determined to be an invalid idle connection. The server immediately updates the network status of the device to offline and actively disconnects the TCP link and releases the corresponding server link resources to avoid invalid connections occupying system resources.
[0130] In another embodiment of this application, if the idle check result is "not idle timeout", it means that after the device establishes a TCP connection, there is valid data interaction within a preset time. Therefore, the connection is determined to be valid, and the server can keep the device's network status online.
[0131] Specifically, for a target detection mechanism that is a resource cleanup mechanism, updating the network status of the device based on the target detection mechanism and device behavior can include the following steps: Step 41: Analyze the device behavior to obtain the device identifier and / or logout parameters.
[0132] The above-mentioned logout parameters refer to the exclusive parameters carried by the device when initiating a logout action, including logout type (active logout / passive disconnection), logout timestamp, current connection identifier, link status code, etc.
[0133] In this embodiment of the application, the server performs a full-dimensional analysis of the device behavior (i.e., logout behavior) of the access device. If the device actively logs out, the device identifier and complete logout parameters are extracted. If the device is passively disconnected, the device identifier and key information such as the connection identifier and status code corresponding to the link disconnection are extracted.
[0134] Step 42: Verify the validity of the device identifier and / or logout parameters to obtain the resource cleanup verification result.
[0135] The aforementioned validity verification refers to the process by which the server, based on the preset rules of the resource cleanup mechanism, determines the legality and relevance of the parsed device identifier and / or logout parameters. The verification content may include whether the device identifier is a valid registration identifier, whether the logout parameters match the valid connection record of the current device, and whether the link status code is a normal disconnection code. The resource cleanup verification result can be divided into two types: verification passed and verification failed.
[0136] In this embodiment, the server compares the parsed device identifier and / or logout parameters with the device status record and connection record in the server's memory to complete the validity check and obtain the corresponding resource cleanup check result.
[0137] Step 43: If the resource cleanup verification result is successful, then update the device's network status to offline.
[0138] In this embodiment of the application, if the resource cleanup verification result is successful, it indicates that the device logout behavior is legal and the relevant parameters match the actual connection status. The server immediately updates the network status of the device to offline and, in accordance with the rules of the resource cleanup mechanism, completes the full cleanup of the corresponding cache resources (login information, timestamp, connection record) and link resources (TCP channel, session identifier) of the device, releasing server system resources and ensuring the consistency between device status and server resources.
[0139] In another embodiment of this application, if the resource cleanup verification result is that the verification fails, it indicates that the device logout behavior is abnormal and the relevant parameters do not match the actual connection status. The logout behavior is invalid, and the server will maintain the current network status of the device.
[0140] Corresponding to the above method embodiments, this application also provides a device for updating the network status of a device, such as... Figure 5 As shown, the device may include a monitoring module 501, a detection mechanism determination module 502, and a network status update module 503.
[0141] Monitoring module 501 is used to monitor the equipment and determine its behavior; The detection mechanism determination module 502 is used to determine the target detection mechanism based on device behavior; The network status update module 503 is used to update the network status of the device based on the target detection mechanism and device behavior.
[0142] This application also provides an electronic device, such as... Figure 6 As shown, it includes a processor 601, a communication interface 602, a memory 603, and a communication bus 604, wherein the processor 601, the communication interface 602, and the memory 603 communicate with each other through the communication bus 604. Memory 603 is used to store computer programs; In one embodiment of this application, when the processor 601 executes a program stored in the memory 603, it performs the following steps: Monitor the equipment to determine its behavior; determine the target detection mechanism based on the equipment behavior; and update the network status of the equipment based on the target detection mechanism and the equipment behavior.
[0143] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not indicate that there is only one bus or one type of bus.
[0144] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0145] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0146] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0147] In another embodiment provided in this application, a storage medium is also provided, which stores instructions that, when run on a computer, cause the computer to execute the device network status update method described in any of the above embodiments.
[0148] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute the device network status update method described in any of the above embodiments.
[0149] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a storage medium or transmitted from one storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0150] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0151] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0152] The above description is merely a specific embodiment of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the protection scope of this application.
Claims
1. A method for updating the network status of a device, characterized in that, The method includes: Monitor the equipment to determine its behavior; Based on the device behavior, a target detection mechanism is determined; Based on the target detection mechanism and the device behavior, the network status of the device is updated.
2. The method according to claim 1, characterized in that, The monitoring of the equipment to determine its behavior includes: If a login event is detected on the device, the device behavior is determined to be a login behavior; If a heartbeat event is detected in the device, then the device behavior is determined to be a heartbeat behavior; If an uplink data event is detected from the device, the device behavior is determined to be a live behavior. If a communication connection establishment event is detected for the device, then the device behavior is determined to be a connection behavior; If a logout event is detected on the device, the device behavior is determined to be a logout behavior.
3. The method according to claim 2, characterized in that, The determination of the target detection mechanism based on the device behavior includes: If the device behavior is the login behavior, then the target detection mechanism is determined to be a login state verification mechanism; If the device behavior is the heartbeat behavior, then the target detection mechanism is determined to be a heartbeat update mechanism; If the device behavior is the survival behavior, then the target detection mechanism is determined to be a survival judgment mechanism; If the device behavior is the connection behavior, then the target detection mechanism is determined to be a duplicate connection detection mechanism and / or an idle connection listening mechanism; If the device behavior is the logout behavior, then the target detection mechanism is determined to be a resource cleanup mechanism.
4. The method according to claim 3, characterized in that, The target detection mechanism is the login state verification mechanism. The step of updating the network status of the device based on the target detection mechanism and the device behavior includes: Login permission verification is performed on the device behavior based on the login status verification mechanism. If the login permission verification passes, the device's network status will be updated to online.
5. The method according to claim 3, characterized in that, The target detection mechanism is the heartbeat update mechanism. The step of updating the network status of the device based on the target detection mechanism and the device behavior includes: Receive the heartbeat packet corresponding to the device behavior; The heartbeat packets corresponding to the device behavior are parsed to obtain the device identifier and / or timestamp information; Based on the heartbeat update mechanism, the device identifier and / or timestamp information are validated to obtain the validation result. If the validity verification result is valid, then the network status of the device will be updated to online; If the validity check result is invalid, then the network status of the device is updated to offline.
6. The method according to claim 3, characterized in that, The target detection mechanism is the liveness determination mechanism. The step of updating the network status of the device based on the target detection mechanism and the device behavior includes: Obtain the first timestamp of the device communication; Get the current timestamp; Obtain the time difference threshold from the survival determination mechanism; The absolute difference between the first timestamp and the current timestamp is taken as the time difference; If the time difference is greater than the time difference threshold, the network status of the device is updated to offline; If the time difference is less than or equal to the time difference threshold, then the network status of the device is updated to online.
7. The method according to claim 3, characterized in that, The target detection mechanism is the duplicate connection detection mechanism, and the step of updating the network status of the device based on the target detection mechanism and the device behavior includes: The device behavior is parsed to obtain the device identifier and connection identifier; Obtain the memory record based on the connection identifier; Based on the duplicate connection detection mechanism, the memory record, and the device identifier, the device behavior is duplicated to obtain a duplicate verification result. If the duplicate verification result is a duplicate connection, then update the network status of the device to online; If the duplicate verification result is no duplicate connection, then the network status of the device is updated to offline.
8. The method according to claim 3, characterized in that, The target detection mechanism is the idle connection listening mechanism. The step of updating the network status of the device based on the target detection mechanism and the device behavior includes: Obtain the read / write data corresponding to the device behavior; Based on the idle connection monitoring mechanism, idle verification is performed on the read and write data corresponding to the device behavior to obtain the idle verification result. If the idle check result is idle timeout, then the network status of the device is updated to offline.
9. The method according to claim 3, characterized in that, The target detection mechanism is the resource cleanup mechanism. The step of updating the network status of the device based on the target detection mechanism and the device behavior includes: The device behavior is parsed to obtain the device identifier and / or logout parameters; The validity of the device identifier and / or logout parameters is verified to obtain the resource cleanup verification result; If the resource cleanup verification result is successful, the network status of the device will be updated to offline.
10. A device for updating the network status of a device, characterized in that, The device includes: The monitoring module is used to monitor the equipment and determine its behavior. The detection mechanism determination module is used to determine the target detection mechanism based on the device behavior; The network status update module is used to update the network status of the device based on the target detection mechanism and the device behavior.
11. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method described in any one of claims 1-9.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-9.