Release the TCP network framework for C + + implementation Khala

Source: Internet
Author: User

1, Khala Introduction

Khala (Kara) is a TCP network framework implemented in C + +. The bottom layer adopts Muduo network library as the network io+ threading model, and encapsulates the multi-threaded network framework which separates the network implementation from the business logic, which has the functions of timeout exit, multi-device multi-event registration support, device life cycle management and communication between devices.

Project Escrow Address: Https://github.com/moyangvip/khala

2, the bottom support

The Khala bottom uses Muduo as the network IO support. Muduo is similar to some common open source Event-driven network libraries (such as libevent) in the market, implementing a non-blocking IO mechanism based on reactor mode, with the thread part using one loop per thread + thread pool model. Muduo Source: Https://github.com/chenshuo/muduo. For more information on Muduo see the book "Linux Multithreaded Server Programming" in Aboutspeaker.

3. Device Inheritance

When using the Khala framework, users do not need to be concerned with the implementation of the underlying network IO and multithreaded models, only the message response events needed to customize the business logic for the specific device. Simultaneous user-defined devices support multiple levels of inheritance. For example, you can customize a class of devices called "light equipment" and customize "switch" events for "light devices". Then you can customize a new class of devices called "smart Lights", and inherit "light equipment" and custom "light intensity Detection" events, "smart light" will not only have "light intensity Detection" response event, and "light device" can support all the response events. Through this mechanism, we can realize the multi-level succession system of different equipments well.

Khala Framework composed of multi-level device inheritance diagram, the next level of device type when registering their own message response events, will also inherit the support of the previous device type support all message response events, but also to the previous level of device type implementation of some message response events to be re-implemented.

4. Equipment Life cycle

Khala the device type that is implemented by default is divided into two categories, the temporary device type and the logon device type. The temporary device type can provide some basic generic message response events for all devices, such as querying the current device type, querying the current time of the system, and so on. Users can also register for common message response events that meet their business needs.

At the same time Khala provides a login management device type. In the Login management device type, Khala provides life cycle management of the device.

In the life cycle of the device, Khala provides the relevant interface to the user to implement different operations and to formulate related message responses at different times.

To prevent some illegal connections from establishing a connection to the server for a long time, occupying system resources, Khala supports the timeout detection exit mechanism. The user can set the maximum connection time, and a connection is forced to disconnect if a valid event message is not sent during that time period. The current timeout connection is only for temporary connection devices, and future considerations for logon connection devices also support timeout detection exit.

Finally, Khala also provides device management support, which enables users to query related connection information and login device information through related interfaces. and realize the message communication function between different devices.

5. Applicable scenarios

The network is based on TCP long connection device management, multi-device communication and so on. At the same time, for the most common chat rooms and other functions, Khala also only need to write a very small number of code to achieve.

6, about Khala

Khala originates from StarCraft and is a religion of Protoss belief in StarCraft. At the same time it is also protoss between the spirit of the network, can be connected to each Khala Protoss to provide a spiritual connection.

The Khala framework originated from my thinking about a smart home project. After learning Aboutspeaker's Muduo network library, I generated the idea of further encapsulation based on the network library, and one person spent three weeks completing the design of the open source framework and the approximate implementation of the code. In the past, there is not much experience in C + + related projects, for service-side programming has only learned from "UNP Volume One" and Aboutspeaker introduced Muduo-related "Linux multithreaded Server Programming", in the development process and no mentor, Daniel's guidance, is essentially a type of learning communication code. Design out of personal thinking and understanding, code is not good to read, there are still many bugs, the function is not perfect. Slowly learn to change slowly later.

I want to be able to publish 1-2 related learning documents each week. Also hope that the students with experience in this area can make a lot of bricks, or interested in this area to join me to learn to communicate together.

Email:[email protected]

qq:1030507918

7. Bibliography

W.richard Stevens: "UNIX Network programming Volume One"

Aboutspeaker: "Linux multi-threaded server Programming"

Release the TCP network framework for C + + implementation Khala

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.