Disclosure of Invention
In order to overcome the defects of the prior art, the invention aims to provide a Netty-based ETC bidirectional encryption communication system and method, which develop the characteristics of disconnection reconnection, multi-machine deployment and bidirectional encryption communication on the basis of a Netty network framework, so that a server only needs to be used as a management center to be mainly responsible for communication with each client, maintain a network list of the client, record payment information such as order numbers, license plate numbers and the like, register the network information and report the payment information of the ETC from the client to the server, simplify the ETC payment information into a payment channel and improve the access efficiency to a great extent.
In order to achieve the above object, the present invention provides a Netty-based ETC bidirectional encrypted communication system, which is based on a Netty network framework, and comprises:
the server side is deployed in a cluster mode and serves as a unified registration center of the client sides, the connection information of all the client sides is automatically managed and maintained, the legality of the client sides is verified, payment requests are received and issued to the client sides, and the payment information of all the client sides is collected;
the client side is communicated with the ETC antenna controller and the server side and keeps long connection, operates the action of the ETC antenna controller after receiving the fee deduction request from the server side, completes the functions of starting transaction, reading electronic tags, deducting fees, closing transaction and reporting transaction, and automatically reconnects the ETC antenna controller and the server side after disconnection;
the connection information cache is used for storing the mapping relation between the ip of the server and the client;
the ETC antenna controller is used for controlling the operation of the corresponding ETC antenna according to the lane transaction control instruction of the client;
and the ETC antenna is used for scanning the electronic tag information under the control of the ETC antenna controller and returning the read information to the ETC antenna controller.
Preferably, the server includes:
the registration processing module is used for receiving the registration request sent by the client, acquiring a public key corresponding to the registration request to verify whether the registration request is legal or not, binding the ip of the server and the information of the client together after the verification is passed, storing the bound ip and the information of the client into the connection information cache to establish a mapping relation, and returning a registration processing result to the client;
the fee deduction request module is used for issuing a fee deduction request message to a corresponding client when receiving a payment request of a local timing and charging system;
and the payment information collection module is used for receiving the reported information of the client and collecting the payment information of each client.
Preferably, when a payment request of the local time-counting charging system is received, the cluster of the server generates a payment order and obtains the connection information cache through key information to find a corresponding server node, issues a fee deduction request message to the client through the fee deduction request module, and sends a delay message corresponding to the payment order to the message queue while issuing the fee deduction request, so that the client marks the payment order as a failure order when the client does not respond to the fee deduction request within a certain time.
Preferably, the client further comprises:
the registration request sending module is used for sending a registration request to the server after establishing connection with the server, creating a registration processor to be cached to the local, blocking all operations of the client when the client registers to the server by the registration processor, and ending blocking after receiving a response of the server;
the register response processing module is used for modifying the register identifier of the register processor after receiving the register response of the server, interrupting the task of the register processor and moving the task out of the local cache;
the antenna connection module is used for connecting the antenna controller with the ETC by using Socket after the registration is successful, responding to heartbeat detection of the ETC antenna controller after the connection is successful so as to keep long connection, and caching the connection to the local;
and the fee deduction request processing module is used for receiving the fee deduction request of the server, generating a local order according to the fee deduction request, checking the legality of fee deduction request information, sending a lane transaction control instruction to the ETC antenna controller according to a check result to control to execute fee collection, processing and reporting the order state.
Preferably, the payment request at least comprises a license plate number of the vehicle needing payment, a lane and fee deduction amount information.
Preferably, after the response of the waiting server is timed out, the registration processor calls the task processing thread to send the message of the registration request again until the response of the server is received.
Preferably, if the server is disconnected from the client, a connection establishment success event is sent out after the reconnection is successful, and the registration request sending module is started to initiate the registration process again after the reconnection success event is captured by the reconnection success event listener, so as to refresh the connection cache of the server.
Preferably, the deduction request processing module further comprises:
the local order generating unit is used for generating a local order according to the fee deduction request;
the lane information checking unit is used for checking whether a lane requested by the server exists or not according to the fee deduction request when the fee deduction request is received, whether fee deduction processes exist in the current lane to be deducted or not is processed, if the lane exists and the current lane to be deducted does not have the fee deduction processes, the lane transaction control instruction generating unit is started, and if not, the order processing unit is started to mark that the current order fails, the transaction of the current ETC is closed, and the transaction is reported to the server;
the lane transaction control instruction generating unit is used for taking out the socket connection from the connection cache after the lane information of the lane information verifying unit passes the verification, setting the information of the current lane in the local cache and sending a lane transaction control instruction to the ETC antenna controller;
the license plate information checking unit is used for checking whether the license plate number in the information is consistent with the license plate number in the fee deduction request of the server side and whether the license plate number is in a blacklist or not according to the acquired information after the electronic tag information returned by the ETC antenna controller is acquired, if the checking is successful, the order processing unit is correctly responded to the ETC antenna controller, otherwise, the order processing unit is started to mark the order failure, the current transaction of the ETC is closed, and the current transaction of the ETC is reported to the server side;
and the order processing unit is used for receiving the fee deduction result of the ETC antenna controller, modifying the order state of the database, sending a transaction closing instruction, and reporting the order closing instruction to the service terminal, or marking the failure of the current order, closing the current transaction of the ETC and reporting the transaction to the service terminal when the verification fails.
Preferably, after the client reports the order successfully, the order is deleted from the local database, after the reporting fails, the process is ended, and then the order is submitted to a timing task component inside the client at regular intervals until the reporting is successful.
In order to achieve the above object, the present invention further provides a Netty-based ETC bidirectional encrypted communication method, including the following steps:
step S1, after the client establishes connection with the server, the client sends a registration request to the server through the connection, the server obtains a public key corresponding to the registration request to verify whether the registration request is legal, and returns a registration processing result to the client to complete the registration of the client;
step S2, after the registration is successful, the client is connected with the ETC antenna controller by using Socket, and after the connection is successful, the client responds to the heartbeat detection of the ETC antenna controller to keep long connection and simultaneously caches the connection to the local;
and step S3, when the server receives the payment request of the local timing charging system, the server issues a fee deduction request message to the corresponding client, the client generates a local order according to the fee deduction request, checks the legality of the fee deduction request message, sends a lane transaction control instruction to the ETC antenna controller according to the check result to control and execute charging, processes and reports the order state.
Compared with the prior art, the invention discloses a Netty-based ETC bidirectional encryption communication system and method, which develop the characteristics of disconnection reconnection, multi-machine deployment and bidirectional encryption communication on the basis of a Netty network framework, so that a server only needs to be used as a management center to mainly communicate with each client, maintain a network list of the client, record payment information such as order numbers, license plate numbers and the like, register the network information and report the payment information of ETC to the server by the client, simplify the system into a payment channel and improve the access efficiency to a great extent.
Detailed Description
Other advantages and capabilities of the present invention will be readily apparent to those skilled in the art from the present disclosure by describing the embodiments of the present invention with specific embodiments thereof in conjunction with the accompanying drawings. The invention is capable of other and different embodiments and its several details are capable of modification in various other respects, all without departing from the spirit and scope of the present invention.
Fig. 1 is a system architecture diagram of the ETC bidirectional encrypted communication system based on Netty according to the present invention. As shown in fig. 1, the ETC bidirectional encryption communication system based on Netty of the present invention is based on a Netty network framework, and comprises:
the server 10, as a unified registration center of the clients, automatically manages and maintains connection information of the clients, verifies the validity of the clients, receives payment requests and issues the payment requests to the clients, and collects payment information of the clients. In the specific embodiment of the invention, the server can be deployed in a cluster, the connection between the client and the server only falls on one server, and the corresponding server is found for calling when the local timing charging system issues the payment request.
Specifically, the server 10 includes:
the registration processing module 101 is configured to receive a registration request sent by a client, obtain a public key corresponding to the registration request to verify whether the registration request is legal, bind the ip of the server and the information of the client together after the verification is passed, store the bound ip and the information of the client in the connection information cache 30 to establish a mapping relationship, and return a registration processing result to the client 20.
Specifically, the client 20 starts to establish a connection with the server 10, and when the connection is successfully established, the client sends a registration request to the server 10 through the connection, the data is transmitted by using an AES encryption method, after receiving the registration request, the server 10 obtains a public key corresponding to the registration request, then verifies whether the registration request is legal, binds the ip of the server and the information of the client together after verification, stores the bound ip and the information of the client in the connection information cache 30 to establish a mapping relationship, and replies that the client 20 indicates that the server 10 has received the registration information.
The deduction request module 102 is configured to issue a message of a deduction request to the corresponding client 20 when receiving a payment request of the local time-counting charging system.
That is to say, when needing to pay, the local timing and charging system sends a payment request to the server cluster, where the payment request at least includes the license plate number of the vehicle needing to pay, the lane, the key information of the client, the fee deduction amount information, and the like, the server cluster generates a "payment order" and obtains the connection information cache through the key information to confirm which server node needs to be used for communication, the server node and the client 20 are in a one-to-one relationship, and the corresponding server node is found, that is, the fee deduction request message can be sent to the client 20 through the fee deduction request module 102. Preferably, the deduction request module 102 sends a delay message corresponding to the payment order to the message queue while issuing the deduction request, and the purpose of the delay message is to mark that the payment order is failed if the client does not respond to the deduction request within a certain time.
And the payment information collection module 103 is configured to receive the report information of the clients and collect payment information of each client.
The client 20 is in communication with the ETC antenna controller 30 and the server 10 and keeps long connection, and after receiving the fee deduction request from the server, the client 20 operates the ETC antenna controller to complete the functions of starting transaction, reading electronic tags, deducting fees, closing transaction and reporting transaction, and automatically reconnects the ETC antenna controller 30 and the server 10 after disconnection.
Specifically, as shown in fig. 2, the client 20 further includes:
a registration request sending module 201, configured to send a registration request to the server 10 after establishing a connection with the server 10, and create a new registration processor to be cached locally, where the registration processor is configured to block all operations of the client when the client registers with the server.
Specifically, the client 20 starts to establish a connection with the server 10, and immediately sends a registration request message to the server 10 through the connection after the connection is successfully established, the data is transmitted by using an AES encryption method, and at the same time, a new registration processor is created and cached locally, the registration processor is used for blocking all operations of the client when the client registers with the server, and ends the blocking after receiving a response from the server 10, and calls a task processing thread to send the registration request message again after waiting for the response timeout from the server until the server receives a response.
That is, when the client 20 registers with the server 10, the registration processor blocks all operations of the client, including establishing connection with the ETC antenna and reporting deduction result operations, which are meaningless actions before establishing connection with the server.
Preferably, because the Netty network framework is provided with a reconnection mechanism of a server and a client, the invention adds a connection establishment success event on the original basis. If the server is disconnected from the client and a connection establishment success event is sent after the reconnection is successful, the registration request sending module 201 is started to initiate a registration process again after the reconnection success event is captured by the reconnection success event listener, so as to refresh the connection cache of the server 10. That is, the invention expands the Netty network framework, and adds an event of successful connection establishment in the self-contained reconnection action of Netty, and the client 20 is responsible for monitoring the event, and the client 20 performs the registration process with the server again after monitoring the event.
Since the first connection and the reconnection cannot be distinguished, the registration success flag registered after the first registration is successful is set to true, because the first registration is performed manually, and the subsequent registrations are triggered by the connection establishment success event listener, so that the successful situation of the first connection needs to be ignored. In the present invention, connection establishment between the client and the server and registration are two actions, where connection establishment is a precondition for bidirectional communication between the server 10 and the client 20, and registration is to find a server node corresponding to the client 20 in a server cluster, because the server and the client 20 correspond to each other one to one. In the specific embodiment of the present invention, the registration processor operates in 2 cases: the first is when the client 20 is started for the first time, the subsequent operation of the client will be blocked under this condition, if the registration response of the server is not received within the specified time, the client will continuously retry until the registration is successful, and the subsequent operation of the client 20 will not be released after the registration is successful; the second is when the client 20 disconnects from the server, which may be done in the presence of interaction between the client 20 and the ETC antenna, and attempts to re-register asynchronously without interrupting this operation. Since a connection establishment success event is triggered when the client 20 establishes a connection with the server 10, and the reconnection success event listener cannot recognize whether it is the first time to start or disconnect reconnection, it is necessary to set the registration success flag to true to distinguish which case the registration processor is to operate. That is, since the Netty network framework provides a function for successfully establishing a connection, based on which a function for sending an event can be added, but when the connection is successfully established, it is impossible to distinguish whether the establishment of the connection is started for the first time or the reconnection is successful in the extended function, and therefore, a registration success flag needs to be set to distinguish which situation the registration processor needs to work according to.
And the registration response processing module 202 is configured to, after receiving the response from the server 10, modify the registration identifier of the registration processor to true, and then interrupt and remove the task of the registration processor from the local cache, that is, destroy the registration processor. In the present invention, the blocking logic of the registration processor is: and circularly judging whether the registration success identifier is true or not, blocking for a period of time when the registration success identifier is not true, and judging again and blocking again after the period of time is exceeded until the registration success identifier is true. When the server 10 responds to the client 20, the registration response processing module 202 of the client 20 immediately modifies the registration success identifier of the registration processor to true, and at this time, the registration processor immediately stops blocking when monitoring that the registration success identifier is true, and then the registration response processing module 202 of the client 20 destroys the registration processor and runs the work after the blocking is finished.
And the antenna connection module 203 is used for connecting with the ETC antenna controller 30 by using Socket after the registration is successful, responding to heartbeat detection of ETC antenna controller hardware after the connection is successful so as to keep long connection, and caching the connection to the local.
The fee deduction request processing module 204 is configured to receive a fee deduction request from the service end 10, generate a local order according to the fee deduction request, check validity of fee deduction request information, send a lane transaction control instruction to the ETC antenna controller according to a check result to control execution of charging, process and report an order state. In the embodiment of the present invention, the verification of the validity of the fee deduction request message includes, but is not limited to, verifying whether the request is from a unique identifier authorized by the service end, verifying whether the lane to be paid is existed, and verifying that the lane to be paid is not currently processed in the fee deduction process.
Specifically, the deduction request processing module 204 further includes:
and the local order generating unit is used for generating a local order according to the fee deduction request. In the present invention, a local order is generated whether the deduction request information passes or fails, and the success or failure is determined by the status of the order, and is reported to the server 10.
And the lane information checking unit is used for checking whether a lane requested by the server 10 exists according to the fee deduction request when the fee deduction request is received, processing whether a fee deduction process exists in the current lane to be deducted, starting the lane transaction control instruction generating unit if the lane exists and the fee deduction process does not exist in the current lane to be deducted, and starting the order processing unit to mark that the current order fails, closing the transaction of the current ETC and reporting the current order to the server 10 if the lane exists and the fee deduction process does not exist in the current lane to be deducted.
And the lane transaction control instruction generating unit is used for taking out the socket connection from the connection cache after the lane information verification of the lane information verifying unit passes (namely the lane exists and no fee deduction process exists in the current lane to be deducted), setting the information of the current lane in the local cache and sending a lane transaction control instruction to the ETC antenna controller 30.
And the license plate information checking unit is used for checking whether the license plate number in the information is consistent with the license plate number in the fee deduction request of the server 10 and whether the license plate number is in a blacklist or not according to the acquired information after the electronic tag information returned by the ETC antenna controller is acquired, correctly responding to the ETC antenna controller 30 if the checking is successful, and starting the order processing unit to mark the order failure if the checking is failed, closing the current transaction of the ETC and reporting the order failure to the server 10. In the present invention, the license plate verification is a process between the client 20 and the ETC antenna controller, and the client 20 can check whether the requested license plate is consistent with the charged license plate after the ETC antenna reads the license plate.
And the order processing unit is used for receiving the fee deduction result of the ETC antenna controller, modifying the order state of the database, sending a transaction closing instruction, and reporting the order closing instruction to the service terminal 10, or marking the current order failure when the verification fails, closing the current transaction of the ETC and reporting the current transaction to the service terminal 10. Preferably, after the client 20 reports the order successfully, the order is deleted from the local database, after the reporting fails, the process is ended, and then the order is reported to the timing task component in the client at regular intervals until the reporting is successful.
And the connection information cache 30 is used for storing the mapping relationship between the ip of the server 10 and the client 20, which is stored by the server 10. In the invention, the server can be deployed in a cluster, the connection between the client and the server can only fall on one server, and the corresponding server is found for calling when a payment request is issued, and the cache of the redis server is mainly used.
And the ETC antenna controllers 40 are used for controlling the operation of the ETC antennas according to lane transaction control instructions of the client 20, and each controller can be connected with at most 4 ETC antennas to represent 4 lanes.
Specifically, after receiving the lane transaction control instruction of the client 20, the ETC antenna controller 40 opens the ETC antenna of the corresponding lane according to the lane transaction control instruction, reads the electronic tag information and returns the electronic tag information to the client 20, the client 20 checks whether the read license plate number is consistent with the license plate number from the fee deduction request of the server 10d and whether the license plate number is in the blacklist, if the check fails, the order is marked to fail, the transaction of the ETC is closed, if the check succeeds, the ETC antenna controller 40 correctly responds to the ETC antenna controller 40, the ETC antenna controller 40 executes fee deduction, and returns the fee deduction result to the client 20.
And an ETC antenna 50 for scanning electronic tag (OBU) information under the control of the ETC antenna controller 40 and returning the read information to the ETC antenna controller 40.
Fig. 3 is a flowchart illustrating steps of an ETC bidirectional encrypted communication method based on Netty according to the present invention. As shown in fig. 3, the ETC bidirectional encrypted communication method based on Netty of the present invention includes the following steps:
step S1, after the client establishes connection with the server, the client sends a registration request to the server through the connection, and the server obtains the public key corresponding to the registration request to verify whether the registration request is legal, and returns the registration processing result to the client to complete registration of the client.
Specifically, step S1 further includes:
step S100, after establishing connection with the server, sending a registration request to the server, and creating a registration processor to be cached to the local, wherein the registration processor blocks all operations of the client when the client registers to the server.
Specifically, a client starts to establish connection with a server, a registration request message is sent to the server through the connection immediately after the connection is successfully established, data is transmitted by using an AES encryption mode, a registration processor is newly built to be cached locally, when the client registers with the server, the registration processor blocks all operations of the client, including establishing connection with an ETC antenna and reporting deduction result operations, and the operations are meaningless actions before the connection is established with the server.
Step S101, the server receives a registration request sent by the client, acquires a public key corresponding to the registration request to verify whether the registration request is legal, binds the ip of the server and the information of the client together after the verification is passed, stores the bound ip and the information of the client into a connection information cache to establish a mapping relation, and returns a registration processing result to the client.
And step S102, when the client receives the response of the server, the registration identifier of the registration processor is changed into true, and then the task of the registration processor is interrupted and moved out of the local cache, namely the registration processor is destroyed.
In the present invention, the blocking logic of the registration processor is: and circularly judging whether the registration success identifier is true or not, blocking for a period of time when the registration success identifier is not true, and judging again and blocking again after the period of time is exceeded until the registration success identifier is true. When the server side responds to the client side, the client side immediately modifies the registration success identification of the registration processor into true, the registration processor immediately stops blocking when monitoring that the registration success identification is true, and then the client side destroys the registration processor and simultaneously runs the work after the blocking is finished.
Preferably, before step S102, the method further includes the following steps:
after the response of the waiting server is overtime, the register processor calls the task processing thread to send the message of the register request to the server again until the response of the server is received.
Preferably, step S1 further includes the steps of:
if the server is disconnected from the client and the reconnection is successful, the client sends a connection establishment success event, and returns to the step S100 to initiate the registration process again after being captured by the reconnection success event listener, so as to refresh the connection cache of the server. Specifically, because the Netty network framework is provided with a reconnection mechanism of a server and a client, a connection establishment success event is added on the original basis, namely after reconnection succeeds, the client sends out the connection establishment success event, and after the reconnection success event is captured by an event monitor, a registration process is initiated again to refresh a connection cache of the server.
Since the first connection and the reconnection cannot be distinguished, the registration success flag registered after the first registration is successful is set to true, because the first registration is performed manually, and the subsequent registrations are triggered by the connection establishment success event listener, so that the successful situation of the first connection needs to be ignored.
And step S2, after the registration is successful, the client is connected with the ETC antenna controller by using Socket, and after the connection is successful, the client responds to the heartbeat detection of the ETC hardware to keep long connection and caches the connection to the local.
And step S3, when the server side receives the payment request, the server side sends a fee deduction request message to the corresponding client side, the client side generates a local order according to the fee deduction request, verifies the legality of the fee deduction request message, and sends a lane transaction control command to the ETC antenna controller according to the verification result to control and execute the fee collection. In the embodiment of the present invention, the verification of the validity of the fee deduction request message includes, but is not limited to, verifying whether the request is from a unique identifier authorized by the service end, verifying whether the lane to be paid is existed, and verifying that the lane to be paid is not currently processed in the fee deduction process.
Specifically, step S3 further includes:
step S300, when receiving the payment request of the local timing charging system, the server side issues a message of the fee deduction request to the corresponding client side. That is to say, when needing to pay, the local time-counting charging system sends a payment request to the server cluster, the payment request at least includes the number of the vehicle license plate, the lane, the information of the fee deduction amount, etc. when receiving the payment request of the local time-counting charging system, the server cluster generates a 'payment order' and obtains the connection information cache through the key information, confirms which server node needs to be used for communication, the server node and the client 20 are in a one-to-one relationship, finds the corresponding server node, and then sends the information of the fee deduction request to the corresponding client. Preferably, the server sends a delay message corresponding to the payment order to the message queue while issuing the deduction request. The purpose of this delay message is to mark that the payment order is failed if the client has not responded to the debit request within a certain time.
Step S301, generating a local order according to the fee deduction request, checking whether the lane requested by the server exists according to the fee deduction request, and processing whether the lane to be deducted fee currently exists or not by the fee deduction process. In the present invention, a local order is generated whether the deduction request information passes or fails, and the success or failure is determined by the status of the order, and is reported to the server 10.
And step S302, if the lane exists and the current lane to be paid is not processed by the fee deduction process, taking out the socket connection from the connection cache, setting the information of the current lane in the local cache, sending a lane transaction control instruction to the ETC antenna controller, and otherwise, marking the failure of the current order, closing the transaction of the current ETC and reporting the transaction to the server.
And step S303, after receiving the lane transaction control instruction of the client, the ETC antenna controller opens the ETC antenna of the corresponding lane according to the lane transaction control instruction, reads the electronic tag information and returns the electronic tag information to the client.
And step S304, after the client side acquires the electronic tag information returned by the ETC antenna controller, checking whether the license plate number in the information is consistent with the license plate number in the fee deduction request of the server side and whether the license plate number is in a blacklist according to the acquired information, if the checking is successful, correctly responding to the ETC antenna controller, otherwise, starting an order processing unit to mark order failure, closing the current transaction of the ETC, and reporting the order failure to the server side. That is to say, the license plate verification is a process between the client and the ETC antenna controller, and the client can check whether the requested license plate is consistent with the paid license plate after the ETC antenna reads the license plate.
In step S305, the ETC antenna controller executes fee deduction after receiving the correct response from the client, and returns a fee deduction result to the client.
Step S306, the client modifies the order state of the database according to the received deduction result and sends a transaction closing instruction, and then the order is reported to the server.
Examples
Fig. 4 is a system architecture diagram of the ETC bidirectional encrypted communication system based on Netty in the embodiment of the present invention. In this embodiment, the system includes:
1. the server side: the method is used as a unified registration center of the client, automatically manages and maintains connection information of each client, verifies the legality of the client, receives and issues payment requests to the clients, and collects payment information of each client.
2. A client: the ETC antenna controller is communicated with the ETC antenna controller and the server, long connection is kept, the actions of the ETC antenna are operated after payment requests from services are received, the functions of opening transactions, reading electronic tags, deducting fees, closing transactions and reporting transactions are completed, and the ETC antenna and the server can be automatically reconnected after connection and disconnection.
3. Caching connection information: the server can be deployed in a cluster, the connection between the client and the server can only fall on one server, the corresponding server is found for calling when the payment request is issued, and the cache of the redis server is mainly used.
4. The ETC antenna controllers control the operation of the ETC antennas, and each controller can be connected with 4 ETC antennas at most and represents 4 lanes.
5. And the ETC antenna scans electronic tag (OBU) information, and the read information is returned to the ETC antenna controller.
Fig. 5 is a flowchart of the operation of the client in the embodiment of the present invention. In this embodiment, the starting process of the client:
1. the client starts to establish connection with the server, immediately sends a registration message to the server through the connection after the connection is successfully established, transmits data by using an AES encryption mode, and manually creates a registration processor to be cached locally.
2. The register processor blocks all operations of the client, including whether the client has registered the identifier, the task processing thread and waiting for the response time of the server, when the client registers in the server, the blocking is ended only after the server responds to the registration request of the client, otherwise, after the response time of the waiting server is overtime, the task processing thread is called to send the registered message again until the server receives the response.
The Netty network framework is provided with a reconnection mechanism of a server and a client, and a connection establishment success event is added on the original basis. If the server is disconnected with the client and a connection establishment success event is sent out after the reconnection is successful, the registration process is initiated again after the reconnection success event is captured by the reconnection success event monitor, so that the connection cache of the server side is refreshed.
Since the first connection and the reconnection cannot be distinguished, the registration success flag registered after the first registration is successful is set to true, because the registration is manually performed during the first registration, and the subsequent registration is triggered by the connection establishment success event listener, so that the successful situation of the first connection needs to be ignored.
3. After receiving the message, the server acquires a public key corresponding to the request, then verifies whether the message is legal, binds the ip of the server and the information of the client together after the verification is passed, stores the bound ip and the information of the client into a redis cache to establish a mapping relation, and replies that the client receives the registration information.
4. After receiving the response of the server, the client firstly changes the registration identifier of the registration processor into true, then interrupts the task of the registration processor and moves the task out of the local cache, then connects the local cache with the ETC antenna controller by using Socket, responds to the heartbeat detection of the ETC hardware after the connection is successful so as to keep long connection, and caches the connection to the local.
Fig. 6 is a fee deduction flow chart of the ETC in the embodiment of the invention. In this embodiment, the fee deduction process of the ETC is as follows:
1. when the server cluster receives a payment request of a local timing charging system, a 'payment order' is generated, connection information cache is obtained through key information, it is confirmed which server node needs to be used for communication, the server nodes and the client 20 are in a one-to-one relationship, a corresponding server node is found, a message of the payment request is sent to the client, a delay message corresponding to the payment order is sent to a message queue, and the message is used for marking that the order is failed if the client does not respond to the payment request within a certain time.
2. After receiving the request for deducting fee, the client checks the legality of the request information, generates a local order whether the request information passes or does not pass, determines success or failure according to the state of the order, and finally reports the order to the server.
3. The client side needs to check whether the lane requested by the server side exists or not, no fee deduction process is carried out on the lane to be deducted currently, after the check is passed, the client side fetches the socket connection from the connection cache, information of the current lane is set in the local cache, and then lane transaction control is sent to the ETC antenna controller.
4. The ETC antenna controller opens the ETC antenna to start reading the electronic tag information and return the electronic tag information to the client after receiving the transaction starting instruction, the client checks whether the read license plate number is consistent with the license plate number requested by the server and whether the license plate number is in a blacklist, if the check fails, the order is marked to fail, and the transaction of the ETC is closed; and if the verification is successful, the ETC antenna controller is correctly responded.
5. The ETC antenna controller executes fee deduction and returns to the fee deduction interface, the client receives the fee deduction result, modifies the order state of the database and sends an order closing instruction, and then the order is reported to the server.
6. After the client side reports the order successfully, the order is deleted from the local database, after the reporting fails, the process is ended, and the order is subsequently submitted to a timing task component in the client side for reporting at regular intervals until the reporting is successful.
In summary, the characteristics of disconnection reconnection, multi-machine deployment and bidirectional encrypted communication are developed on the basis of a Netty network framework, so that the server only needs to serve as a management center to be mainly responsible for communication with each client, a network list of the client is maintained, payment information such as order numbers, license plate numbers and the like is recorded, the client registers the network information and reports the payment information of the ETC to the server, the ETC is simplified into a payment channel, and the access efficiency is improved to a great extent.
The foregoing embodiments are merely illustrative of the principles and utilities of the present invention and are not intended to limit the invention. Modifications and variations can be made to the above-described embodiments by those skilled in the art without departing from the spirit and scope of the present invention. Therefore, the scope of the invention should be determined from the following claims.