Skip to content

NodeSocket

Node socket adapters for Effect sockets.

This module opens node:net connections or wraps existing Node Duplex streams and presents them as Socket.Socket values, socket channels, or layers. It also exposes the current underlying NetSocket service for code running inside a socket handler and re-exports the ws package namespace.

6 exports Added in v4.0.0 Source

Constructors

fromDuplex

Added in v4.0.0 Source

Adapts a Node Duplex into a Socket.Socket, wiring data events to socket handlers, providing a scoped writer, and mapping open, read, write, and close failures to SocketError.

Signature

declare function fromDuplex<RO>(
open: Effect<Duplex, SocketError, RO>,
options?: {
readonly openTimeout?: Input;
},
): Effect<Socket, never, Exclude<RO, Scope>>;

makeNet

Added in v4.0.0 Source

Opens a Node TCP connection as an Effect socket.

When to use

Use to create a scoped Socket.Socket from Node net.createConnection.

Details

Supports openTimeout and closes or destroys the underlying socket when the enclosing scope is finalized.

Signature

declare function makeNet(options: any): Effect<Socket>;

Creates a Channel over a TCP socket, reading arrays of Uint8Array chunks and writing arrays of bytes, strings, or socket close events.

Signature

declare function makeNetChannel<IE = never>(
options: NetConnectOpts,
): Channel<
readonly [Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>],
SocketError | IE,
void,
readonly [
string | Uint8Array<ArrayBufferLike> | CloseEvent,
string | Uint8Array<ArrayBufferLike> | CloseEvent,
],
IE
>;

Layers

layerNet

Added in v4.0.0 Source

Provides a Socket.Socket by opening a TCP connection with the supplied Node net connection options.

Signature

declare const layerNet: (
options: Net.NetConnectOpts,
) => Layer.Layer<Socket.Socket, Socket.SocketError>;

Re-Exports

NodeWS

Added in v4.0.0

Signature

declare const NodeWS: any;

Services

NetSocket

Added in v4.0.0 Source

Service tag for the underlying Node net.Socket associated with the current socket connection.

Signature

declare class NetSocket extends Shape<"@effect/platform-node/NodeSocket/NetSocket", Socket, this> {
constructor(_: never);
}