doujia5863 2016-07-22 01:49
浏览 18

使用套接字实时更新计算机统计信息到网站

End Goal: We want our CPU meter on our website to update live as we retrieve CPU % from C++ client via sockets.

My friend and I didn't exactly know which to use to accomplish this task, have AJAX or Sockets via PHP to request the CPU usage from my C++ application and update the meter on the website with whatever value is received from the client.

Is there any other way to update the website in real time after it's been already loaded other than AJAX? If not, should the website request the information from the client via sockets and then store it to a variable and pass to AJAX to update the element?

Your help is highly appreciated :) We are working on a energy efficiency project for school. (I'm in school for C++, and he is in for web development)

  • 写回答

1条回答 默认 最新

  • drqvsx1228 2016-07-22 02:05
    关注

    BROWSER [with ajax] --> Webserver [PHP script that calls the C++ Application]

    [ Browser]   [apache that hosts your php app]   [C++] 
        |           |                                 |
        |---(1)---->|----------(2)------------------->|
        |<----------|<--------------------------------|
    

    (1): ajax calls periodic with setIntervall() in javascript

    (2): exec() function in php that calls a system script that is called whenever you receive an ajax call .. whatever the result of the exec command can be wrapped in a json format and sent back to the browser.

    *: the other way to do is more advanced using websockets: Using rabbitmq (message brocker) and socketio server + socketio javascript client .. but it is "over engineered" for your use case, if you are interested to know more about I will be happy to explain in details.

    Sorry i tried to make it clear .. i hope it helps !

    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败