Packard_Goose

Packard_Goose

I’m trying to send a message using websockex but I’m getting an error when I try to send out my json string (I used Jason), what could I possibly be missing?

"{\"action\":\"subscribe\",\"options\":{\"accounts\":[\"nano_1qzfp3op48im348qdybmrheu9dogtopj1jyioguq9pyo5i7mkqgo4jaswp4a\"],\"all_local_accounts\":true},\"topic\":\"confirmation\"}"
** (ArgumentError) argument error
    :erlang.send(MitoNode.Client, {:"$websockex_cast", "{\"action\":\"subscribe\",\"options\":{\"accounts\":[\"nano_1qzfp3op48im348qdybmrheu9dogtopj1jyioguq9pyo5i7mkqgo4jaswp4a\"],\"all_local_accounts\":true},\"topic\":\"confirmation\"}"})
    (websockex) lib/websockex/utils.ex:57: WebSockex.Utils.send/2
    (websockex) lib/websockex.ex:398: WebSockex.cast/2

Showing Posts 1 to 5

NobbZ

NobbZ

:erlang.send/2 only fails when the first argument is an atom and this atom is not registered to a process name.

So you need to make sure, that there is actually a process with the name MitoNode.Client.

Or pass a pid that actually does exist.

But all of this is just guessing, as you have not even provided code, but just an error.

Packard_Goose

Packard_Goose OP

Sorry, my bad

Heres the construction of the message.

  def sub() do

    {:ok, message} = %{
    "action" => "subscribe",
    "topic" => "confirmation",
    "options" => %{
      "all_local_accounts" => true,
      "accounts" => [
        "nano_1qzfp3op48im348qdybmrheu9dogtopj1jyioguq9pyo5i7mkqgo4jaswp4a"
      ]
    }
  } |> Jason.encode

    IO.inspect(message)

    WebSockex.cast(__MODULE__, message)
  end

in my supervision tree I just have the child {MitoNode.Client, ["random WebSockex message"]} as per the example but I will try a pid too

NobbZ

NobbZ

That just delegates the start of the client to its start_link/1, IIRC.

But in that, do you actually name the started process?

Packard_Goose

Packard_Goose OP

Man you’re the best. Forgot the opts field in start_link, which of course had a name: field, tried subbing with the atom name I gave it and it works fine now. Thanks for the quick advice!

CamonZ

CamonZ

You can also use the pid of the WebSockex process and WebSockex.send_frame/2 to send the data. e.g.

{:ok, pid} = MyWebSockexWrapper.start_link()


msg = Jason.encode!(%{
    "action" => "subscribe",
    "topic" => "confirmation",
    "options" => %{
      "all_local_accounts" => true,
      "accounts" => [
        "nano_1qzfp3op48im348qdybmrheu9dogtopj1jyioguq9pyo5i7mkqgo4jaswp4a"
      ]
    })

WebSockex.send_frame(pid, {:text, msg})
— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews