本文整理汇总了C++中TestClient::sendAndReceiveMsg方法的典型用法代码示例。如果您正苦于以下问题:C++ TestClient::sendAndReceiveMsg方法的具体用法?C++ TestClient::sendAndReceiveMsg怎么用?C++ TestClient::sendAndReceiveMsg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestClient
的用法示例。
在下文中一共展示了TestClient::sendAndReceiveMsg方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: spinner
TEST(DISABLED_MessageManagerSuite, tcp)
{
const int port = TEST_PORT_BASE + 201;
char ipAddr[] = "127.0.0.1";
TestClient* client = new TestClient();
TestServer server;
SimpleMessage pingRequest, pingReply;
MessageManager msgManager;
// MessageManager uses ros::ok, which needs ros spinner
ros::AsyncSpinner spinner(0);
spinner.start();
ASSERT_TRUE(pingRequest.init(StandardMsgTypes::PING, CommTypes::SERVICE_REQUEST, ReplyTypes::INVALID));
// TCP Socket testing
// Construct server
ASSERT_TRUE(server.init(port));
// Construct a client
ASSERT_TRUE(client->init(&ipAddr[0], port));
// Connect server and client
pthread_t serverConnectThrd;
pthread_create(&serverConnectThrd, NULL, connectServerFunc, &server);
ASSERT_TRUE(client->makeConnect());
pthread_join(serverConnectThrd, NULL);
// Listen for client connection, init manager and start thread
ASSERT_TRUE(msgManager.init(&server));
// TODO: The message manager is not thread safe (threads are used for testing,
// but running the message manager in a thread results in errors when the
// underlying connection is deconstructed before the manager
//boost::thread spinSrvThrd(boost::bind(&MessageManager::spin, &msgManager));
pthread_t spinSrvThrd;
pthread_create(&spinSrvThrd, NULL, spinFunc, &msgManager);
// Ping the server
ASSERT_TRUE(client->sendMsg(pingRequest));
ASSERT_TRUE(client->receiveMsg(pingReply));
ASSERT_TRUE(client->sendAndReceiveMsg(pingRequest, pingReply));
// Delete client and try to reconnect
delete client;
sleep(10); //Allow time for client to destruct and free up port
client = new TestClient();
ASSERT_TRUE(client->init(&ipAddr[0], port));
ASSERT_TRUE(client->makeConnect());
ASSERT_TRUE(client->sendAndReceiveMsg(pingRequest, pingReply));
pthread_cancel(spinSrvThrd);
pthread_join(spinSrvThrd, NULL);
delete client;
}