I am learning and I did examples of Node interface to communicate messages between multi-devices.
There are a Nerves target and the other device of Phoenix for watching image through ethernet.
What means can I use to transfer an image data in the Nerves to the Phoenix watching the data?
Thanks!
I am sorry that I found a way. I thought that sending data should be “text/character” data but binary data.
defmodule Server do
def server_start do
pid = spawn(__MODULE__, :loop, [])
:global.register_name(:server, pid)
end
def loop() do
receive do
{sender, msg} ->
data = File.read!(msg)
send sender, {:ok, data}
end
loop()
end
end
defmodule Client do
def start do
send :global.whereis_name(:server), {self(), "racoondog.jpg"}
receive do
{:ok, message} ->
File.write("getimg.jpg", message)
end
end
end
Then
---- server
iex(server@HOST)>Node.connect(:"client@HOST")
true
iex(server@HOST)>Server.server.start
---- client
iex(client@HOST)>Client.start
iex(client@HOST)>ls
xxx getimg.jpg xxx
$ open getimg.jpg ---> it shows up correctly.