# Multi-Channel

A Klaytn node can be run with **Multi-channel**.

If a node is executed with multi-channel configuration, 2 ports are set up for communication. On the otherhand, if a node is executed with single channel configuration, 1 port is set up. If 2 multi-channel nodes are trying to connect, a connection is established using 2 ports. Otherwise, they will use 1 port for communication.

A multi-channel node can be enabled through the flag `--multichannel`. If you use [`kend`](https://klaytn.gitbook.io/docs/node/endpoint-node/operation-guide/starting-stopping-en), multi-channel is enabled by default due to the statement `MULTICHANNEL=1` in [`kend.conf`](https://klaytn.gitbook.io/docs/node/endpoint-node/operation-guide/configuration). To disable multi-channel, please replace the statement with `MULTICHANNEL=0`. If you want to run a node with specific ports, flags `port` and `subport` can be used. If you want to specify ports values of a connecting peer, check out [KNI](https://klaytn.gitbook.io/docs/klaytn/design/kni).

## Architecture <a href="#architecture" id="architecture"></a>

![Multi-Channel Server](https://1632916805-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_tOQ0x4-szpVU0FZV4%2Fsync%2Ff96ec73881c10086d97d0a8867885a7b9867e3c3.png?generation=1608509647161296\&alt=media)

The picture above shows a connection between two multi-channel nodes. Two ports, mainport (A) and subport (B), transfer different messages.

* **Mainport**(A) is used to transfer messages related to blocks and consensus protocols.
  * Block messages include requests and responses of the hash, header, body and receipt of a block.
  * Consensus messages include Request, Preprepare, Prepare, Commit and RoundChange. The meaning of the messages can be found in [PBFT](https://klaytn.gitbook.io/docs/klaytn/consensus-mechanism#pbft-practical-byzantine-fault-tolerance).
* **Subport**(B) is for transferring transaction messages.

![Single Channel Server](https://1632916805-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_tOQ0x4-szpVU0FZV4%2Fsync%2Feddbc65e760c775448ba537fe9e290abe33b63a0.png?generation=1608509647263616\&alt=media)

The picture shows a connection between two single channel nodes or between a single channel node and a multi-channel node. In this case, all messages related to blocks, transactions, and consensus protocols are transported via the same port.

## Ports <a href="#multichannel-port" id="multichannel-port"></a>

To set port numbers in KNI, please refer to [the KNI scheme](https://klaytn.gitbook.io/docs/klaytn/design/kni).

* Single Channel : A single channel node uses one port (default is 32323).
* Multi-Channel: A multi-channel node uses two ports. The ports can be specified in `port` and `subport`. In Klaytn, the default values of `port` and `subport` are 32323 and 32324, respectively.
  * You might not set `subport` when connecting to multi-channel node. In this case, at first, a Klaytn node tries to connect using a single-channel. In handshake process, the actual peer's port numbers are revealed. If the peer is a multi-channel node, the ongoing connection will be canceled and a reconnection will be made with the updated ports.
