dpn517111 2018-08-17 14:49
浏览 132

将文件从一个服务器发布到另一个

I have an Apache server A set up that currently hosts a webpage of a bar chart (using Chart.js). This data is currently pulled from a local SQLite database every couple seconds, and the web chart is updated.

I now want to use a separate server B on a Raspberry Pi to send data to the server to be used for the chart, rather than using the database on server A.

So one server sends a file to another server, which somehow realises this and accepts it and processes it.

The data can either be sent and placed into the current SQLite database, or bypass the database and have the chart update directly from the Pi's sent information.

I have come across HTTP Post requests, but not sure if that's what I need or quite how to implement it.

I have managed to get the Pi to simply host a json file (viewable from the external ip address) and pull the data from that with a simple requests.get('ip_address/json_file') in Python, but this doesn't seem like the most robust or secure solution.

Any help with what I should be using much appreciated, thanks!

  • 写回答

1条回答 默认 最新

  • drrrdo0802 2018-08-17 15:02
    关注

    Maybe I didn't quite understand your request but this is the solution I imagined:

    1. You create a Frontend with WebSocket support that connects to Server A
    2. Server B (the one running on the raspberry) sends a POST request with the JSON to Server A
    3. Server A accepts the JSON and sends it to all clients connected with the WebSocket protocol

    Server B ----> Server A <----> Frontend

    This way you do not expose your Raspberry directly and every request made by the Frontend goes only to Server A.

    To provide a better user experience you could also create a GET endpoint on Server A to retrieve the latest received JSON, so that when the user loads the Frontend for the first time it calls that endpoint and even if the Raspberry has yet to update the data at least the user can have an insight of the latest available data.

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)