Hazardous chemical vehicle real-time positioning method and system based on WebSocket protocol
Through the use of the WebSocket protocol, the lack of data transmission rate and stability of hazardous chemical vehicle monitoring system has been solved, real-time positioning and safety management of hazardous chemical vehicles has been realized, and an efficient, reliable and safe transportation monitoring solution has been provided.
Patent Information
- Application Number
- CN202410955379.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-17
- Publication Date
- 2024-11-19
AI Technical Summary
The existing hazardous chemical vehicle monitoring system cannot meet the needs of high-speed and large-capacity data transmission in terms of data transmission rate, connection stability and network coverage, resulting in the inability to achieve real-time, safe and efficient hazardous chemical transportation management.
Using the WebSocket protocol, the original location data of hazardous chemical vehicles are received through the server and stored in Redis and MySQL databases. The client establishes a WebSocket connection with the server to maintain heartbeat detection, realizes real-time location push and display, and ensures the immediacy of data transmission and Security.
Improve the stability and security of data transmission, reduce network overhead, reduce the number of connection establishment and disconnection, avoid redundant information of traditional HTTP requests, and realize instant update of hazardous chemical vehicle location and status information and Safe push.
Smart Images

Figure CN118984441A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of transportation monitoring, and in particular to a real-time positioning method and system for a hazardous chemical vehicle based on a WebSocket protocol. Background Art
[0002] With the acceleration of industrialization and the booming logistics industry, the demand for the transportation of hazardous chemicals is growing. Due to their special physical and chemical properties, hazardous chemicals have put forward higher requirements for safety management during transportation. Although traditional hazardous chemical vehicle monitoring systems have met basic positioning and tracking needs to a certain extent, with the development of technology and the upgrading of market demand, these systems have gradually shown limitations in function and performance. The market has higher expectations for the communication speed and stability of hazardous chemical vehicle monitoring systems. Existing monitoring systems may not meet the needs of high-speed and large-capacity data transmission in terms of data transmission rate, connection stability and network coverage.
[0003] The WebSocket protocol, with its low latency and full-duplex communication characteristics, provides a technical foundation for the real-time data interaction, intelligent management and efficient data processing of hazardous chemical vehicle monitoring systems. Through the full-duplex communication capability of WebSocket, key information such as the vehicle's real-time location, operating status, speed and acceleration can be updated and transmitted to the monitoring center in real time. In the event of an abnormality or emergency in a hazardous chemical vehicle, the low latency characteristics of the WebSocket protocol enable it to quickly push key information to the monitoring center and receive instructions from the monitoring center to achieve fast and effective emergency response. At the same time, the encrypted communication function of the WSS protocol ensures the security of transmitted data, which is crucial for hazardous chemical vehicle monitoring involving sensitive information, and provides an efficient, reliable and secure technical solution for the safe management of hazardous chemical transportation. Summary of the invention
[0004] In view of the needs and shortcomings of current technological development, the present invention provides a real-time positioning method and system for hazardous chemicals vehicles based on the WebSocket protocol.
[0005] In the first aspect, the present invention provides a method for real-time positioning of hazardous chemicals vehicles based on the WebSocket protocol. The technical solution adopted to solve the above technical problems is as follows:
[0006] A method for real-time positioning of hazardous chemicals vehicles based on the WebSocket protocol comprises the following steps:
[0007] S1. The server receives the original location data of the hazardous chemicals vehicle from the third-party interface, and stores it in the Redis cache database and the MySQL relational database after preprocessing;
[0008] S2. The client establishes a WebSocket connection with the server and maintains heartbeat detection;
[0009] S3. The client sends a request for the current location of the hazardous chemicals vehicle to the server via WebSocket;
[0010] S4. The server queries the latest location information of the corresponding hazardous chemicals vehicle and pushes it to the client via WebSocket;
[0011] S5. The client displays the real-time location of the hazardous chemicals vehicle on the map;
[0012] S6. The client sets a timer to implement polling, and by repeating steps S1 to S5, the location of the hazardous chemicals vehicle is displayed on the map in real time.
[0013] Optionally, executing step S2, the client establishes a WebSocket connection with the server and maintains heartbeat detection, specifically including:
[0014] After the WebSocket connection is successfully established, the client sends a heartbeat request message to the server and sets a timeout. The heartbeat request message is agreed upon in advance by both parties.
[0015] After receiving the WebSocket message, if the server detects that it is a heartbeat request message, it will push a heartbeat response message to the client. The heartbeat response message is agreed upon in advance by both parties.
[0016] If the client receives the heartbeat response message sent by the server within the timeout period, it means that the WebSocket connection is normal and the heartbeat detection is reset;
[0017] If the client does not receive the heartbeat response message sent by the server within the timeout period, it means that the WebSocket connection is abnormal. The client closes the current WebSocket connection and re-establishes a new WebSocket connection with the server.
[0018] Optionally, when executing step S3, the hazardous chemicals vehicle current location request sent carries the license plate number information of the hazardous chemicals vehicle.
[0019] Further optionally, step S4 is performed, where the server queries the latest location information of the corresponding hazardous chemicals vehicle and pushes it to the client via WebSocket, specifically including:
[0020] The server queries the latest location information of the hazardous chemicals vehicle in the Redis cache database based on the license plate number.
[0021] If the query is successful, the latest location information of the hazardous chemicals vehicle will be pushed to the client via WebSocket.
[0022] If the query fails, the latest location information of the hazardous chemicals vehicle will be queried in the MySQL relational database based on the license plate number, and then the latest location information will be stored in the Redis cache server, and finally the latest location data of the hazardous chemicals vehicle will be pushed to the client through WebSocket.
[0023] Optionally, execute step S5. After the client receives the latest location information of the hazardous chemicals vehicle through WebSocket, the hazardous chemicals vehicle icon is displayed at the corresponding position on the map according to the latitude and longitude coordinates of the hazardous chemicals vehicle, so that the location of the hazardous chemicals vehicle is displayed on the map.
[0024] In the second aspect, the present invention provides a real-time positioning system for hazardous chemicals vehicles based on the WebSocket protocol. The technical solution adopted to solve the above technical problems is as follows:
[0025] A real-time positioning system for hazardous chemicals vehicles based on the WebSocket protocol, comprising:
[0026] The data processing module is deployed on the server side and is used to receive the original location data of hazardous chemicals vehicles from the third-party interface, and store them in the Redis cache database and the MySQL relational database after preprocessing;
[0027] The connection detection module is deployed on the server and client to establish a WebSocket connection between the client and the server and maintain heartbeat detection;
[0028] The request sending module is deployed on the client and is used to send the current location request of the hazardous chemicals vehicle to the server through WebSocket;
[0029] The query push module is deployed on the server side, used to query the latest location information of the corresponding hazardous chemicals vehicle and push it to the client via WebSocket;
[0030] The real-time display module is deployed on the client and is used to display the real-time location of hazardous chemicals vehicles on the map;
[0031] A polling module is set up and deployed on the client to set a timer to implement polling. By repeatedly executing the data processing module, connection detection module and request sending module, the location of the hazardous chemicals vehicle can be displayed in real time on the map.
[0032] Optionally, the connection detection module involved establishes a WebSocket connection between the client and the server and maintains heartbeat detection. The specific operations performed are as follows:
[0033] After the WebSocket connection is successfully established, the client sends a heartbeat request message to the server and sets a timeout. The heartbeat request message is agreed upon in advance by both parties.
[0034] After receiving the WebSocket message, if the server detects that it is a heartbeat request message, it will push a heartbeat response message to the client. The heartbeat response message is agreed upon in advance by both parties.
[0035] If the client receives the heartbeat response message sent by the server within the timeout period, it means that the WebSocket connection is normal and the heartbeat detection is reset;
[0036] If the client does not receive the heartbeat response message sent by the server within the timeout period, it means that the WebSocket connection is abnormal. The client closes the current WebSocket connection and re-establishes a new WebSocket connection with the server.
[0037] Optionally, the request sending module involved sends a request for the current location of the hazardous chemicals vehicle to the server via WebSocket, and the request carries the license plate number information of the hazardous chemicals vehicle.
[0038] Further optionally, the query push module involved queries the latest location information of the corresponding hazardous chemicals vehicle and pushes it to the client through WebSocket. The specific operations are as follows:
[0039] The server queries the latest location information of the hazardous chemicals vehicle in the Redis cache database based on the license plate number.
[0040] If the query is successful, the latest location information of the hazardous chemicals vehicle will be pushed to the client via WebSocket.
[0041] If the query fails, the latest location information of the hazardous chemicals vehicle will be queried in the MySQL relational database based on the license plate number, and then the latest location information will be stored in the Redis cache server, and finally the latest location data of the hazardous chemicals vehicle will be pushed to the client through WebSocket.
[0042] Optionally, after the real-time display module receives the latest location information of the hazardous chemicals vehicle through WebSocket, it displays the hazardous chemicals vehicle icon at the corresponding position on the map according to the latitude and longitude coordinates of the hazardous chemicals vehicle, thereby displaying the location of the hazardous chemicals vehicle on the map.
[0043] The method and system for real-time positioning of hazardous chemicals vehicles based on the WebSocket protocol of the present invention have the following beneficial effects compared with the prior art:
[0044] 1. The present invention can reduce network overhead, enhance data transmission stability and security, and provide an efficient, reliable and safe technical solution for the safe management of hazardous chemicals transportation;
[0045] 2. Real-time data exchange between the server and the client is achieved through the full-duplex communication mechanism of the WebSocket protocol, ensuring that the location and status information of hazardous chemical vehicles can be updated and received in real time; the persistent connection established through the WebSocket protocol reduces the number of connection establishment and disconnection times, reduces the risk of communication interruption due to network fluctuations, avoids the repeated handshake process of traditional HTTP requests, reduces redundant information in data transmission, and improves data transmission efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Attached Figure 1 is a flow chart of a method according to Embodiment 1 of the present invention;
[0047] Attached Figure 2 This is a module connection block diagram of the second embodiment of the present invention. DETAILED DESCRIPTION
[0048] In order to make the technical solution, the technical problem solved and the technical effect of the present invention more clearly understood, the technical solution of the present invention is clearly and completely described below in conjunction with specific embodiments.
[0049] Embodiment 1:
[0050] Combined with Figure 1 This embodiment proposes a real-time positioning method for hazardous chemicals vehicles based on the WebSocket protocol, which includes the following steps:
[0051] S1. The server receives the original location data of the hazardous chemicals vehicle from the third-party interface, and stores it in the Redis cache database and MySQL relational database after preprocessing.
[0052] The purpose of storing the pre-processed data in the Redis cache database is that the Redis cache database is a high-performance database with very fast reading and writing speeds, which can ensure the real-time positioning of subsequent vehicles.
[0053] The purpose of storing the preprocessed data in the MySQL relational database is to ensure permanent storage of the data and prevent data loss so that data can be quickly restored when data is missing in the Redis cache database.
[0054] It should be added that after the server pre-processes the original location data of the hazardous chemicals vehicle, it stores the basic information, license plate number information and vehicle coordinate information of the hazardous chemicals vehicle into the Redis cache database and the MySQL relational database respectively.
[0055] S2. The client establishes a WebSocket connection with the server and maintains heartbeat detection, including:
[0056] After the WebSocket connection is successfully established, the client sends a heartbeat request message to the server and sets a timeout. The heartbeat request message is agreed upon in advance by both parties.
[0057] After receiving the WebSocket message, if the server detects that it is a heartbeat request message, it will push a heartbeat response message to the client. The heartbeat response message is agreed upon in advance by both parties.
[0058] If the client receives the heartbeat response message sent by the server within the timeout period, it means that the WebSocket connection is normal and the heartbeat detection is reset;
[0059] If the client does not receive the heartbeat response message sent by the server within the timeout period, it means that the WebSocket connection is abnormal. The client closes the current WebSocket connection and re-establishes a new WebSocket connection with the server.
[0060] S3. The client sends a request for the current location of the hazardous chemicals vehicle to the server through WebSocket, and the request carries the license plate number information of the hazardous chemicals vehicle.
[0061] S4. The server queries the latest location information of the corresponding hazardous chemicals vehicle and pushes it to the client through WebSocket, including:
[0062] The server queries the latest location information of the hazardous chemicals vehicle in the Redis cache database based on the license plate number.
[0063] If the query is successful, the latest location information of the hazardous chemicals vehicle will be pushed to the client via WebSocket.
[0064] If the query fails, the latest location information of the hazardous chemicals vehicle will be queried in the MySQL relational database based on the license plate number, and then the latest location information will be stored in the Redis cache server, and finally the latest location data of the hazardous chemicals vehicle will be pushed to the client through WebSocket.
[0065] S5. After the client receives the latest location information of the hazardous chemicals vehicle through WebSocket, it displays the hazardous chemicals vehicle icon at the corresponding position on the map according to the latitude and longitude coordinates of the hazardous chemicals vehicle, thereby displaying the location of the hazardous chemicals vehicle on the map.
[0066] S6. The client sets a timer to implement polling, and by repeating steps S1 to S5, the location of the hazardous chemicals vehicle is displayed on the map in real time.
[0067] Embodiment 2:
[0068] Combined with Figure 2This embodiment proposes a real-time positioning system for hazardous chemicals vehicles based on the WebSocket protocol, which includes:
[0069] The data processing module is deployed on the server side and is used to receive the original location data of hazardous chemicals vehicles from the third-party interface, and store them in the Redis cache database and the MySQL relational database after preprocessing;
[0070] The connection detection module is deployed on the server and client to establish a WebSocket connection between the client and the server and maintain heartbeat detection;
[0071] The request sending module is deployed on the client and is used to send the current location request of the hazardous chemicals vehicle to the server through WebSocket. The request carries the license plate number information of the hazardous chemicals vehicle.
[0072] The query push module is deployed on the server side, used to query the latest location information of the corresponding hazardous chemicals vehicle and push it to the client via WebSocket;
[0073] The real-time display module is deployed on the client and is used to receive the latest location information of the hazardous chemicals vehicle through WebSocket, and then display the hazardous chemicals vehicle icon at the corresponding position on the map according to the latitude and longitude coordinates of the hazardous chemicals vehicle, so as to display the location of the hazardous chemicals vehicle on the map;
[0074] A polling module is set up and deployed on the client to set a timer to implement polling. By repeatedly executing the data processing module, connection detection module and request sending module, the location of the hazardous chemicals vehicle can be displayed in real time on the map.
[0075] In this embodiment, the connection detection module involved establishes a WebSocket connection between the client and the server and maintains heartbeat detection. The specific operations performed are as follows:
[0076] After the WebSocket connection is successfully established, the client sends a heartbeat request message to the server and sets a timeout. The heartbeat request message is agreed upon in advance by both parties.
[0077] After receiving the WebSocket message, if the server detects that it is a heartbeat request message, it will push a heartbeat response message to the client. The heartbeat response message is agreed upon in advance by both parties.
[0078] If the client receives the heartbeat response message sent by the server within the timeout period, it means that the WebSocket connection is normal and the heartbeat detection is reset;
[0079] If the client does not receive the heartbeat response message sent by the server within the timeout period, it means that the WebSocket connection is abnormal. The client closes the current WebSocket connection and re-establishes a new WebSocket connection with the server.
[0080] In this embodiment, the query push module involved queries the latest location information of the corresponding hazardous chemicals vehicle and pushes it to the client through WebSocket. The specific operations performed are as follows:
[0081] The server queries the latest location information of the hazardous chemicals vehicle in the Redis cache database based on the license plate number.
[0082] If the query is successful, the latest location information of the hazardous chemicals vehicle will be pushed to the client via WebSocket.
[0083] If the query fails, the latest location information of the hazardous chemicals vehicle will be queried in the MySQL relational database based on the license plate number, and then the latest location information will be stored in the Redis cache server, and finally the latest location data of the hazardous chemicals vehicle will be pushed to the client through WebSocket.
[0084] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A real-time positioning method for hazardous chemicals vehicles based on the WebSocket protocol, characterized in that: The steps include: S1. The server receives the original location data of the hazardous chemicals vehicle from the third-party interface, and stores it in the Redis cache database and the MySQL relational database after preprocessing; S2. The client establishes a WebSocket connection with the server and maintains heartbeat detection; S3. The client sends a request for the current location of the hazardous chemicals vehicle to the server via WebSocket; S4. The server queries the latest location information of the corresponding hazardous chemicals vehicle and pushes it to the client via WebSocket; S5. The client displays the real-time location of the hazardous chemicals vehicle on the map; S6. The client sets a timer to implement polling, and by repeating steps S1 to S5, the location of the hazardous chemicals vehicle is displayed on the map in real time.
2. According to the WebSocket protocol-based real-time positioning method for hazardous chemicals vehicles according to claim 1, it is characterized in that: Execute step S2, the client establishes a WebSocket connection with the server and maintains heartbeat detection, specifically including: After the WebSocket connection is successfully established, the client sends a heartbeat request message to the server and sets a timeout. The heartbeat request message is agreed upon in advance by both parties. After receiving the WebSocket message, if the server detects that it is a heartbeat request message, it will push a heartbeat response message to the client. The heartbeat response message is agreed upon in advance by both parties. If the client receives the heartbeat response message sent by the server within the timeout period, it means that the WebSocket connection is normal and the heartbeat detection is reset; If the client does not receive the heartbeat response message sent by the server within the timeout period, it means that the WebSocket connection is abnormal. The client closes the current WebSocket connection and re-establishes a new WebSocket connection with the server.
3. According to claim 1, a method for real-time positioning of hazardous chemicals vehicles based on the WebSocket protocol is characterized in that: When executing step S3, the hazardous chemicals vehicle current location request sent carries the license plate number information of the hazardous chemicals vehicle.
4. According to claim 3, a method for real-time positioning of hazardous chemicals vehicles based on the WebSocket protocol is characterized in that: Execute step S4, the server queries the latest location information of the corresponding hazardous chemicals vehicle and pushes it to the client through WebSocket, specifically including: The server queries the latest location information of the hazardous chemicals vehicle in the Redis cache database based on the license plate number. If the query is successful, the latest location information of the hazardous chemicals vehicle will be pushed to the client via WebSocket. If the query fails, the latest location information of the hazardous chemicals vehicle will be queried in the MySQL relational database based on the license plate number, and then the latest location information will be stored in the Redis cache server, and finally the latest location data of the hazardous chemicals vehicle will be pushed to the client through WebSocket.
5. According to the WebSocket protocol-based real-time positioning method for hazardous chemicals vehicles according to claim 1, it is characterized in that: Execute step S5. After the client receives the latest location information of the hazardous chemicals vehicle through WebSocket, it displays the hazardous chemicals vehicle icon at the corresponding position on the map according to the latitude and longitude coordinates of the hazardous chemicals vehicle, so that the location of the hazardous chemicals vehicle is displayed on the map.
6. A real-time positioning system for hazardous chemicals vehicles based on the WebSocket protocol, characterized in that: It includes: The data processing module is deployed on the server side and is used to receive the original location data of hazardous chemicals vehicles from the third-party interface, and store them in the Redis cache database and the MySQL relational database after preprocessing; The connection detection module is deployed on the server and client to establish a WebSocket connection between the client and the server and maintain heartbeat detection; The request sending module is deployed on the client and is used to send the current location request of the hazardous chemicals vehicle to the server through WebSocket; The query push module is deployed on the server side, used to query the latest location information of the corresponding hazardous chemicals vehicle and push it to the client via WebSocket; The real-time display module is deployed on the client and is used to display the real-time location of hazardous chemicals vehicles on the map; A polling module is set up and deployed on the client to set a timer to implement polling. By repeatedly executing the data processing module, connection detection module and request sending module, the location of the hazardous chemicals vehicle can be displayed in real time on the map.
7. According to claim 6, a real-time positioning system for hazardous chemicals vehicles based on the WebSocket protocol is characterized in that: The connection detection module establishes a WebSocket connection between the client and the server and maintains heartbeat detection. The specific operations performed are as follows: After the WebSocket connection is successfully established, the client sends a heartbeat request message to the server and sets a timeout. The heartbeat request message is agreed upon in advance by both parties. After receiving the WebSocket message, if the server detects that it is a heartbeat request message, it will push a heartbeat response message to the client. The heartbeat response message is agreed upon in advance by both parties. If the client receives the heartbeat response message sent by the server within the timeout period, it means that the WebSocket connection is normal and the heartbeat detection is reset; If the client does not receive the heartbeat response message sent by the server within the timeout period, it means that the WebSocket connection is abnormal. The client closes the current WebSocket connection and re-establishes a new WebSocket connection with the server.
8. According to claim 6, a real-time positioning system for hazardous chemicals vehicles based on the WebSocket protocol is characterized in that: The request sending module sends a request for the current location of the hazardous chemicals vehicle to the server via WebSocket, and the request carries the license plate number information of the hazardous chemicals vehicle.
9. A real-time positioning system for hazardous chemicals vehicles based on WebSocket protocol according to claim 8, characterized in that: The query push module queries the latest location information of the corresponding hazardous chemicals vehicle and pushes it to the client through WebSocket. The specific operations performed are as follows: The server queries the latest location information of the hazardous chemicals vehicle in the Redis cache database based on the license plate number. If the query is successful, the latest location information of the hazardous chemicals vehicle will be pushed to the client via WebSocket. If the query fails, the latest location information of the hazardous chemicals vehicle will be queried in the MySQL relational database based on the license plate number, and then the latest location information will be stored in the Redis cache server, and finally the latest location data of the hazardous chemicals vehicle will be pushed to the client through WebSocket.
10. A real-time positioning system for hazardous chemicals vehicles based on WebSocket protocol according to claim 6, characterized in that: After the real-time display module receives the latest location information of the hazardous chemicals vehicle through WebSocket, it displays the hazardous chemicals vehicle icon at the corresponding position on the map according to the latitude and longitude coordinates of the hazardous chemicals vehicle, thereby displaying the location of the hazardous chemicals vehicle on the map.
