Receive Messages
Learn how to receive messages using WebSockets.
Receiving messages from a client
Receiving requests from a client and sending a response is critical to all applications. This lets our users interact with our real-time application without writing additional entry points, such as controller actions. For example, when a client sends a message over the WebSocket connection that powers their Channels, we can also avoid creating traditional HTTP controller code. We’ll see how to handle a client’s request and send various response types.
When a client sends a message to a Channel, the transport process receives it and delegates it to the Socket’s handle_in/2
callback. The Socket sends the decoded message struct to the correct Channel process and handles errors such as a mismatched topic—the Phoenix.Channel
. The server process handles the sent message by delegating to the associated Channel implementation’s handle_in/3
callback. This happens transparently to us, meaning that we only need to be concerned with the client sending a message and our ...