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

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
dgamidov
Hi folks, Just a short instruction. Maybe it will help somebody. https://v4-alpha.getbootstrap.com/getting-started Install boostrap...
New
9mm
So I’m really loving elixir. BY FAR the most excruciating piece of learning a functional language for me is having to “transform” all my ...
New
jshprentz
Geoffrey Lessel’s 2019 book, Phoenix in Action, was written for Phoenix 1.4. I found that the book’s code examples did not match the cur...
New
kokolegorille
Hello dear alchemists, There was this question some days ago here about the deployment to a VPS. As I was in the process of deploying t...
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
Zurga
In a quest to optimize the amount of data sent between the server and client I recently decided to try to use MessagePack instead of JSON...
New
alejandroErik
POST IN CONSTRUCTION Process for compile erlang otp 20 with odbc-unix for Oracle connections on Solaris 11.3 for 64 bits: Introductio...
New
AstonJ
With a few questions relating to this recently, I wonder if it might help having a thread where we share how we’ve set up Elixir/Erlang/P...
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

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
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
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
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
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

We're in Beta

About us Mission Statement