Skip to content

NodeSocketServer.ts

Node socket server adapters for Effect’s unstable socket server API.

This module turns node:net TCP or Unix-domain servers and ws WebSocket servers into scoped SocketServer.SocketServer services. Use the TCP constructors when handlers should receive a Socket.Socket backed by a Node net.Socket; use the WebSocket constructors when handlers should receive a Socket.Socket backed by ws and have access to the per-connection WebSocket and IncomingMessage services.

Since v4.0.0



Creates a scoped TCP SocketServer from a Node net.Server, starts listening with the supplied options, queues pending connections until run is called, and closes the server when the scope ends.

Signature

declare const make: (
options: Net.ServerOpts & Net.ListenOptions
) => Effect.Effect<
{
readonly address: SocketServer.Address
readonly run: <R, E, _>(
handler: (socket: Socket.Socket) => Effect.Effect<_, E, R>
) => Effect.Effect<never, SocketServer.SocketServerError, R>
},
SocketServer.SocketServerError,
Scope.Scope
>

Source

Since v4.0.0

Creates a scoped WebSocket SocketServer backed by the ws package, providing the WebSocket and its Node IncomingMessage to connection handlers and closing the server when the scope ends.

Signature

declare const makeWebSocket: (
options: NodeWS.ServerOptions<typeof NodeWS.WebSocket, typeof Http.IncomingMessage>
) => Effect.Effect<SocketServer.SocketServer["Service"], SocketServer.SocketServerError, Scope.Scope>

Source

Since v4.0.0

Provides a TCP SocketServer by creating and managing a scoped Node net.Server with the supplied server and listen options.

Signature

declare const layer: (
options: Net.ServerOpts & Net.ListenOptions
) => Layer.Layer<SocketServer.SocketServer, SocketServer.SocketServerError>

Source

Since v4.0.0

Provides a WebSocket SocketServer backed by the ws package and managed with the supplied server options.

Signature

declare const layerWebSocket: (
options: NodeSocket.NodeWS.ServerOptions<typeof NodeSocket.NodeWS.WebSocket, typeof Http.IncomingMessage>
) => Layer.Layer<SocketServer.SocketServer, SocketServer.SocketServerError>

Source

Since v4.0.0

Service tag for the Node IncomingMessage associated with the current WebSocket server connection.

Signature

declare class IncomingMessage

Source

Since v4.0.0