Logan

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

idi527

:wave:

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

darnahsan

Thank you for this excellent post, helped me setup my PoC , much appreciated.

kasvith

kasvith

this is really valuble

Logan

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)

Where Next?

Popular in Guides/Tuts Top

sergio
https://sergiotapia.me/generate-images-with-name-initials-using-elixir-and-imagemagick-374eca4d14ff Hope this saves you guys some time!...
New
hauks96
Hello everyone, I created a deployment tutorial for Phoenix applications with Kubernetes (microk8s) a few months back with the goal of s...
New
kuon
I have a page with a large state that is loaded from DB, let’s call that “data”. I have a root live view that load “data” on mount and r...
New
hlx
Typed my very first blog post ever, hope it will help some people https://henricus.xyz/roll-your-own-email-password-authentication-with...
New
njwest
In the process of developing a Phx-based multiplayer experience, I found myself with so many browser tabs open with Elixir gaming resourc...
New
wfgilman
I'm writing up this quick "How to" because what I thought was going to be an easy implementation of a Plug to validate a webhook request ...
New
rhcarvalho
After collecting information from multiple sources (this forum, blogs, StackOverflow and GitHub), I was finally able to successfully embe...
New
jtormey
Hello! Having written a lot of LiveView code, I’ve made some VS Code snippets to speed up writing callbacks for LiveViews and LiveCompon...
New
stryrckt
I’m excited about the new LiveComponents feature in LiveView, but I haven’t seen much written on it, so I decided to write a couple of ar...
New
AstonJ
..or as and when you can think of one :icon_cool: This thread my also be of interest: What took you way too long to figure out? :003:
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

We're in Beta

About us Mission Statement