effect-socket

Build bidirectional TCP, Unix-domain, and WebSocket transports with Effect v4 socket modules.

1|Updated Aug 24, 2026
One-click install
npx skills add https://github.com/lambdasolver2/opencode-effect-harness --skill effect-socket-lambdasolver2
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: effect-socket
Source: https://github.com/lambdasolver2/opencode-effect-harness/tree/main/packages/module-typescript/assets/skills/effect-socket
Command: npx skills add https://github.com/lambdasolver2/opencode-effect-harness --skill effect-socket-lambdasolver2

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires effect, @effect/platform-node, @effect/platform-bun.

What problem does it solve? Writing correct bidirectional socket code in Effect v4 requires understanding the unstable effect/unstable/socket API surface, which differs significantly from v3's @effect/platform/Socket. This Skill provides verified guidance on the Socket run/writer model, error taxonomy, framing, and reconnect patterns so you avoid silent failures like clobbered writers, suspended writes, and unexpected close-code errors. ## Core Features & Use Cases - Socket clients: Create WebSocket clients via Socket.makeWebSocket/layerWebSocket and TCP or Unix-domain clients via NodeSocket.makeNet/fromDuplex, with open timeouts and per-reconnect URL re-evaluation. - Servers: Build TCP/Unix and WebSocket servers with NodeSocketServer.make/layer accept loops, per-connection scoping, and access to raw net.Socket or IncomingMessage services. - Framing and streaming: Convert sockets to Channels with Socket.toChannel, frame typed messages with Ndjson.duplexSchema, and pipe streams through connections with Stream.pipeThroughChannel. - Reconnect patterns: Implement retry loops with Effect.retry and exponential backoff schedules, using onOpen for re-subscription handshakes, mirroring RpcClient.makeProtocolSocket. - Use Case: Build a reconnecting WebSocket consumer that subscribes to a trade feed, refreshes auth tokens per reconnect via an effectful URL, and treats clean closes as normal completion with closeCodeIsError. ## Quick Start Ask the assistant to write an Effect v4 TCP echo client and server using NodeSocket and NodeSocketServer with NDJSON framing and automatic reconnection.

Frequently Asked Questions about effect-socket

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a WebSocket client in Effect v4?

Use Socket.makeWebSocket from effect/unstable/socket with a URL and options like closeCodeIsError and openTimeout, then provide a WebSocketConstructor layer such as NodeSocket.layerWebSocketConstructor. The connection opens per run call, so retrying the run loop reconnects.

How do I build a TCP server with NodeSocketServer?

Call NodeSocketServer.make with a port (0 for ephemeral) inside a scope, then fork server.run with a handler that receives each connection as a Socket. Wrap handlers using socket.writer in Effect.scoped, since the server strips Scope from the handler context.

Does @effect/platform/Socket exist in Effect v4?

No, @effect/platform/Socket was removed in v4. Import Socket and SocketServer from effect/unstable/socket, and use NodeSocket/NodeSocketServer from @effect/platform-node or BunSocket/BunSocketServer from @effect/platform-bun for platform implementations.

Why does my WebSocket run fail on a clean close with code 1000?

By default every WebSocket close code fails the run with SocketCloseError because defaultCloseCodeIsError returns true for all codes. Pass closeCodeIsError: (code) => code !== 1000 to make clean closes complete successfully, or catch with SocketCloseError.filterClean.

How do I frame messages over a TCP socket in Effect?

TCP delivers a byte stream, so wrap Socket.toChannel with Ndjson.duplexSchema from effect/unstable/encoding, providing inputSchema for outgoing values and outputSchema for incoming lines. Pipe a Stream through the resulting channel with Stream.pipeThroughChannel.

Why do my socket writes hang forever in Effect?

Writes through socket.writer suspend on an internal latch until a run loop is active and the connection is open. Always run socket.run concurrently (for example in a forked fiber) alongside any writing fibers, or the writes wait indefinitely.