Skip to content

feat: Windows TCP fallback for intercom broker#27

Open
guvengursel wants to merge 1 commit into
nicobailon:mainfrom
guvengursel:windows-tcp-fallback
Open

feat: Windows TCP fallback for intercom broker#27
guvengursel wants to merge 1 commit into
nicobailon:mainfrom
guvengursel:windows-tcp-fallback

Conversation

@guvengursel
Copy link
Copy Markdown

Problem

On Windows, named pipes (\\.\pipe\) may be blocked by security policy or antivirus software, returning EACCES. This makes the Pi intercom broker completely non-functional on affected Windows machines.

Error Observed

Error: Intercom unavailable: Broker failed to start within timeout

Root cause: net.Server.listen('\\.\pipe\pi-intercom-...') throws EACCES due to Windows security restrictions on named pipe creation.

Solution

Add automatic TCP fallback when Windows is detected:

  1. paths.ts — On platform === 'win32', returns a TCP port number (19315) instead of a named pipe path. Adds helper functions: isTcpMode(), parseTcpPort(), writeBrokerPort(), readBrokerPort().

  2. broker.ts — When socket path is numeric (TCP mode), listens on {port, host: '127.0.0.1'} instead of a pipe path.

  3. client.ts — When socket path is numeric, connects via net.connect({port, host}) instead of net.connect(pipePath).

  4. spawn.ts — Health check uses TCP connection when in TCP mode.

The framing protocol (length-prefixed JSON) is unchanged — only the transport layer differs.

Behavior

Platform Default Transport Fallback
Linux/macOS Unix socket / Named pipe N/A
Windows TCP port 19315 Named pipe (if PI_INTERCOM_TCP=0)

Environment variable PI_INTERCOM_TCP=1 can force TCP on any platform.

Testing

  • Broker starts successfully on Windows with TCP transport
  • Client connects and registers sessions
  • Cross-session intercom messaging works end-to-end
  • Multiple Pi sessions coordinate via intercom
  • npm install for tsx dependency is required after fresh install

Windows named pipes (\.\pipe\) may be blocked by security policy
or antivirus, returning EACCES. This adds automatic TCP fallback:

- paths.ts: auto-detect Windows → use TCP port 19315 instead of named pipe
- broker.ts: listen on TCP {port, host} when path is numeric
- client.ts: connect via TCP when path is numeric
- spawn.ts: health-check via TCP when path is numeric

Also adds port file persistence (broker.port) for discovery.

The TCP mode is ONLY activated on Windows by default. Unix systems
continue to use named pipes / Unix domain sockets unchanged.

Environment variable PI_INTERCOM_TCP=1 can force TCP on any platform.

Tested: broker starts and client connects successfully on Windows.
Cross-session intercom messaging works end-to-end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant