Skip to content

feat: Bind TCP connections to correct local interface for multi-NIC support #352

@tylerkron

Description

@tylerkron

Summary

When connecting to a discovered WiFi device, bind the TCP connection to the same local network interface that discovered the device. This prevents connection issues in multi-NIC scenarios.

Problem

When a system has multiple network interfaces (e.g., Ethernet + WiFi, or multiple WiFi adapters), and different interfaces have routes to the same IP address (192.168.1.1 is common for both home routers and DAQiFi devices in AP mode), TCP connections may be routed through the wrong interface.

Symptoms:

  • Connection timeouts when trying to connect to discovered devices
  • Connections succeeding but to the wrong device (e.g., router instead of DAQiFi)
  • Intermittent connection failures depending on Windows routing table state

Proposed Solution

1. Update DeviceInfoConverter.ToWiFiDevice() to populate LocalInterfaceAddress

Once daqifi/daqifi-core#88 is implemented, update the converter:

public static DaqifiStreamingDevice ToWiFiDevice(CoreDeviceInfo coreInfo)
{
    var deviceInfo = ToDesktopDeviceInfo(coreInfo);
    var device = new DaqifiStreamingDevice(deviceInfo);
    
    // Propagate local interface for TCP binding
    if (coreInfo.LocalInterfaceAddress != null)
    {
        device.LocalInterfaceAddress = coreInfo.LocalInterfaceAddress.ToString();
    }
    
    return device;
}

2. Update DaqifiStreamingDevice.Connect() to bind to local interface

public override bool Connect()
{
    try
    {
        // If we know which local interface discovered this device, bind to it
        if (!string.IsNullOrEmpty(LocalInterfaceAddress))
        {
            var localEndpoint = new IPEndPoint(IPAddress.Parse(LocalInterfaceAddress), 0);
            Client = new TcpClient(localEndpoint);
            AppLogger.Information($"Binding TCP to local interface {LocalInterfaceAddress} for {IpAddress}");
        }
        else
        {
            Client = new TcpClient();
        }
        
        // ... rest of connection logic
    }
}

Dependencies

Context

This was originally part of PR #173, which has been closed because the multi-interface UDP discovery moved to Core. The TCP binding feature needs to be re-implemented once Core provides the local interface information.

Acceptance Criteria

  • DaqifiStreamingDevice has LocalInterfaceAddress property
  • DeviceInfoConverter populates LocalInterfaceAddress from Core's IDeviceInfo
  • DaqifiStreamingDevice.Connect() binds TCP socket to local interface when available
  • Fallback to default behavior when LocalInterfaceAddress is not set
  • Logging indicates which interface is being used for connection

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions