Skip to content

Add robust reconnection with mDNS watch and WaitingForServer state#123

Merged
chrisuthe merged 1 commit intochrisuthe:devfrom
scyto:dev
Jan 29, 2026
Merged

Add robust reconnection with mDNS watch and WaitingForServer state#123
chrisuthe merged 1 commit intochrisuthe:devfrom
scyto:dev

Conversation

@scyto
Copy link
Copy Markdown
Collaborator

@scyto scyto commented Jan 27, 2026

Summary

  • Disable SDK AutoReconnect — The app manages its own reconnection with fresh mDNS discovery and clean player contexts, which handles server address changes better than the SDK's built-in retry-same-URI approach.
  • Map all SDK connection states to app PlayerStateConnecting, Handshaking, Reconnecting, Disconnected, and Disconnecting now propagate to the UI instead of being ignored.
  • Concurrent reconnection with mDNS watch — When players disconnect, an mDNS watch (ServerFound + ServerUpdated events) detects server reappearance and triggers immediate concurrent reconnection via SemaphoreSlim signal + Task.WhenAll, replacing the old sequential polling loop.
  • WaitingForServer state for mDNS-dependent startup — Players that start before a server is available enter a passive wait mode (no active retries, NextRetryTime = DateTime.MaxValue) until mDNS discovers a server. UI shows "Waiting for mDNS discovery" badge.
  • Suppress transient error states during reconnection — Override Error/Stopped/Starting/Connecting states with Reconnecting or WaitingForServer in the API response to prevent red error flash in UI.
  • Initial connection failure queuing — Players that fail their first connection attempt are now queued for reconnection instead of staying in Error state permanently.

Dependency

Required together with chrisuthe/windowsSpin#7 — The SDK's SendMessageAsync fix is needed to detect connection loss promptly (triggers HandleConnectionLostAsync when WebSocket closes but receive loop is still blocking). Both PRs must be merged together.

Test plan

  • Start app with no server running → all players show "Waiting for mDNS discovery"
  • Start the server → all players connect concurrently within ~15 seconds
  • Kill the server → players transition to "Reconnecting" within ~10 seconds
  • Restart the server → mDNS watch triggers immediate reconnection (no backoff wait)
  • Verify no red error flash between reconnection attempts
  • Verify explicit-server players use active backoff retries (not passive mDNS wait)
  • Verify single-player stop/start/restart still works independently

🤖 Generated with Claude Code

- Disable SDK AutoReconnect; app manages reconnection with fresh mDNS
  discovery and clean player contexts
- Map all SDK connection states to app PlayerState enum
- Add concurrent reconnection via Task.WhenAll instead of sequential
- Add mDNS watch (ServerFound + ServerUpdated) with semaphore signal
  for immediate reconnection when server reappears
- Add WaitingForServer state for mDNS-dependent players that start
  before a server is available (passive wait, no active retries)
- Override transient Error/Stopped states during reconnection to
  prevent red flash in UI
- Switch to local SDK ProjectReference for development

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@chrisuthe chrisuthe merged commit 5d514a5 into chrisuthe:dev Jan 29, 2026
scyto added a commit that referenced this pull request Feb 8, 2026
Skip invalid 0ms latency samples during lock-in
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.

2 participants