Skip to content

SocketServer

Service contract for servers that accept socket connections.

SocketServer exposes the bound server address and a long-running run loop that hands each accepted connection to a handler as a Socket.Socket. The module also defines TCP and Unix socket address models plus the server-level errors reported while opening or running a server. Platform layers provide concrete implementations of this service.

10 exports Added in v4.0.0 Source

Errors

Tagged socket server error that wraps a server error reason and exposes its cause.

Signature

declare class SocketServerError extends YieldableError<this> & {
  readonly _tag: "SocketServerError";
} & Readonly<{
  readonly reason: SocketServerErrorReason;
}> {
  constructor(props: {
    readonly reason: SocketServerErrorReason;
  });
  readonly "@effect/platform/SocketServer/SocketServerError": "@effect/platform/SocketServer/SocketServerError";
  message: string;
}

Union of socket server error reasons.

Signature

type SocketServerErrorReason = SocketServerOpenError | SocketServerUnknownError;

Error reason for failures that occur while opening a socket server.

Signature

declare class SocketServerOpenError extends YieldableError<this> & {
  readonly _tag: "SocketServerOpenError";
} & Readonly<{
  readonly cause: unknown;
}> {
  constructor(args: {
    readonly cause: unknown;
  });
  message: string;
}

Error reason for uncategorized socket server failures.

Signature

declare class SocketServerUnknownError extends YieldableError<this> & {
  readonly _tag: "SocketServerUnknownError";
} & Readonly<{
  readonly cause: unknown;
}> {
  constructor(args: {
    readonly cause: unknown;
  });
  message: string;
}

Models

Address type

Added in v4.0.0 Source

Socket server address, either a TCP host and port or a Unix socket path.

Signature

type Address = UnixAddress | TcpAddress;

TcpAddress interface

Added in v4.0.0 Source

TCP socket server address with hostname and port.

Signature

interface TcpAddress {
  readonly _tag: "TcpAddress";
  readonly hostname: string;
  readonly port: number;
}

UnixAddress interface

Added in v4.0.0 Source

Unix socket server address identified by a filesystem path.

Signature

interface UnixAddress {
  readonly _tag: "UnixAddress";
  readonly path: string;
}

Services

SocketServer

Added in v4.0.0 Source

Context service for a socket server, exposing its bound address and a run loop that handles each accepted Socket.

Signature

declare class SocketServer extends Shape<
  "@effect/platform/SocketServer",
  {
    readonly address: Address;
    readonly run: <R, E, _>(
      handler: (socket: Socket) => Effect<_, E, R>,
    ) => Effect<never, SocketServerError, R>;
  },
  this
> {
  constructor(_: never);
}

Type IDs

ErrorTypeId

Added in v4.0.0 Source

Runtime type identifier attached to SocketServerError values.

Signature

declare const ErrorTypeId: ErrorTypeId;

ErrorTypeId type

Added in v4.0.0 Source

Type-level identifier used to mark SocketServerError values.

Signature

type ErrorTypeId = "@effect/platform/SocketServer/SocketServerError";