getnamo/UDP-Unreal

How to specify a network adapter to send a UDP broadcast?

Closed this issue · 3 comments

I have a network adapters that has four separate Ethernet ports (e.g. eth0, eth1, eth2, eth3) and all the ports have different IP address. Is it possible to specify port that I want to communicate on?

I don't think this is supported in the plugin atm, you may want to identify the lower level Unreal call required on the ISocketSubsystem to select an adapter (see e.g. https://docs.unrealengine.com/4.27/en-US/API/Runtime/Sockets/ISocketSubsystem/GetLocalAdapterAddresses/) and when you've identified the calls required, make a pull request here with code changes and I'll merge the feature support.

You don't select an adapter. That is up to the operating system to decide. What you can do is decide which IP address to send and receive from. The OS will figure out which adapter to use from the IP.

The plugin already supports setting a receive IP. By default it is set to 0.0.0.0 which generally functions as an 'any' address. If you set it to one of your 4 IPs it should only accept traffic from that Ethernet port.

I am not 100% sure what the send behavior is. Generally the underlying socket implementations are pretty clever about making sure they bind to an adapter that can route to your sending IP. So if all of your adapters have IPs with different subnets, setting different send IPs should be enough to make sure traffic goes out of each of them. If they all share a subnet then you are going to have to make some code changes and add a BindtoEndpoint line to the send socket setup here:
https://github.com/getnamo/UDP-Unreal/blob/master/Source/UDPWrapper/Private/UDPComponent.cpp#L169

Similar to what the receive socket setup has here:
https://github.com/getnamo/UDP-Unreal/blob/master/Source/UDPWrapper/Private/UDPComponent.cpp#L263

@gstorer
Thank you for your detailed response. I have resolved by setting SendIP and ReceiveIP manually.