← Back to Home

WebSocket with History

/ws/:id
WebSocket endpoint that stores message history. Create a session, connect via WebSocket, and view message history later. Messages stored for 1 hour.
Try it now

Parameters

id path
WebSocket session ID (use /ws/new to create)

Examples

curl
# Step 1: Create a WebSocket session
curl https://tcpdata.com/ws/new

# Returns:
# {
#   "id": "abc12345",
#   "ws_url": "wss://tcpdata.com/ws/abc12345",
#   "history_url": "https://tcpdata.com/ws/abc12345/history",
#   "expires_in": "1 hour"
# }

# Step 2: Connect with wscat or any WebSocket client
wscat -c wss://tcpdata.com/ws/abc12345

# Step 3: View message history
curl https://tcpdata.com/ws/abc12345/history
JavaScript (WebSocket)
// Create session
const session = await fetch('https://tcpdata.com/ws/new')
  .then(r => r.json());

// Connect to WebSocket
const ws = new WebSocket(session.ws_url);

ws.onopen = () => {
  ws.send('Hello!');
};

ws.onmessage = (event) => {
  console.log('Received:', event.data);
};

// Later, view history
const history = await fetch(session.history_url)
  .then(r => r.json());
console.log(history.messages);
Python (websocket-client)
import requests
import websocket

# Create session
response = requests.get('https://tcpdata.com/ws/new')
session = response.json()

# Connect and send messages
ws = websocket.WebSocket()
ws.connect(session['ws_url'])
ws.send('Hello!')
print(ws.recv())

# View history
history = requests.get(session['history_url']).json()
print(history['messages'])