ace v0.8.0 Ace.Application behaviour
Behaviour module for implementing a server to handle tcp/tls connections.
See Ace.Server to start a server with an application
Example
defmodule CounterServer do
use Ace.Application
def handle_connect(_, 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
Callbacks
Invoked when a new client connects to the server
Invoked when connection to the client is lost, or client disconnects
Every message recieved by the server, that was not sent from the client, invokes this callback
Every packet recieved from the client invokes this callback
Types
Callbacks
Invoked when a new client connects to the server.
The state is the second element in the app tuple that was used to start the endpoint.
Returning {:nosend, state} will setup a new server with internal state.
The state is perserved in the process loop and passed as the second option to subsequent callbacks.
Returning {:nosend, state, timeout} is the same as {:send, state}.
In addition handle_info(:timeout, state) will be called after timeout milliseconds, if no messages are received in that interval.
Returning {:send, message, state} or {:send, message, state, timeout} is similar to their :nosend counterparts,
except the message is sent as the first communication to the client.
Returning {:close, state} will shutdown the server without any messages being sent or recieved
Invoked when connection to the client is lost, or client disconnects.
Note a server will not always call handle_disconnect on exiting.
Every message recieved by the server, that was not sent from the client, invokes this callback.
The return actions are the same as for the init/2 callback