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

x/sockets/src/server.ts>Server

A WebSocket library for Deno.
Latest
class Server
extends EventEmitter
import { Server } from "https://deno.land/x/sockets@v0.5.0/src/server.ts";

The SocketServer class is responsible for creating a users socket server. Similar to how Drash.Http.Server creates a server instance.

Constructors

new
Server(transmitterOptions?: ITransmitterOptions)

Construct an object of this class.

Properties

deno_server: DenoServer | null

A property to hold the Deno server. This property is set in this.run() like so:

this.deno_server = serve();
hostname: string

A property to hold the hostname this server listens on.

port: number

A property to hold the port this server listens on.

transmitter: Transmitter

A property to hold the transmitter. The transmitter is in charge of transmitting data throughout the server-client lifecycle.

Methods

protected
acceptWebSockets()

Accept incoming web sockets as clients.

protected
handleMessageAsBinary(client: Client, message: Uint8Array)

Handle a binary message sent by the socket client.

protected
handleMessageAsJsonString(client: Client, message: string): Promise<void>

Handle a message in the format of a JSON string.

protected
handleMessageAsString(client: Client, message: string): Promise<void>

Handle a string message sent by the socket client.

close(): Promise<void>

Close the server.

run(options: HTTPOptions): Promise<DenoServer>

Handles websocket connection. After a successful connection, the client will be added to EventEmitter.clients and the server will start listening to events.

runTLS(options: HTTPSOptions): Promise<DenoServer>

Handles websocket secure connection. After a successful connection, the client will be added to EventEmitter.clients and the server will start listening to events.