jonasbhjulstad
Hi!
I’ve been able to setup child nodes, but I’m trying to get them online. The intention is to make the nodes act as separate computers, such that I can broadcast messages to them via udp.
Code I’ve been using for parent node:
Node.start(:master@localhost, :shortnames)
(When running :longnames, I get a name error when initializing child nodes)
Code for initializing child nodes:
defmodule Child_Nodes do
def init child_names do
:os.cmd('epmd -daemon')
for child_name <- child_names do
{:ok, node} = start_child child_name
load_code node
end
end
def project_module_path do
Path.absname('_build/dev/ebin') |>
to_charlist()
end
def start_child name do
:slave.start(:localhost, name)
end
def load_code node do
:rpc.block_call(node, :code, :add_paths, [:code.get_path()])
:rpc.block_call(node, :code, :add_paths, [project_module_path()])
end
end
This allows me to run my projects code on the child_nodes and access them using Node.ping(). However, each node are going to find eachother over udp using this module, with different ports:
defmodule Broadcasting do
@broadcast_timeout 1000
@localhost {10, 0, 0, 68}
#Node-name format: OrderHandler_<port>@<address>
def init port do
{:ok, socket} = :gen_udp.open(port, [active: true, broadcast: true])
Task.async fn -> broadcast socket, port end
IO.puts "Node at port #{port} initialized"
listen socket, port
end
def broadcast socket, port do
:gen_udp.send(socket, {255,255,255,255}, port, to_string(port))
:timer.sleep(@broadcast_timeout)
broadcast socket, port
end
def listen socket, port do
local_msg = to_string(port)
receive do
{:udp, _socket, _address, port, ^local_msg} ->
IO.inspect port
IO.puts "localmsg"
listen socket, port
{:udp, _socket, address, remote_port, _msg} ->
string_address = ip_to_string(address)
IO.puts "new node added at port: #{port}"
#"OrderHandler_" <> to_string(remote_port) <> "@" <> string_address |> String.to_atom |> Node.ping
#localhost-version
"OrderHandler_" <> to_string(remote_port) <> "@localhost" |> String.to_atom |> Node.ping
end
end
def ip_to_string ip do
:inet.ntoa(ip) |> to_string()
end
end
Is it possible to bring all child nodes online?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
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
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
ityonemo
What is going to call this broadcasting module? A task? I think this is a place you should use gen_servers.
Also, the nodes have to be on the same layer-2 network that supports udp broadcasting and most major cloud providers don’t support this.
You might need to give beam.smp special setuid permissions (CAP_NET_RAW iirc) for it to be able to broadcast.
Finally you may run out of udp connections if you’re using nf_conntrack on Ubuntu 18.04.
jonasbhjulstad
The plan was to simply spawn the broadcasting procedure in each child node:
The thing is that they aren’t able to find each other once the broadcasting starts.
This isn’t going to be a long-time robust solution, it is only going to be a replacement for the lack of computers atm
ityonemo
What’s the result of gen_udp.send?
jonasbhjulstad
They are able to detect themselves, but not each other
ityonemo
What is the result of :gen_udp.send? Can you IO.inspect it?
jonasbhjulstad
Sorry, for the late reply, inspecting the :gen_udp.send was a good idea: