LegitStack

LegitStack

Websocket server in Elixir or phoenix

I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that smart I thought I’d go as high level as possible.

I found this thread:

and this one:

and forked his code to:
https://github.com/SatoriNetwork/phx_raws

I as I was bringing it up to date I ran into this issue:

Phoenix.Socket.Transport.connect/6 is undefined or private. Did you mean:

 * connect_info/3Elixir

Call to missing or unexported function ‘Elixir.Phoenix.Socket.Transport’:connect/6ElixirLS Dialyzer

on this line:
case Transport.connect(endpoint, handler, transport, __MODULE__, nil, conn.params) do

so after consulting the docs, which I don’t understand I came up with this, which I;m sure is wildly incorrect as well:

case Transport.connect(
          %{:endpoint=>endpoint, :transport=>transport, :params=>conn.params, :options=>[
            handler: handler, __MODULE__: __MODULE__, serializer: nil]}) do

But it told me I shouldn’t use this function anyway:

Phoenix.Socket.Transport.connect/1 is undefined or private. Did you mean:

 * connect_info/3Elixir

Call to missing or unexported function ‘Elixir.Phoenix.Socket.Transport’:connect/1ElixirLS Dialyzer

I think the code is almost updated, but what do I have to do to get it to a working state?

Most Liked

josevalim

josevalim

Creator of Elixir

There is a simpler API in Phoenix for custom websockets, you can follow the example here:

https://hexdocs.pm/phoenix/Phoenix.Socket.Transport.html#module-example

11
Post #3
ruslandoga

ruslandoga

:wave:

Using cowboy might be easier than you think. Here’s a small example of how it could be done. The important bits are the plug child spec and the module implementing cowboy_websocket behaviour. You can ignore the Web.UserSocket and “pubsub” specifics.

More info on cowboy_websocket behaviour.

RooSoft

RooSoft

Figured out this part

socket("/", RelayWeb.Sockets.EchoSocket, websocket: [path: ""])
ku1ik

ku1ik

Thank you @RooSoft! I was trying to solve these 2 specific problems (path, ping) myself and your solutions to both work perfectly.

mtrudel

mtrudel

Creator of Bandit

Careful that sending pongs in response to client pings is explicitly handled for you by the underlying server in the WebSock world: WebSock — WebSock v0.4.3

Where Next?

Popular in Questions Top

yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement