"Write a common server program in Java" 01 overview

Source: Internet
Author: User

In the last year or two, several TCP-based communication-type programs have been written in C + +, writing a small server, listening for requests, parsing custom protocols, processing requests, and returning results. Every time you write a new program, you take the old code, modify the Protocol Resolution section and the Business Processing section, and then a new program is born. After doing this for a few times, an idea arose: is it possible to do a generic server program that can build a new server program every time you implement very little code?

Coincidentally, when writing code in C + +, I just came across a project called the Push Framework, which can be found here:www. Pushframework. com), this is the dry, functional integrity, good performance.

Because I mainly do Java, so I have to translate it into the Java version of the idea, this process can learn two points:

1. Basic architecture of the server program

2. The Java Network section of the API

Speaking of which, I think of Netty and Mina, which provides this type of functionality, but also provides asynchronous I/O. In addition to these two well-known projects, I also found some projects in the Java World with similar features:

1. Grizzly (https://grizzly.java.net/): Isolated from the GlassFish server program, implemented with Java NIO.

2. Ioserver (https://code.google.com/p/ioserver/): People's projects, claiming to be more lightweight than Mina, focused on hand-tour aspects of the server.

3. Quick Server (http://www.quickserver.org/): Based on TCP, it is also only necessary to focus on protocol and processing logic.

See a lot of similar projects, what force lattice are not, it is purely basic learning it. Here's your address for this project: Java Push Framework (https://github.com/wanly3643/Java-Push-Framework/). Now a running version has been submitted, interested friends can take a look, the document is grasping the writing.

After translating to Java version, a simple architecture diagram of a server program is drawn according to your own understanding:

The first line represents the processing logic when the new client arrives, and the 23rd line represents the processing logic when a new request arrives.

A server should provide a monitoring service that provides a listening service port to get the running state of the server. Because the processing of the monitoring request is similar to that of the normal client, it can be handled with the normal client.

In addition to the server, also need to include broadcast functions, which requires a broadcast management module, broadcast Message Queuing and broadcast message sending module.

In fact, to do this generic server framework is only the first step, but also to implement the HTTP protocol itself, and then implement the Servlet container, so that a small tomcat can come out.

This is a line, and a line is a study of the performance of the server program.

The beginning is written so much, followed by modules to analyze, write some ideas and implementation of the code encountered problems.

"Write a common server program in Java" 01 overview

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.