ace v0.10.0 Ace.Application behaviour View Source
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
Link to this section Summary
Functions
Check if a module is an implementation of Ace.Application
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
Link to this section Types
The current state of a server.
Link to this section Functions
Check if a module is an implementation of Ace.Application
.
iex> is_implemented?(EchoServer)
true
iex> is_implemented?(IO)
false
Link to this section 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
handle_disconnect(reason, state) :: term when reason: term
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 handle_disconnect/2
callback
Every packet recieved from the client invokes this callback.
The return actions are the same as for the handle_disconnect/2
callback
No additional packets will be taken from the socket until this callback returns