All Projects → emqx → Esockd

emqx / Esockd

Licence: apache-2.0
Erlang General Non-blocking TCP/SSL Socket Server

Programming Languages

erlang
1774 projects

Projects that are alternatives of or similar to Esockd

Mqtt Pwn
MQTT-PWN intends to be a one-stop-shop for IoT Broker penetration-testing and security assessment operations.
Stars: ✭ 156 (-10.34%)
Mutual labels:  mqtt
Acl
Server framework and network components written by C/C++ for Linux, Mac, FreeBSD, Solaris(x86), Windows, Android, IOS
Stars: ✭ 2,113 (+1114.37%)
Mutual labels:  mqtt
Homeautio.mqtt.googlehome
Stars: ✭ 168 (-3.45%)
Mutual labels:  mqtt
Modular Psu
EEZ Bench Box 3 (BB3) Modular T&M chassis
Stars: ✭ 159 (-8.62%)
Mutual labels:  mqtt
Simpletcp
A minimal non-blocking TCP server written for Python 3.
Stars: ✭ 162 (-6.9%)
Mutual labels:  tcp-server
Zm1
斐讯M1空气检测仪个人固件公开项目. 此项目为公开release+讨论
Stars: ✭ 165 (-5.17%)
Mutual labels:  mqtt
Win10as
Make your windows 10 computer IOT friendly
Stars: ✭ 153 (-12.07%)
Mutual labels:  mqtt
Rabbitmq Mqtt
RabbitMQ MQTT plugin
Stars: ✭ 169 (-2.87%)
Mutual labels:  mqtt
Mqtt Sn Tools
Command line tools written in C for the MQTT-SN (MQTT for Sensor Networks) protocol
Stars: ✭ 162 (-6.9%)
Mutual labels:  mqtt
Emqx Rel
The Release Project for EMQ X Broker
Stars: ✭ 166 (-4.6%)
Mutual labels:  mqtt
Eomaia
一个基于reactor模式的Linux/C++网络库,支持one loop per thread机制。
Stars: ✭ 159 (-8.62%)
Mutual labels:  tcp-server
Designiot
教你设计物联网系统。构建自己的Internet of Things 。
Stars: ✭ 1,983 (+1039.66%)
Mutual labels:  mqtt
Amstomqttbridge
Minimalistic system to read AMS/HAN data from electrical meter
Stars: ✭ 165 (-5.17%)
Mutual labels:  mqtt
Ngx Mqtt
This library isn't just a wrapper around MQTT.js for angular. It uses observables and takes care of subscription handling and message routing.
Stars: ✭ 157 (-9.77%)
Mutual labels:  mqtt
Espmqttclient
Wifi and MQTT handling for ESP8266 and ESP32
Stars: ✭ 169 (-2.87%)
Mutual labels:  mqtt
Temper Esp8266
Temper is a compact temperature sensor based on ESP8266 and SHT30 with large 13x7 pixel led display.
Stars: ✭ 155 (-10.92%)
Mutual labels:  mqtt
Simplenet
An easy-to-use, event-driven, asynchronous network application framework compiled with Java 11.
Stars: ✭ 164 (-5.75%)
Mutual labels:  tcp-server
Broadlink Mqtt
MQTT client to control BroadLink devices
Stars: ✭ 169 (-2.87%)
Mutual labels:  mqtt
Mqttnet
MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
Stars: ✭ 2,486 (+1328.74%)
Mutual labels:  mqtt
Esp32 Mqtt
ESP32 MQTT sample project for
Stars: ✭ 166 (-4.6%)
Mutual labels:  mqtt

esockd Build Status

Erlang General Non-blocking TCP/SSL Socket Server.

Features

  • General Non-blocking TCP/SSL Socket Server
  • Acceptor Pool and Asynchronous TCP Accept
  • UDP/DTLS Server
  • Max connections management
  • Allow/Deny by peer address
  • Proxy Protocol V1/V2
  • Keepalive Support
  • Rate Limit
  • IPv6 Support

Usage

A Simple TCP Echo Server:

-module(echo_server).

-export([start_link/2, init/2]).

start_link(Transport, Sock) ->
    {ok, spawn_link(?MODULE, init, [Transport, Sock])}.

init(Transport, Sock) ->
    case Transport:wait(Sock) of
        {ok, NewSock} ->
            loop(Transport, NewSock);
        Error -> Error
    end.

