当前位置: 首页>>代码示例>>C++>>正文


C++ Subscriber::SetAddress方法代码示例

本文整理汇总了C++中Subscriber::SetAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ Subscriber::SetAddress方法的具体用法?C++ Subscriber::SetAddress怎么用?C++ Subscriber::SetAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subscriber的用法示例。


在下文中一共展示了Subscriber::SetAddress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc,char**argv)
{
 int port=5566;
 string address="127.0.0.1";
  
 printf("This program is going to test:\n");
 printf("   * the dataType consistency\n");
 printf("   * the publisher and subscriber ability to handle it\n");
 printf("   * Port used for the communication is %d.\n",port);
 printf("   * Addressed used for the communication is '%s'.\n",address.c_str());
 printf("   * Logger.\n");
 printf("\n");

 Logger l;

 printf("-> Constructing Publisher\n");
	 Publisher pub;
 printf("-> Constructing Subscriber\n");
	 Subscriber sub;
 //printf("-> Constructing Context\n");
	 //zmq::context_t context(2);

 // ActivateLog
 printf("-> Config Log\n");
	l.SetLogLevel(3);
 	//l.SetAsync();
 	l.SetFileName("/tmp/log.txt");
 	l.Init();
 printf("-> Activate Logs\n");
 	sub.LogInit(&l);
 	pub.LogInit(&l);
 //Configure
 printf("-> Setting port\n");
 	pub.SetPort(port);
 printf("-> Setting port/address\n");
 	sub.SetAddress(address,port);
 //printf("-> Setting Context\n");
 	//pub.SetContext(&context);
 	//sub.SetContext(&context);

 //pub.SetAsync();
 //Init Sockets
 printf("-> Init Publisher\n");
 	pub.Init();
 printf("-> Init subscriber\n");
	sub.Init();

 //Init Mex
 printf("-> Init Mex\n");
	 dataType mexSend, mexRecv;
	 char mex[]="Ciao\0da\0Andrea";
 printf("-> Append to Send\n");
	 mexSend.append((void*)mex,14);

 printf("-> Send Dummy\n");
	int rc=1;
	rc=sub.RecvMessage(mexRecv);
	pub.SendMessage(mexSend);
 printf("-> Recv Dummy\n");
	//while (rc) { rc=sub.RecvMessage(mexRecv); printf("Cycle\n"); sleep(1);}
	rc=sub.RecvMessage(mexRecv);

 printf("-> Send\n");
	 pub.SendMessage(mexSend);
 printf("-> Recv\n");
 	rc=1;
	while (rc) { rc=sub.RecvMessage(mexRecv); printf("Cycle\n"); sleep(2);}


 printf("-> Verify content of size %d == %d\n",mexSend.size(),mexRecv.size());
 if (mexSend == mexRecv)printf(" ------ SUCCESS -------\n");
 else printf(" ------ FAIL -------\n");

 // for(int i=0;i<mexSend.size();i++)
 // {
 //        char c1='\0';
 //        if(i<mexSend.size())c1=((char*)mexSend.data())[i];
 //        char c2='\0';
 //        if(i<mexRecv.size())c2=((char*)mexRecv.data())[i];
 //        printf(" %02X %02X\n",c1,c2);	
 // }
 string toprint=Utility::AsciiData(mexSend.data(),mexRecv.data(),mexSend.size() );
 printf("%s",toprint.c_str());

 sleep(1);
 printf("-> Calling Destructors and exit\n");
}
开发者ID:cmsromadaq,项目名称:H4DAQ,代码行数:87,代码来源:testDataType.cpp


注:本文中的Subscriber::SetAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。