paper3—Algorithm2-Engine-Trigger-on-SMD—temp

//source code: /run/media/root/E6B2798BB279614B/.../PAPER/paper-3/twin-engine-trigger-code/server-client-pthread-c
----------------------------------------------------------------------------------

Description: guest access FCD by using SMD, there are two parts: browser on SMD and daemon written in c language

//browser on SMD:
guest access server on FCD by using browser on SMD;
socket();  //use WebSocket
connect(); //connect to daemon on SMD
send username to daemon WAIT on the same SMD;
executing tasks in brower; // take some time
if finish tasks then
  send finish=1 to daemon WAIT on the same SMD;
end if

//---------------------------------------------------------

//daemon WAIT on SMD that waiting data sent by brower
PROCEDURE: WAIT
socket();
bind();
recvfrom();
if receive username from browser then
  write username to pipe;
end if
if receive finish=1 from browser then
  write finish=1 to pipe; // send to daemon MAIN
end if
END PROCEDURE

//daemon MAIN on SMD
PROCEDURE: MAIN
socket();
connect(); //connect to TCP Socket on FCD;
//fcdtime: time of sending heartbeat to FCD last;
fcdtime = currenttime;
pthread_create(WAIT); //daemon WAIT on SMD

while true do
  read from pipe; //receive from daemon WAIT
  if read username from pipe then
    send heartbeat to FCD;
    send username, processid to FCD;
    if receive heartbeat from FCD then
      SMD receive current process information from FCD;
      update correlative tables in database;
    end if
    period = currenttime - fcdtime;
 
    if period < 5 then  //connectiong to FCD is normal
      fcdtime = currenttime;
    else if period > 30 then //server shutdown or connectiong to FCD is abnormal
      trigger SMD;
      redirect to localhost and invoke task in SMD
      while true do
        send heartbeat to FCD; //probe whether FCD is active
        if receive heartbeat from FCD then
          read from pipe; //receive from daemon WAIT
          if finish=1 then
            send finish to FCD;
            send information for current process to FCD;
            exit;
          else
            stop accessing MPE;
            send information for current process to FCD;
            sleep 3s; //waiting for FCD to update it's database
            trigger FCD;
            redirect to FCD and invoke task in FCD;
          end if
        end if
        sleep 60s;
      done //end while
    end if
  else if read finish=1 from pipe
    send finish to FCD;
    send information for current process to FCD;
    exit;
  end if
  sleep 5s; //send heartbeat request every 5s to FPE
done
END PROCEDURE
posted @   张同光  阅读(115)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示