Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/content/docs/workers/examples/websockets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ async function handleRequest(request) {
}

const webSocketPair = new WebSocketPair();
const client = webSocketPair[0],
// This is the server-side WebSocket in the Worker.
const client = webSocketPair[0],
//This is the remote connection. For example, from a browser client.
server = webSocketPair[1];

return new Response(null, {
Expand All @@ -118,7 +120,9 @@ async fn fetch(req: HttpRequest, _env: Env, _ctx: Context) -> Result<worker::Res
}

let ws = WebSocketPair::new()?;
// This is the server-side WebSocket in the Worker.
let client = ws.client;
// This is the remote connection. For example, from a browser client.
let server = ws.server;
server.accept()?;

Expand Down Expand Up @@ -300,4 +304,4 @@ async function websocket(url) {

## WebSocket compression

Cloudflare Workers supports WebSocket compression. Refer to [WebSocket Compression](/workers/configuration/compatibility-flags/#websocket-compression) for more information.
Cloudflare Workers supports WebSocket compression. Refer to [WebSocket Compression](/workers/configuration/compatibility-flags/#websocket-compression) for more information.
Loading