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.