LegitStack
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/3ElixirCall 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/3ElixirCall 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?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 8 of 8 Posts
ruslandoga
Using
cowboymight 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 theWeb.UserSocketand “pubsub” specifics.More info on
cowboy_websocketbehaviour.josevalim
There is a simpler API in Phoenix for custom websockets, you can follow the example here:
RooSoft
Is there a way to make this thing listen to the root path, such as ws://localhost?
From what I understand, it listens to the
/websocketpath if the endpoint’s socket is configured like sosocket "/", RelayWeb.Sockets.EchoSocket.I’ve seen comments saying it’s better for whatever reason. Thing is, I have to fill a spec that requires that the websockets endpoint answers to the root path and I have no idea how to do that with
Phoenix.Socket.Transportas we stand.RooSoft
Also would like to know how to implement heartbeat such as sending a PING and expecting a PONG after a while instead of simply closing the connection after 60s of inactivity.
RooSoft
Figured out this part
RooSoft
Also figured out…
In init/1,
Then, add a handle_info
Will suggest the peer has to send a
PONG, and if it does, that will count as a communication and thus will reset the timeout.ku1ik
Thank you @RooSoft! I was trying to solve these 2 specific problems (path, ping) myself and your solutions to both work perfectly.
mtrudel
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.5.3