Sending and receiving messages
Send saved text, JSON and binary messages, and read the connection's transcript.
Overview
A WebSocket request keeps the messages you send as saved messages, in its Messages tab, so they're ready each time you connect and they're shared along with the request. Each message has a name, a format and a body that can use variables.
Everything sent and received on a connection appears in the response inspector's Messages tab, in the order it happened, along with pings, the connection's opening and its close.
Write a message
In the request editor, click Messages, or press Command-5. The editor shows the selected message.
-
Choose a format from the menu beside the message's name: Text, JSON or Binary.
-
Enter the message's body.
Text and JSON messages can use variables, such as
{"type": "subscribe", "token": "{{token}}"}. To indent a JSON message and sort its keys, click Beautify JSON. -
For a Binary message, choose Hex or Base64 from the menu beside the format, then enter the bytes. To send a file's contents, click Load from File…. The file can't be larger than the connection's maximum message size.
Relay saves the message as you type. When you change a message's format, Text and JSON become their UTF-8 bytes, and Binary that's valid UTF-8 text becomes that text.
Manage saved messages
Click the message's name at the left of the editor to see every saved message. Click a message to select it.
- To add a message, click New Message at the bottom of the list.
- To rename, copy, reorder or remove a message, click the button with three dots on its row and choose Rename, Duplicate, Move Up, Move Down or Delete.
Each of these changes is a single step you can undo.
Send a message
Connect first, as described in Connecting to a WebSocket server. Then click Send in the message editor, or press Command-Return to send the selected message.
Relay fills in a message's variables when you send it, with the variables' current values and any values the request's Before Connecting script set. Dynamic variables, such as {{$guid}}, get a new value each time. If a variable has no value, Relay sends the token as written and notes it in the Messages tab.
To check that the server is responding, click Ping. The Messages tab's footer shows how long the server took to answer. To send pings automatically, set Automatic Pings in the request's Settings tab.
Read the Messages tab
In the response inspector, click Messages. Each row shows when the message was sent or received, relative to the connection opening, its direction, its kind, its data and its size. Select a row to see its details below the list: JSON is formatted and highlighted, and binary data is shown as hex and ASCII.
- Direction: Choose All Messages, Sent or Received from the menu at the top.
- Filter: Enter text to show only the messages that contain it.
- Follow: Click the Follow button to keep the newest message in view. Scroll up to pause.
- Copy Message: Copies the selected message's data. Binary data is copied as base64.
- Clear: While the connection is open, removes the messages so far from the list. It can't be undone, and History records only what's left.
- More: Choose Show Pings to show pings and their replies. Choose Copy All as NDJSON to copy every message as one JSON object per line; while a filter is on, the item is Copy Shown as NDJSON and copies only the messages shown.
The footer shows the number of messages, their total size, how long the connection has been open and the last ping's round trip. When the connection ends, it shows why, such as Closed by server, Disconnected or the error.
If a connection receives more than 10,000 messages or 64 MB, Relay drops the oldest ones, and the footer shows how many were dropped.
Find messages in History
When a connection ends, History records it with its messages, up to the most recent 2,000 messages and 8 MB. Like other history, the messages are encrypted on your Mac. Select the entry in History and click Messages to read them again. For more, see Reviewing request history.
See Also
- Connecting to a WebSocket server: Create a WebSocket request, configure its handshake and open a connection.
- Using variables: Insert values into requests with
{{name}}tokens and see where each value comes from. - Generating dynamic values: Fill requests with fresh IDs, timestamps and sample data each time they're sent.
- Receiving server-sent events: Watch an event stream as it arrives, filter its events and stop it when you're done.