Send Messages

Learn how to send messages using WebSockets.

Pushing messages to a client

We saw an example of how PubSub is used to broadcast from our Endpoint module. We could push a message to our connected topic without writing any Channel handler code. This is the default behavior of Channels:

Any message sent to their topic is broadcast directly to the connected client.

However, we can customize this behavior by intercepting any outgoing messages and deciding how to handle them.

Let’s intercept an outgoing ping request and add some additional metadata to the request. We’ll start with a broken implementation to highlight a widespread problem when adding a handle_out/3 function.

Get hands-on with 1200+ tech skills courses.