ace v0.5.2 Ace.TCP.Server
Each Ace.TCP.Server
manages a single TCP connection.
They are responsible for managing communication between a TCP client and the larger application.
The server process accepts as well as manages the connection. There is no separate acceptor process. This means that that is no need to switch the connections owning process. Several erlang servers do use separate acceptor pools.
Example
The TCP.Server abstracts the common code required to manage a TCP connection. Developers only need to their own Server module to define app specific behaviour.
defmodule CounterServer do
def init(_, num) do
{:nosend, num}
end
def handle_packet(_, last) do
count = last + 1
{:send, "#{count}
", count}
end
def handle_info(_, last) do
{:nosend, last}
end
end
Summary
Functions
Take provisioned server to accept the next connection on a socket
Start a new Ace.TCP.Server
linked to the calling process
Functions
Take provisioned server to accept the next connection on a socket.
Accept can only be called once for each server. After a connection has been closed the server will terminate.
Start a new Ace.TCP.Server
linked to the calling process.
A server process is started with an app to describe handling connections.
The app is a comination of behaviour and state app = {module, config}
The server process is returned immediatly. This is allow a supervisor to start several servers without waiting for connections.
A provisioned server will remain in an awaiting state untill accept is called.