Logan
Basic Websocket Chat Example Using the Cowboy Server w/o Phoenix
Here is an example of a Mix application that utilizes Cowboy to handle websocket connections. If anyone has an idea about making this work with multiple nodes that would be helpful for the question posed in the comments. Thanks.
https://medium.com/@loganbbres/elixir-websocket-chat-example-c72986ab5778
Most Liked
idi527

Instead of
file = EEx.eval_file("lib/application.html.eex")
you might want to compile the template to a function
require EEx
EEx.function_from_file(:defp, :index_html, "lib/application.html.eex", [])
get "/" do
send_resp(conn, :ok, index_html())
end
it would help you avoid reevaluating the template on each request.
For distribution, there are several options worth exploring, you can go the “phoenix route” and make a basic pubsub or you can go “riak route” and use a hash ring to distribute chat processes across nodes. The former is simpler, the latter is less chatty.
darnahsan
Thank you for this excellent post, helped me setup my PoC , much appreciated.
kasvith
this is really valuble
Logan
Hi kasvith,
Elixir has the URI module that includes a function for parsing a query string.
https://hexdocs.pm/elixir/1.12/URI.html#decode_query/3
URI.decode_query(request.qs)







