Pomelo chat room

Source: Internet
Author: User

The chatting room is the most typical example of a server verification. The pomelo operating architecture:

In this architecture, the front-end server, or connector, is responsible for the connection, while the backend Chat Server is responsible for processing the specific logic. The expanded operating architecture has the following advantages:

  • Load separation: This architecture completely separates the logic of the bearer connection from the business processing logic of the backend, which is necessary, especially for broadcast-intensive applications (such as games and chats ). Intensive broadcast and network communication occupy a large amount of resources. After separation, the processing capability of business logic is no longer affected by broadcast.

  • Easy to switch: with the front-end and back-end architecture, you can switch the channel or room without re-connecting the front-end websocket.

  • Good scalability: expansion of the number of users can be supported by increasing the number of connector processes. Channel extensions can be load balanced to multiple chat servers by hash partitioning and other algorithms. Theoretically, this architecture can achieve unlimited expansion of channels and users.

Actively triggered by the client

1. 'gate. Handler handler. queryentry ': the client queries a ctor server from the gate server, and the gate replies a connector address and port number to it.

2. 'ctor ctor. entryhandler. enter': Requests the connector process. The corresponding uid information needs to be bound upon first entry.

3. 'chat. chathandler. Send': the user initiates a chat.

Client passive triggering

Pomelo. On ('onadd', function (data ){
// Triggered by... enter
});

Pomelo. On ('onleave ', function (data ){
// Triggered by... Leave
});

Pomelo. On ('onchat', function (data ){
// Triggered by... send
});

Server Handler

Handler. queryentry = function (MSG, session, next ){
//... Corresponds to 'gate. handler. queryentry'
};

Handler. Enter = function (MSG, session, next ){
//... Corresponds to 'ctor ctor. entryhandler. enter', and binds the closed function onuserleave of the session.
};

Handler. Send = function (MSG, session, next ){
//... Corresponds to 'chat. chathandler. Send'
};

VaR onuserleave = function (app, session ){
//... The user leaves
};

Service Remote

Chatremote. Prototype. Add = function (UID, Sid, name, flag, CB ){
//... Enter Internal call
};

Chatremote. Prototype. Kick = function (UID, Sid, name ){
//... Leave Internal call
};


Chatremote. Prototype. Get = function (name, flag ){
//... Helper function, used to obtain the user list of a channel
};

Note:When implementing a specific handler, call next. The next signature is next (ERR, resp ). if no error occurs, err is null. If it is not a request but a callback y, you need to call next. In this case, the RESP parameter is not required. Generally, if there is no error, Use it directly.next(null)You can.

The server configuration information is in the config directory. Now we only pay attention to servers. JSON and master. JSON. The master. JSON configuration is the configuration information of the master server, including the address and port number, and the specific application server information configured in servers. JSON. In the configuration file, there are two environments: development and production, indicating the development environment and product environment.pomelo startYou can use-e to specify the environment to use. For more information, seepomelo start --help.

 

Pomelo chat room

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.