NodeSocketServer
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.
Constructors
Signature
declare const make: (...args: [options: any]) => Effect<
{
readonly address: Address;
readonly run: <R, E, _>(
handler: (socket: Socket) => Effect<_, E, R>,
) => Effect<never, SocketServerError, R>;
},
SocketServerError,
Scope
>;makeWebSocket
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
>;Layers
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>;layerWebSocket
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>;Services
IncomingMessage
Service tag for the Node IncomingMessage associated with the current WebSocket server connection.
Signature
declare class IncomingMessage extends Shape<
"@effect/platform-node-shared/NodeSocketServer/IncomingMessage",
IncomingMessage,
this
> {
constructor(_: never);
}
Creates a scoped TCP
SocketServerfrom a Nodenet.Server, starts listening with the supplied options, queues pending connections untilrunis called, and closes the server when the scope ends.