Skip to content
This repository was archived by the owner on Sep 25, 2023. It is now read-only.

Pomelo 0.4 new features

py edited this page Jul 19, 2013 · 5 revisions

New features in Pomelo 0.4

Pomelo 0.4 makes structural changes to support friendly custom communication protocol, and provides custom data transmission strategy for different situations.

Custom protocol

Implementation of server side

Pomelo 0.4 makes a more detailed protocol division to support more flexible custom feature. The main structure is as follow chart:

![pomelo-transport](http://pomelo.netease.com/resource/documentImage/pomelo-transport.png)

We add the protocol layer to encode/decode data packages between the upper layer and under layer. Protocol layer is mainly in charge of encoding and decoding transmission data for upper layer, and is associated with specific connector. Hybridconnector is responsible for dealing with Message layer data, and sioconnector is responsible for dealing with data from socket.io layer.

Encoding and decoding algorithm in protocol layer can be custom made by passing it to connector, example code is as follow:

var encode = function(reqId, route, msg) {
  // do some customized encode with reqId, route and msg
  return result;	// return encode result
};

var decode = function(msg) {
  // do some customized decode with msg
  return result;	// return decode result
};

app.configure('production|development', 'connector', function(){
  app.set('connectorConfig', {
    connector : pomelo.connectors.hybridconnector,
    encode: encode,
    decode: decode
  });
});

When data comes to connector, the corresponding encode and decode methods will be invoked.

  • encode(reqId, route, msg) - means encoding reqId, route and msg.

Clone this wiki locally