简体   繁体   中英

Connecting through TCP to 0.0.0.0 on Wi-Fi while the listener PC has active Wi-Fi and Ethernet doesn't work

I'm creating a TCP connection from a device on Wi-Fi to a computer that's listening on port 0.0.0.0:44440.

When I am only on Wi-Fi, the device is able to connect without a problem. When I enable / plug in Ethernet, the listener never accepts the device's connection request. (Wi-Fi is still connected throughout this process. Checked by ipconfig)

I'm using C++, and the command looks like this:

handle = (int)accept(listening_socket->handle, (struct sockaddr *)&address, &addrlen);

The command gets a handle when a device connects if both are on Wi-Fi only, but continues blocking if the listener is on both Ethernet and Wi-Fi.

0.0.0.0 is supposed to be interface-ambiguous, so it should accept connections from both Ethernet (192.168.xx) and Wi-Fi (10.161.xx), but it seems to 'attach' to the interface that is giving the best internet. Checking using "netstat -an", there is an active listener on 0.0.0.0:44440 using each method.

Anyone a pro at networking and know why having multiple running interfaces messes with this?

.

Extra Info

I have done many checks to make sure Wi-Fi and Ethernet are enabled. I am running a UDP broadcast over both interfaces that tells devices to connect to the local computer. So the broadcast contains a message of "192.168.xx:44440" for devices running on local network and "10.161.xx:44440" for devices running on Wi-Fi. The device picks up this message and then tries to form a TCP connection on "10.161.xx:44440." When the computer is only connected through Wi-Fi, connecting like this works. When it's connected through both, the listener running on port 44440 never detects when the device connects. It will still connect local programs running on the same machine from either IP.

Also note, my Ethernet is not the same network as my Wi-Fi (for security reasons). So each network has separate properties

When I connected Ethernet, it reset my Wi-Fi to a public Wi-Fi rather than private. That didn't allow the TCP connection because sharing was now disabled. Though it allowed a UDP connection, which is interesting to me. So if you run into this, make sure your Wi-Fi has network sharing on!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM