TCPSocket.NetworkInterface Question

I want to be able to set the NetworkInterface for a TCP socket. When I do that, I want any communication from that socket to go over that interface ONLY. So If I bind to the ethernet interface, I want connections just over that but not over say Wi-Fi. But I am not seeing this happen. Here’s an example:

I have a device that I have connected directly to my laptop via ethernet. It’s IP address is 10.0.10.101. In my software, I bind to the ethernet adapter using the NetworkInterface property of the socket. I then try to connect to the device. The problem is I have another device with the same IP that is on my LAN which I am accessing through WiFi. When I make the connection to what I think is the device connected to the ethernet, it doesn’t happen. The software connects instead to the device on the LAN.

Is this a bug in the NetworkInterface property?

I’m running on OS X at the moment.

Thanks,

Jon

You should make the devices have different networks. My experience is that computers connected to two different networks which have the same IP address ranges always have troubles anyway.

Technically, they are two different networks. One is WiFi and one is a peer to peer connection to a device. Yes, I agree with you about the IPs and it was unintentional when it happened.

However, if I am binding a specific connection to a specific adapter, that means that all connection info and traffic related to that socket should go only over that socket. So it really should not matter if there is a device in each network that has the same IP.

My question still stands: Why is traffic that is bound to a specific interface going over an interface to which the socket is not bound?

Hi Jon,

when you bind to an interface you are not binding to a physical piece of hardware but instead you are binding to the logical network address assigned to the interface.
In your (weird) case you have two different physical interfaces linked to the same logical network with two different devices with the same IP address connected to the same logical network.

Your problem it is completely out of Xojo domain: the IP stack of the OS it is in charge.

Regards.

[quote=118585:@Maurizio Rossi]Hi Jon,

when you bind to an interface you are not binding to a physical piece of hardware but instead you are binding to the logical network address assigned to the interface.

[/quote]

Seriously? Then what good is binding to a specific interface? If I choose a network adapter through which I wish to send my traffic, then that’s where I want to send my traffic. It’s logical to assume I’m binding to the logical network based on my IP address.

Yes, it is a weird case and had I not had the same IP addresses accidentally, I would never have noticed this in all likelihood. But while the networks use the same IP space, they are two different physical networks. And in the use case for my application it is entirely possible that the same address space could be in use on two different physical adapters because it is a configuration tool. So while the location/jobsite may have a particular logical network, the idea is to be able to configure hardware that will be installed in a network prior to it being physically inserted into that network (do you follow?). So a technician may have his laptop on the local LAN of the job site via WiFi and yet he needs to use his ethernet adapter on the laptop to configure the devices that are ultimately going onto that LAN but are not physically installed yet.

Being able to attach to a specific physical NIC is what I was looking to do, but this doesn’t seem possible according to you. It’s not that I don’t believe you but it’s just not logical to bind to a specific adapter card but not really be binding to that card but instead to the logical network. That’s not logical.

[quote]
Your problem it is completely out of Xojo domain: the IP stack of the OS it is in charge.
Regards.[/quote]

Again, it doesn’t make sense, but then the way programmers do things doesn’t make sense either. Some of you probably think I’m loopy for what I’m trying to do as well! :slight_smile:

Jon,

usually binding to a specific address it is useful when a server accepts connection from a specific network and not from all networks available in the system.

As an example if you must accept connection only from clients running on the same system your server binds to the loopback network (127.0.0.1) (you can’t do this with Xojo, there is an already made feature request for this).

With the IP stack the application can’t decide which physical interface to use.
The IP stack exists to mask to the program the physical implementation of the network itself (boards, radio, cables, modem…)

Unfortunately Xojo’s framework has glued IP addresses with network interfaces causing some confusion (as for example in Xojo the loopback network does not exist).

Regards.

[quote=118634:@Maurizio Rossi]Jon,

usually binding to a specific address it is useful when a server accepts connection from a specific network and not from all networks available in the system.
[/quote]

So is binding to an interface really more designed for inbound connections rather than outbound?

Is there any way to tell the application which physical interface to use? Or is it really a limitation of the IP stack itself?

[quote]
Unfortunately Xojo’s framework has glued IP addresses with network interfaces causing some confusion (as for example in Xojo the loopback network does not exist).

Regards.[/quote]

Xoxo doesn’t show all the interfaces either which makes for some headaches too…

Usually “bind” it is used on servers or with sockets not “binded” to a specific address.

Please take a look at for an explanation of the “bind()” function not related to the Xojo framework.