Phoenix Channel - question on broadcast behavior on cluster


I am learning about Phoenix Channel and have question on behavior of broadcast which not as I expected.

Environment: Windows 10, Phoenix 1.4.17, Erlang 22, Elixir 1.12

server@127.0.01, listening on port 4000
remote@, listening on port 4001

client1 - wscat connects to server@ on port 4000, then subscribe to “ping” topic.
client2 - wscat connects to remote@ on port 4001, then subscribe to “ping” topic.

And here is my doubt, when I broadcast on server@, only client1 receives the message.
When I broadcast on remote@, only client2 receives the message.

I need help on what is exactly the correct behavior?


Have you connected the two nodes? They need to be connected before they can chat with each other.

iex(remote@> Node.connect(:"server@")
1 Like

That’s all it needs. Thanks.

How to make them connected automatically on startup?

You can look at the libcluster library as one way to do that

1 Like

Many thanks for giving the hint.