Skip to content

Support multiple NICs for UDP discovery and connection management#362

Merged
from2001 merged 5 commits intodevelopfrom
feature/support-multiple-nics-for-python-client
Mar 14, 2026
Merged

Support multiple NICs for UDP discovery and connection management#362
from2001 merged 5 commits intodevelopfrom
feature/support-multiple-nics-for-python-client

Conversation

@from2001
Copy link
Collaborator

@from2001 from2001 commented Mar 3, 2026

This pull request enhances the reliability and flexibility of network connection and discovery in both the Python server (styly_netsync/client.py) and Unity client (ConnectionManager.cs, ServerDiscoveryManager.cs). The main improvements are: (1) robust support for multi-NIC (multiple network interface cards) environments, ensuring correct NIC selection for outgoing connections and UDP broadcasts; (2) improved UDP discovery logic to broadcast and listen on all available interfaces; and (3) better error handling and logging for network operations. These changes make the system more resilient and discoverable in complex network setups.

Network interface selection and connection improvements:

  • Added logic to automatically detect and bind to the correct local NIC for outgoing ZeroMQ TCP connections, using the OS routing table to select the optimal source IP. Both Python and Unity clients now use the extended ZeroMQ TCP format (tcp://source_ip:0;dest_host:port) when appropriate, ensuring traffic uses the right interface. [1] [2] [3]

UDP discovery enhancements:

  • Updated UDP discovery to create and use one socket per physical NIC, broadcasting discovery messages on all interfaces. This allows servers on any reachable subnet to be found, and ensures responses are received on all NICs. Legacy single-socket fields are maintained for backward compatibility. [1] [2] [3]
  • Improved the UDP broadcast logic to compute and use the correct directed broadcast address for each NIC, increasing the likelihood of discovery in segmented networks. [1] [2]

Error handling and logging:

  • Added more robust error handling for socket creation, binding, sending, and receiving, with clear debug or warning logs for failures and fallbacks. This helps with diagnosing network issues and understanding discovery behavior. [1] [2] [3] [4]
  • Enhanced log output to indicate the number of interfaces used for discovery and connection attempts, aiding in debugging multi-NIC scenarios. [1] [2]

Code organization and maintainability:

  • Refactored and centralized network utility functions (e.g., for source address resolution and broadcast address calculation) into utility modules/classes for reuse and clarity. [1] [2]

These improvements collectively make the NetSync system more robust in real-world, multi-network environments, and easier to maintain and debug.

Close #359

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Python NetSync client to better support multi-NIC environments by (a) selecting the correct local source IP for outbound ZeroMQ connections and (b) broadcasting/listening for UDP discovery across multiple NIC-bound sockets.

Changes:

  • Add source-NIC auto-detection and build ZeroMQ “extended TCP” connect addresses when a non-local destination is used.
  • Refactor UDP discovery to create one socket per local interface and broadcast discovery messages on each.
  • Add directed broadcast address calculation (per local IP) for improved discovery reachability.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@from2001 from2001 merged commit 5f7efe9 into develop Mar 14, 2026
@from2001 from2001 deleted the feature/support-multiple-nics-for-python-client branch March 14, 2026 07:32
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.

Multiple NICs support

2 participants