0

I've got an app that connects to a wifi access point, then connects to a local server on port 50,000. Works fine on API < 29. But in 29, I have to use ConnectivityManager instead of WifiManager. Got that working no problem. The problem is connecting to the server afterwards. The device acts like port 50,000 is closed, yet I have other devices right here that are connecting without problem. But if I tell the device to connect to the same server on port 80 (which is also open), boom, instant connection. So I am connected to the access point and the server is accessible, I just can't get it to connect to 50,000. Is there some special permission I need to request to access ports >1024 maybe? I tried adding the internet permission to my manifest, but if I add the capability NetCapability.Internet then the callback gets instantly called with OnUnavailable. Doesn't even try. I've also got capabilities NotRestricted and Trusted in there too. Anyone know what I'm missing here?

drussell
  • 11
  • 2
  • If you are making the connection from the App to a server there shouldn't be any limitation to which port you are accessing. However, when you say local server, what do you mean? Local on the device? Local on the WiFi network you are connected to? Can you connect to this local server using a different device, such as a PC? Maybe the network you are connecting to has a limitation? – Cheesebaron Feb 06 '20 at 22:33
  • A local PC on the wifi network. And I figured it out, although I still don't know how it let me access port 80 and not 50,000. After the wifi successfully switches, you gotta call ConnectionManager.BindProcessToNetwork(). Everything works fine now. – drussell Feb 06 '20 at 23:15
  • Well, some Android devices have these "smart WiFi" features, where it tries handing over traffic if it thinks the network you are connected to is bad. That is probably what is happening. – Cheesebaron Feb 07 '20 at 06:39

1 Answers1

1

After the wifi switch succeeds and OnAvailable gets called, you must call ConnectivityManager.BindProcessToNetwork().

drussell
  • 11
  • 2