Ssm-netty realization of hardware and software communication, real project case

Source: Internet
Author: User
Tags unique id

Share today is myself own work project in a module instance of the idea of implementation and process, in this process also encountered a lot of problems, can be successfully resolved is the result of team communication.

Project Simulation Background: Suppose we have a software platform, our offline products are some detector (sensor) hardware, they need to upload data to the server in a certain range of time, and the server may also need to command them (for a single), or broadcast instructions (for all), And may be in the background of the administrator ordered, or may be in the user's applet (app) and other front-end application order, so we need a two-way, concurrent, asynchronous communication module, and product volume, need to take into account the status of the connection pool, so the role of the thread is taken into account. For connected listening ports, it is best to have only one.

Well, through the above simulation scenario, we need to build the idea of the main core points to understand clearly: 1, single-port multi-Connection 2, bidirectional, concurrent, asynchronous 3, ordered, broadcast 4, data to the database write operation 5, the link instance to do security troubleshooting 6, the system self-preservation function (not everyone can link)

After finishing these points, I decided to use Netty to help us solve the problem, since the project started with the SSM's underlying framework (post-migration spring Boot), so we need to consider the simplest modular configuration, after several days of open source projects.

As for the Netty project, I am sure you can see it in the list of items in this public number, which is also the note that Uncle Mao studied when he integrated the project.

Next I go directly to the theme, because usually work for a long time (9 hours, study 2 hours) so write technology sharing, may not be all points are detailed, the problem of friends can direct the public message, Uncle Cat see will be the first time to reply to everyone.

Let's take a look at the project architecture diagram I've drawn, which is a process. Just as SSM is also a server project running in a Tomcat container, I added a new listener in Web. XML, the listener will start Netty's thread service startup class, it will run Netty's main configuration class, Bossgroup is the link instance that handles the connection, Workergroup is the link to work, and our handling of the business is placed in Tcpserverhand Ler inside, I have a unique ID for each instance of the storage, so that the service layer can get to the link instance through the ID, then order or broadcast instructions, while Tcpserverhandler also have the operation of the database write, which for different instruction header parameters.

The above is the directory of our project, which is the introduction of the package about Netty.

The protocol definition of communication is also security, this depends on the business or requirements of your project, our project adopts: Frame head +id+ instruction type + instruction content +crc16+ frame Tail server and MCU over there all with this Protocol to ensure the security of the data. Finally, I have a log of the test server and can see the instance ID of the connection as well as the broadcast test event ordered by the API.

If you have any help, please click and go.

Ssm-netty realization of hardware and software communication, real project case

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.