Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/ws/mod.ts>WebSocket

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
interface WebSocket
implements AsyncIterable<WebSocketEvent>
import { type WebSocket } from "https://deno.land/std@0.71.0/ws/mod.ts";

Properties

readonly
conn: Deno.Conn
readonly
isClosed: boolean

Methods

[[Symbol.asyncIterator]](): AsyncIterableIterator<WebSocketEvent>
send(data: WebSocketMessage): Promise<void>
ping(data?: WebSocketMessage): Promise<void>
close(): Promise<void>

Close connection after sending close frame to peer. This is canonical way of disconnection but it may hang because of peer's response delay. Default close code is 1000 (Normal Closure)

close(code: number): Promise<void>
close(code: number, reason: string): Promise<void>
closeForce(): void

Close connection forcely without sending close frame to peer. This is basically undesirable way of disconnection. Use carefully.