Start SSH and Telnet servers for hosting TUI applications over the network.
Each connecting client gets their own session. Two modes are supported:
:isolated(default) — each client runs an independent app instance with its own state. Ideal for single-user tools, games, and dashboards.:shared— all clients share the same app state. Input from any client mutates the shared state and all clients re-render. Ideal for collaborative apps, multi-player games, and shared dashboards.
SSH Example
Drafter.Server.start_ssh(ChatApp,
port: 2222,
mode: :shared,
auth: [{"alice", "pass1"}, {"bob", "pass2"}]
)Telnet Example
Drafter.Server.start_telnet(MyApp, port: 2323, mode: :isolated)Generating SSH host keys
If no system_dir: is provided, host keys are automatically generated and
cached in a temp directory. For production use, generate persistent keys:
ssh-keygen -t rsa -b 2048 -f /etc/drafter/ssh_host_rsa_key -N ""Then pass system_dir: "/etc/drafter".
Summary
Functions
Starts an SSH server hosting app_module, linked to the caller.
Starts a Telnet server hosting app_module, linked to the caller.
Stops what start_ssh/2 returned: one listener, or every listener of a list. Each
connected session ends first, its client's terminal restored and notice printed
on it (default "The server closed this session."), then its connection closes.
Returns once every session has ended, so call it from a process the sessions do
not wait on as they end.
Closes the port of what start_ssh/2 returned, so it can be listened on again at
once, leaving the sessions already connected running until stop_ssh/2.
Functions
Starts an SSH server hosting app_module, linked to the caller.
app_module is a module that does use Drafter.App. Returns {:ok, pid} for the
listener — {:ok, [pid]} when :ip is a list — or {:error, reason}; stop_ssh/1
takes either. The listener runs until it is stopped; each client that connects gets
its own session process.
Options
:port- TCP port. Default2222.:ip- what to bind: an IPv4 or IPv6 address tuple,{0, 0, 0, 0}for every IPv4 interface,{0, 0, 0, 0, 0, 0, 0, 0}for every IPv6 interface,:anyfor both families on every interface, or a list of these — say two of a machine's six addresses — each bound by a daemon of its own on the same port. Default{127, 0, 0, 1}, which accepts only local connections.:mode-:isolated(default) gives each client its own app state;:sharedruns every client against one shared state.:auth-[{username, password}]tuples for password authentication, or the atom:anonymousto accept any username and password. Default[{"admin", "admin"}].:system_dir- path to the directory holding the SSH host keys. Default: adrafter_sshdirectory under the system temp directory, with RSA host keys generated byssh-keygenon first use.:mount_props-map()handed to each session'smount/1. Default%{}. The authenticated username is added to it under:usernameas a string, so every SSH session's mount props carry that key whether or not you set it. An:authentry of the form{username, password, props}merges itspropsmap in as well, for that user only.:tunnel-boolean(), defaultfalse.trueacceptsssh -Rfrom clients: the daemon listens on the port the client names and forwards each connection to it back over the ssh connection.:register_as- withauth: {:accounts, server}, a username that, with any password, opens the registration form instead of a session; the account it makes logs in from then on. Defaultnil: nobody registers over ssh.:register_app-{module, props}, the app that form is. Default{Drafter.Accounts.RegisterApp, %{}}.:send_buffer- bytes of the operating system's send buffer for each connection. Output beyond it waits, so a session drawing faster than its connection carries skips frames instead of queueing them. Defaultnil, the system's own, which may grow to megabytes and hold seconds of frames on a slow connection.:login_timeout- milliseconds a client has from connecting to logging in, answering ssh's host key question and typing the password included; past it the connection is closed. Defaultnil,:ssh's two minutes.
Starts a Telnet server hosting app_module, linked to the caller.
app_module is a module that does use Drafter.App. Always returns {:ok, pid}
for the acceptor process, which is linked to the caller. The socket is opened
inside that process, so a port already in use surfaces as an exit from the acceptor
rather than an {:error, reason} return. Each client that connects gets its own
session process.
Telnet carries no authentication or encryption; bind it only where that is acceptable.
Options
:port- TCP port. Default2323. Bound on all interfaces.:mode-:isolated(default) gives each client its own app state;:sharedruns every client against one shared state.:mount_props-map()handed to each session'smount/1. Default%{}.
Stops what start_ssh/2 returned: one listener, or every listener of a list. Each
connected session ends first, its client's terminal restored and notice printed
on it (default "The server closed this session."), then its connection closes.
Returns once every session has ended, so call it from a process the sessions do
not wait on as they end.
Closes the port of what start_ssh/2 returned, so it can be listened on again at
once, leaving the sessions already connected running until stop_ssh/2.