This guide explains how to connect to Vix WebSocket servers from the browser and C++.
const ws = new WebSocket("ws://localhost:9090/");
ws.onopen = () => {
ws.send(JSON.stringify({
type: "chat.join",
payload: { user: "Alice", room: "africa" }
}));
};
ws.onmessage = (e) => console.log("Received:", e.data);ws.send(JSON.stringify({
type: "chat.message",
payload: { user: "Alice", room: "africa", text: "Hello!" }
}));async function poll() {
const res = await fetch("/ws/poll?session_id=123");
const data = await res.json();
console.log("LP:", data);
poll();
}
poll();#include <vix/websocket/client.hpp>
#include <iostream>
int main() {
vix::websocket::Client client("ws://localhost:9090/");
client.on_open([]{ std::cout << "Connected!"; });
client.on_message([](const std::string& m){
std::cout << "Got: " << m << std::endl;
});
client.connect_blocking();
}client.send_json(JsonMessage::serialize(
"chat.message",
{"user", "Bob", "room", "africa", "text", "Hi!"}
));- WS -> LP fallback
- Auto reconnect
- Offline message queue