本文整理汇总了C++中NetClient::initClient方法的典型用法代码示例。如果您正苦于以下问题:C++ NetClient::initClient方法的具体用法?C++ NetClient::initClient怎么用?C++ NetClient::initClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetClient
的用法示例。
在下文中一共展示了NetClient::initClient方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
signal(SIGFPE, signal_handler);
init_quote();
//connect socket server
NetClient* ClientHandler = new NetClient();
ClientHandler->initClient(server_ip, server_prot);
ClientHandler->netSocket();
ClientHandler->netConnect();
ClientHandler->verifyLogin();
//start save db pthread
//ClientHandler->start_save_thread();
//start revc data and send msg to topic
ClientHandler->startSendMsg();
//destory active mq
ActiveMqProducer::getInstance()->close();
activemq::library::ActiveMQCPP::shutdownLibrary();
//destory zlog
zlog_fini();
//delete
delete ClientHandler;
return 0;
}
示例2: main
int main()
{
int port = 10088;
int port2 = 5188;
std::string ip = "183.62.250.18";
NetClient* ClientHandler = new NetClient();
ClientHandler->initClient(ip, port);
ClientHandler->netSocket();
ClientHandler->netConnect();
//init mqtt client
mqtt::async_client client(ADDRESS, CLIENTID);
callback cb;
client.set_callback(cb);
mqtt::itoken_ptr conntok = client.connect();
try{
std::cout << "the mqtt waiting for the connection..." << std::flush;
conntok->wait_for_completion();
std::cout << "OK" << std::endl;
}catch (const mqtt::exception& exc) {
std::cerr << "Error: " << exc.what() << std::endl;
}
//test mqtt
std::string test_message = "this is a test meesage...";
mqtt::message_ptr pubmsg = std::make_shared<mqtt::message>(test_message);
pubmsg->set_qos(QOS);
client.publish(TOPIC, pubmsg)->wait_for_completion(TIMEOUT);
//init active mq
std::string brokerURI = "failover:(tcp://101.37.33.121:61616)";
bool useTopic = true;
bool clientAck = false;
std::string topic = "QUOTE.ORG";
activemq::library::ActiveMQCPP::initializeLibrary();
ActiveMqProducer::getInstance()->initProducer(brokerURI, useTopic, clientAck);
//init write file
std::string date = getDate();
std::string filename = date +".log";
std::ofstream out_file(filename, ios::app);
//start recv json data
bool log_flag = ClientHandler->verifyLogin();
std::string str="";
while( log_flag )
{
ClientHandler->recvData( str );
if(!str.empty())
{
std::string tmep_send = str.substr(0, str.length()-1);
ActiveMqProducer::getInstance()->sendMessage(topic, tmep_send);
//write the message to another file
out_file << getDateAndTime() << "[The received data:]" << tmep_send << std::endl << std::endl;
str="";
}
}
std::vector<mqtt::idelivery_token_ptr> toks = client.get_pending_delivery_tokens();
if (!toks.empty())
{
std::cout << "Error: There are pending delivery tokens!" << std::endl;
}
// mqtt disconnect
std::cout << "Disconnecting..." << std::flush;
conntok = client.disconnect();
conntok->wait_for_completion();
std::cout << "OK" << std::endl;
//destory active mq
ActiveMqProducer::getInstance()->close();
activemq::library::ActiveMQCPP::shutdownLibrary();
//delete
delete ClientHandler;
return 0;
}