WebSocket
WebSocket provides full-duplex communication channels over a single TCP connection, ideal for real-time applications.
Overview
Connecting to a WebSocket
- Select WebSocket from the protocol dropdown
- Enter the WebSocket URL:
wss://echo.websocket.orgorws://localhost:8080 - Click Connect
The connection status indicator will turn green when connected.
URL Schemes
| Scheme | Description |
|---|---|
ws:// | Unencrypted WebSocket |
wss:// | Encrypted WebSocket (TLS) |
Custom Headers
Add authentication or custom headers before connecting:
| Header | Value |
|---|---|
Authorization | Bearer {{TOKEN}} |
X-Custom-Header | custom-value |
note
Headers are sent during the initial HTTP upgrade request and cannot be changed after connection.
Sending Messages
Once connected:
- Type your message in the input field
- Select message type: Text or Binary
- Click Send
Message Types
| Type | Description |
|---|---|
| Text | UTF-8 encoded string (JSON, plain text) |
| Binary | Raw binary data |
Message Log
The message log shows all communication:
| Direction | Description |
|---|---|
| ↑ Sent | Messages you sent (blue) |
| ↓ Received | Messages from server (green) |
| System | Connection events (gray) |
Each message shows:
- Timestamp
- Direction indicator
- Message content
Actions
| Action | Description |
|---|---|
| Connect | Establish WebSocket connection |
| Disconnect | Close the connection |
| Clear | Clear the message log |
Example: Echo Server
Using the playground WebSocket echo server:
URL: ws://localhost:19510/ws/echo
- Connect to the server
- Send a message:
Hello, WebSocket! - Receive echoed response:
{
"type": "echo",
"original": "Hello, WebSocket!",
"timestamp": "2024-01-15T10:30:00Z"
}
Example: Chat Application
URL: wss://chat.example.com/ws
Headers:
Authorization: Bearer {{AUTH_TOKEN}}
X-User-Id: {{USER_ID}}
Send JSON messages:
{
"type": "message",
"room": "general",
"content": "Hello everyone!"
}
Connection States
| State | Description |
|---|---|
| Disconnected | No active connection |
| Connecting | Handshake in progress |
| Connected | Ready to send/receive |
| Closing | Connection closing |
Troubleshooting
Connection Failed
- Verify the URL is correct
- Check if the server is running
- Ensure
ws://vswss://matches server configuration
Messages Not Received
- Check if the server expects a specific message format
- Verify authentication headers are correct
- Look for error messages in the log