I have created a simple distributed chat application using erlang and want to build it using rebar3. The application consists of some modules such as server.erl, client.erl, chatroom.erl. I build the applcation using below command
rebar3 new app chat
I can run the server using
rebar3 shell --sname server
the server.erl is run when the application starts. Now, I want a client to create a server node and connect to the server and send some messages. For example: client:login(name). How to do this please? shall I navigate to the client.beam file or there is another short way ?
Well, the first place to start reading might be here.
You can start by running the application in two different Erlang nodes by doing rebar3 shell --sname server
and rebar3 shell --sname client
on one terminal shell each.
Then you can do net_adm:names() to verify on both nodes to check that nodes see each other. If they don’t you might want to set the same cookie for both started nodes (check out the link above).
Even if they see each other you might want to issue a net_adm:ping from one to the other. If nodes() on each of them lists the other you will be in the right path.
Then it’s a matter of properly registering the “server”. You might want to use the global module to register the server instead of just doing erlang:register/2.
As a tip, be sure to test node communication between two shells before trying to make your logic work between two nodes