Ranch 是一个tcp处理的程序框架。官方的解释 Ranch is a socket acceptor pool for TCP protocols. 主要目的是提供一个方便,易用,高效,稳定的tcp处理基础程序。前面我也用它作为基础写了个简易的聊天的程序。cowboy底层通信处理也是ranch处理,聊聊数十个个文件做为基础的http服务器。今天我们就来看看它到底有什么魔力。废话不多,接下的几天我将分析它,说说我的学习心得。如果有什么地方说的不对还请大家指正。
源码下载地址: https://github.com/extend/ranch
使用例子:https://github.com/extend/ranch/tree/master/examples
下载shell : git clone https://github.com/extend/ranch
首先我们看一下整个目录树 整个程序总共13个文件。整个程序都是采用otp程序的方式组织的。
├── ranch_acceptor.erl
├── ranch_acceptors_sup.erl
├── ranch_app.erl
├── ranch.app.src
├── ranch_conns_sup.erl
├── ranch.erl
├── ranch_listener_sup.erl
├── ranch_protocol.erl
├── ranch_server.erl
├── ranch_ssl.erl
├── ranch_sup.erl
├── ranch_tcp.erl
└── ranch_transport.erl