Skip to Main Content
Mastering Elixir
book

Mastering Elixir

by André Albuquerque, Daniel Caixinha
July 2018
Intermediate to advanced content levelIntermediate to advanced
574 pages
14h 7m
English
Packt Publishing
Content preview from Mastering Elixir

Preparing the server

We'll now adapt our server to allow clients to connect using Phoenix Channels. Just as with traditional web applications, our journey begins in the endpoint. When Phoenix generated the endpoint module, it included the following line:

$ cat apps/elixir_drip_web/lib/elixir_drip_web/endpoint.ex defmodule ElixirDripWeb.Endpoint do  # ...   socket("/socket", ElixirDripWeb.UserSocket)   # ...end

Phoenix.Endpoint.socket/2 defines a mount point for a socket handler, which will contain channel definitions. In this case, we're saying that clients that want to connect to a channel may connect to the /socket path, which will be handled by the module we're passing as the second argument. Let's now see the code for that module:

$ cat ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Testing Elixir

Testing Elixir

Andrea Leopardi, Jeffrey Matthias

Publisher Resources

ISBN: 9781788472678Supplemental Content