#include "MOOS/libMOOS/Comms/MOOSAsyncCommClient.h"
bool OnConnect(void* pParam){
CMOOSCommClient *pC=reinterpret_cast<CMOOSCommClient*>(pParam);
pC->Register("Greeting",0.0);
return true;
}
//用于SetOnmailCallBack()初始化,作为回调
//邮件一来就调用该函数
bool Onmail(void * pParam){
CMOOSCommClient *pC=reinterpret_cast<CMOOSCommClient*>(pParam);
MOOSMSG_LIST M;
pC->Fetch(M);
MOOSMSG_LIST::iterator q;
for(q=M.begin();q!=M.end();q++){
q->Trace();
}
return true;
}
int main(int argc,char *argv[]){
MOOS::MOOSAsyncCommClient Comms;
//设置用户提供的邮件到来的回调函数,不常用,一般在用户线程取邮件
Comms.SetOnMailCallBack(Onmail,&Comms);
Comms.SetOnConnectCallBack(OnConnect,&Comms);
Comms.Run("localhost",9000,"EX20");
for(;;){
MOOSPause(1000);
Comms.Notify("Greeting","Hello");
}
return 0;
}
原文:https://www.cnblogs.com/jingshikongming/p/8971952.html