Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1jehuang Jcode connect socket

From Leeroopedia
Knowledge Sources
Domains Systems_Architecture, Networking
Last Updated 2026-10-18 00:00 GMT

Overview

Concrete tool for connecting to the jcode daemon socket with reconnection support, provided by the jcode server module.

Description

The connect_socket function connects a client to the daemon's Unix socket. It handles connection-refused errors carefully — it never unlinks a refused socket, because doing so can strand a live daemon behind an unlinked path. It also detects EMFILE (too many file descriptors) and provides a diagnostic snapshot. The TUI client uses exponential backoff on reconnection after a server reload or disconnect.

Usage

  • Client connection: Called by clients to connect to the daemon.
  • Reconnection: TUI client reconnects with exponential backoff after disconnect or reload.

Code Reference

Source Location

  • Repository: jcode
  • File: crates/jcode-app-core/src/server/socket.rs

Signature

pub async fn connect_socket(path: &std::path::Path) -> Result<Stream>

Import

use crate::server::socket::connect_socket;

I/O Contract

Inputs

Name Type Required Description
path &Path Yes /// Socket path to connect to

Outputs

Name Type Description
return Result<Stream> /// Connected stream, or error with context

Usage Examples

Connect to Daemon

use crate::server::socket::{socket_path, connect_socket};

let path = socket_path();
match connect_socket(&path).await {
    Ok(stream) => {
        // Send requests over stream
    }
    Err(e) if e.to_string().contains("refused") => {
        // Socket exists but no listener — do NOT unlink
        // Spawn a new daemon instead
    }
    Err(e) => panic!("Connection failed: {e}"),
}

Related Pages

Implements Principle

Requires Environment

Uses Heuristics

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment