0

I created a sample app, with just 3 buttons, Connect , send msg, disconnect. I am using TCP server on another mobile B, (any available tcp server app or test tool app). and our client app is on mobile A.

Case 1. Both the Mobile A & B, are on same wifi network, app is working fine (connect, disconnect) if both have same internet or does not have any internet over wifi, and client device does not have internet availability on other network, like 4g.

Working


Case 2. Both the Mobile are on same wifi network, but in client app device, Mobile A has 4g connection with internet available, now the app is not connecting with tcp server over wifi network. this wifi network does not have internet connectivity.

Not Working

so case 2 is not working. If devices are on same wifi, and client has other 3g/4g working internet , the app is not connecting over wifi.

Indra KP
  • 293
  • 1
  • 2
  • 16
  • That has to do with how the mobile is deciding to route your packets and what transport to use. If it uses only WiFi, then you can reach your server on your local network, but if it chooses to use 3g/4g, then that comes from outside your LAN and it can't reach your server. – jfriend00 Aug 04 '18 at 06:30
  • In any real world app, I presume your app would be accessible from the general internet and thus over 3g/4g so is this really a real-world problem or are you just curious why it's doing this? – jfriend00 Aug 04 '18 at 06:31
  • Generally, phone's software will pick a connection with internet over a connection with no internet. In your case, the higher layer software does not know that no internet wifi connection is needed to be used for your use case. Also, while using 3g/4g internet available connection it seems like Mobile A is not able to reach mobile B. If you want phone to pick wifi over 4G, enable internet connectivity in your wifi connection or disable 3g/4g while you use your (test?) app. – Viral Modi Aug 04 '18 at 06:39
  • @jfriend00, you are correct. the mobile device will always check for available internet, but my question is, socket should work within same LAN/WAN. So in mentioned case its not working, i guess we have to modify default behaviour, like socket connection should not go over mobile internet, it should choose wifi network for connection. – Indra KP Aug 04 '18 at 07:04
  • But we have only single line of code, new Socket(ip,port), and internally mobile os is selecting the network. that i am not sure how i can do. – Indra KP Aug 04 '18 at 07:05
  • You can programmatically turn off 3g/4g before you connect and then re-enable 3g/4g after TCP connection successful. Refer https://yous.be/2013/12/07/how-to-check-and-toggle-wifi-or-3g-4g-state-in-android/ to enable disable 3g/4g in code. – Viral Modi Aug 04 '18 at 08:00
  • yes, i did already but in case user closed the app in between tcp communication, we have to handle other cases. that even not possible to re-enable if user directly close the app by swipe. I think better to specify the preffered network for tcp should be over wifi. I am trying to find that solution. – Indra KP Aug 04 '18 at 08:11
  • If your question is really, "How do I specify what network to use when connecting a socket in node.js when there is more than one network connection?", then you should edit your question to say that and perhaps this is what you want: [How to specify a network interface when making net requests from Node.js?](https://stackoverflow.com/questions/13602066/how-to-specify-a-network-interface-when-making-net-requests-from-node-js) or [Performat request using specific network interface in node.js](https://stackoverflow.com/questions/42767631/perform-request-using-specific-network-interface) – jfriend00 Aug 04 '18 at 22:28
  • That issue is still issue today in 2021. – Goran_Ilic_Ilke Nov 02 '21 at 14:01

0 Answers0