-2

My flask app has a router as shown below:

@app.route('/test', methods=['GET'])
def testfunction():
    return("Hello world")

when I try to reach it from my pc (which is the host of the app) it runs up as shown below: by typing: http://<My_IP_Address>:5000/test

enter image description here

But when I try to reach the same app from my smart phone browser, it says this site can't be reached connection timed out.

my main code snippet is as shown below:

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=5000)

I solved the problem from changing IPV4 Address of ethernet adapter to Wireless LAN Adapter IPV4 address. Does anyone know why was this happening? And what's the right IP address to use to enable your app listen globally

Note that I am using windows system. This is my ipconfig result. Which IP should I use? enter image description here

Shivam Sahil
  • 4,055
  • 3
  • 31
  • 62
  • What WSGI Server are you using? Is it suited for development or production? – Seyi Daniel Aug 13 '20 at 19:30
  • Hmm I see... Actually I didn't use any WSGI server, my bad I thought allowing the port and running the app will automatically allow it to be discovered globally. – Shivam Sahil Aug 14 '20 at 08:55

1 Answers1

1

On Windows, you can go to cmd > ipconfig > IP Address, you can get your machine's IP Address. Should be something like: 192.168.x.x.

On a Mac, go to System Prefs > Network. There, you'll see a sentence that says "Status: Connected. Wi-Fi is connected to and has the IP address 192.168.x.x.".

Change your host to that IP, then navigate to 192.168.x.x:5000 and you should connect.

After reading your edit... Your phone cannot see your ethernet adapter, as it is 2 steps away. But it can see your computer, as both are connected to the wi-fi and see each other as siblings on the same network.

GAEfan
  • 11,244
  • 2
  • 17
  • 33