-1

I am making an app with flutter frontend and python backend. The problem is that I need to create a flask server running offline locally on an Android or iOS device. I don't know how to start the server simultaneously with the app to push some http requests to the server.

The server is basically:

from flask import Flask, request, jsonify
import socket
import threading
import paramiko

app = Flask(__name__)

@app.route('/function_name', methods=['POST'])
def function():

....

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Jan
  • 50
  • 6
  • [This](https://stackoverflow.com/questions/18809214/running-an-android-phone-as-a-stable-webserver-for-a-python-cgi-script) may be appropriate answer, but it's still very uncommon and I think you will have problems with that. Is there any reason you do not start your server on local machine and use 192.168.X.X network? – sudden_appearance Apr 23 '23 at 20:08
  • This is just a sketch. I just wanted to provide some code for better understanding. The big deal for now is the principle itself. – Jan Apr 23 '23 at 20:12

1 Answers1

0

Yes you can do that although not recommended as it may consume a lot of resources.

Install Pydroid 3 app from play store. In the app install flask by typing

pip install flask

write your app and run 'python app.py' or whatever name your app is called

on your phone browser, use http://localhost:5000 and here you go.

On ios, there is no app equivalent to Pydroid 3 so you need to use a cloud based platform such as PythonAnywhere.

Elie Saad
  • 516
  • 4
  • 8