【问题标题】:About a local connection between Flutter and Python关于 Flutter 和 Python 之间的本地连接
【发布时间】:2020-10-22 12:37:19
【问题描述】:

我想将 Flutter 与 Python 后端连接起来。 ML models using flaskonline tutorials等几个教程建议使用FLASK的REST-API来连接Flutter和Python。

通常使用 FLASK 创建一个 localhost,flutter 应用通过 http 包获取信息。

我需要创建一个flutter-python连接,它是非常安全和本地的,也就是说,当App发布时,Python功能可能不在服务器上,而是在手机上。

是否可以在手机上实现运行Flutter前端初始化Flask后端的流程?

【问题讨论】:

    标签: python flutter


    【解决方案1】:

    我做了一些研究并找到了答案,希望能将您引向正确的道路。解决方案看起来很相似。告诉我!

    https://stackoverflow.com/a/62308032/14514188

    https://github.com/rikulo/socket.io-client-dart#usage-flutter

    In Flutter env. it only works with 
    dart:io websocket, 
    not with  
    dart:html websocket, 
    
    
    
    

    所以在这种情况下,您必须在创建套接字实例时添加 'transsports': ['websocket']。

    IO.Socket socket = IO.io('http://localhost:3000', <String, dynamic>{
        'transports': ['websocket'],
        'extraHeaders': {'foo': 'bar'} // optional
    });
    The default Flask development server doesn't support websockets so you'll need to use another server. Thankfully it's simple to get eventlet working with Flask. All you should have to do is install the eventlet package using pip.
    

    pip 安装小事件 一旦安装了 eventlet,socketio 将在运行服务器时检测并使用它。

    You can use chrome to double check what transport method is being used. Open your chrome dev tools Ctrl+Shift+I in Windows and go to the Network tab. On each network request you should see either transport=polling or transport=websocket
    

    https://stackoverflow.com/a/62308032/14514188

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 2020-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-05
      • 1970-01-01
      相关资源
      最近更新 更多