leaf

leaf

Testing sockets in phoenix

I am totally new to sockets and its my first time using them. I have very simple config. In endpoint I have simple default user socket.

          socket "/socket", ApiWeb.UserSocket,
            websocket: true,
             longpoll: false

In user socket I have the following code:

      def connect(%{"token" => token}, socket, _connect_info) do
        case Nuton.Guardian.resource_from_token(token) do
         {:ok, user, _claims} ->
           {:ok, assign(socket, :current_user, user)}

         {:error, _reason} ->
        :error
       end
      end


      def id(socket),
                        do:
                           "#{socket.assigns.current_user.phone_number || socket.assigns.current_user.email}:#{
                               socket.assigns.current_user.id
                             }"

When I try to test it with any online websocket client with the following url:

           ws://localhost:4000/socket

It won’t work and In the console I will get error message that
no route found for GET /socket

. I don’t understand why it’s hitting the router and not the socket. Is there anything else I need to do.
Thanks
@idi527

First Post!

bluejay

bluejay

What happens if you try
ws://localhost:4000/socket/websocket

Where Next?

Popular in Questions Top

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
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
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
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
New

We're in Beta

About us Mission Statement