Communication Between Players

Understand how both players communicate in Islands’ engine.

Communication between the players

Now, let’s look at how push/3 works inside the GameChannel. Instead of a reply tuple, this will send a new event down the Channel, but only to the original caller. Since we don’t rely on a reply tuple to communicate back to the client, we replace it with {:noreply, socket}.

The path of message passing will look the same as the reply shown in the following figure.

Let’s go to the Channel and change the handle_in/3 clause to use push/3. We could leave the :reply tuple there and get two responses. However, since push/3 will already send a reply, it makes more sense to swap in {:noreply, socket} instead:

Get hands-on with 1200+ tech skills courses.