class TcpListener

Overview


TCP_LISTENER is a production ready example of a crystal TCPSocket listener with a pool of 200 fibers ready to process incoming data

There are numerous caveats and tweaks you can do to optimize for your situation, where this example tries to meet a 'happy medium' between short lived TCP connections and large data bursts over a TCP socket.

This example DOES NOT try to be a long-lived TCP connection for websocket-like behavior. The assumption for this is many short-lived or high data connections.


Defined in:

tcp_engine/tcp_listener.cr

Constant Summary

TOTAL_FIBERS = 200

Constructors

Instance Method Summary

Constructor Detail

def self.new(host : String, port : Int32, debug : Bool) #

[View source]

Instance Method Detail

def build_channel #

[View source]
def get_socket_data(socket : TCPSocket, &) #

[View source]
def listen #

[View source]
def reader(socket : TCPSocket) #

[View source]
def set_trap #

Convenience method to turn on DEBUG with a USR1 signal


[View source]
def spawn_listener(socket_channel : Channel) #

[View source]
def stats_response(socket : TCPSocket) #

[View source]