loop(Transport, Sock) ->
    case Transport:recv(Sock, 0) of
        {ok, Data} ->
            {ok, Peername} = Transport:peername(Sock),
            Transport:send(Sock, Data),
            loop(Transport, Sock);
        {error, Reason} ->
            io:format("TCP Error: ~s~n", [Reason]),
            {stop, Reason}
    end.

Setup Echo Server:

%% Start esockd application
ok = esockd:start().
Options = [{acceptors, 10}, {max_connections, 1024}, {tcp_options, [binary, {reuseaddr, true}]}].
MFArgs = {echo_server, start_link, []},
esockd:open(echo, 5000, Options, MFArgs).

Examples

Example Description
examples/async_recv prim_net async recv/send
examples/gen_server gen_server behaviour
examples/simple simple echo server
examples/ssl ssl echo server
examples/proxy_protocol proxy protocol v1/2
examples/udp udp echo server
examples/dtls dtls echo server

API

Open a listener

esockd:open(echo, 5000, [{tcp_options, [binary, {reuseaddr, true}]}],
            {echo_server, start_link, []}).

esockd:open(echo, {"127.0.0.1", 6000}, [{tcp_options, [binary, {reuseaddr, true}]}],
            {echo_server, start_link, []}).

Spec:

-spec(open(Protocol, ListenOn, Options, MFArgs) -> {ok, pid()} | {error, term()} when
           Protocol :: atom(),
           ListenOn :: inet:port_number() | {host(), inet:port_number()}),
           Options  :: [option()],
           MFArgs   :: esockd:mfargs()).

Option:

-type(option() :: {acceptors, pos_integer()}
                | {max_connections, pos_integer()}
                | {max_conn_rate, pos_integer()}
                | {access_rules, [esockd_access:rule()]}
                | {shutdown, brutal_kill | infinity | pos_integer()}
                | tune_buffer | {tune_buffer, boolean()}
                | proxy_protocol | {proxy_protocol, boolean()}
                | {proxy_protocol_timeout, timeout()}
                | {ssl_options, [ssl:ssl_option()]}
                | {udp_options, [gen_udp:option()]}
                | {dtls_options, [gen_udp:option() | ssl:ssl_option()]}).

MFArgs:

-type(mfargs() :: atom() | {atom(), atom()} | {module(), atom(), [term()]}).

Get Setting and Stats

Get stats:

esockd:get_stats({echo, 5000}).

Get acceptors:

esockd:get_acceptors({echo, {"127.0.0.1", 6000}}).

Get/Set max connections:

esockd:get_max_connections({echo, 5000}).
esockd:set_max_connections({echo, 5000}, 100000).

Allow/Deny

Same to Allow/Deny Syntax of nginx:

allow address | CIDR | all;

deny address | CIDR | all;

allow/deny by options:

esockd:open(echo, 5000, [{access, [{deny, "192.168.1.1"}, {allow, "192.168.1.0/24"}, {deny, all}]}], MFArgs).

allow/deny by API:

esockd:allow({echo, 5000}, all).
esockd:allow({echo, 5000}, "192.168.0.1/24").
esockd:deny({echo, 5000}, all).
esockd:deny({echo, 5000}, "10.10.0.0/16").

Close a listener

esockd:close(echo, 5000).
esockd:close(echo, {"127.0.0.1", 6000}).

Spec:

-spec(close(Protocol, ListenOn) -> ok when Protocol :: atom(), ListenOn :: inet:port_number() | {host(), inet:port_number()}).

SSL

Connecting to ssl_echo_server:

openssl s_client -connect 127.0.0.1:5000 -ssl3

openssl s_client -connect 127.0.0.1:5000 -tls1

Design

Supervisor Tree

esockd_sup
    -> esockd_listener_sup
        -> esockd_listener
        -> esockd_acceptor_sup
            -> esockd_acceptor
            -> esockd_acceptor
            -> ......
        -> esockd_connection_sup
            -> esockd_connection
            -> esockd_connection
            -> ......

Acceptor

  1. Acceptor Pool

  2. Suspend for one second when e{n, m}file errors happened

Connection Sup

  1. Create a connection, and let it run...

  2. Control maximum connections

  3. Count active connections

  4. Count shutdown reasons

CIDR

CIDR Wiki: https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing

Benchmark

Benchmark 2.1.0-alpha release on one 8 cores, 32G memory ubuntu/14.04 server::

250K concurrent connections, 50K messages/sec, 40Mbps In/Out consumed 5G memory, 20% CPU/core

License

Apache License Version 2.0

Author

EMQ X Team.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].