本文整理汇总了C++中message_ptr::get_payload方法的典型用法代码示例。如果您正苦于以下问题:C++ message_ptr::get_payload方法的具体用法?C++ message_ptr::get_payload怎么用?C++ message_ptr::get_payload使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类message_ptr
的用法示例。
在下文中一共展示了message_ptr::get_payload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_message
void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) {
client::connection_ptr con = sip_client.get_con_from_hdl(hdl);
std::cout << "Received a reply:" << std::endl;
fwrite(msg->get_payload().c_str(), msg->get_payload().size(), 1, stdout);
received=true;
}
示例2: on_message
void on_message(connection_ptr con, message_ptr msg) {
if (con->get_resource() == "/getcasecount") {
std::cout << "detected " << msg->get_payload() << " test cases." << std::endl;
m_case_count = atoi(msg->get_payload().c_str());
} else {
con->send(msg->get_payload(),msg->get_opcode());
}
}
示例3: on_message
void Handler::on_message(connection_ptr con, message_ptr msg)
{
if (msg->get_opcode() != websocketpp::frame::opcode::TEXT)
return;
Log::debug("client <%s>: <message> %s", plain(con).c_str(),
msg->get_payload().c_str());
publish(format_message(msg->get_payload()));
}
示例4: on_message
void chat_server_handler::on_message(connection_ptr con, message_ptr msg) {
if (msg->get_opcode() != websocketpp::frame::opcode::text) {
return;
}
std::cout << "message from client " << con << ": " << msg->get_payload() << std::endl;
// check for special command messages
if (msg->get_payload() == "/help") {
// print command list
con->send(encode_message("server","avaliable commands:<br /> /help - show this help<br /> /alias foo - set alias to foo",false));
return;
}
if (msg->get_payload().substr(0,7) == "/alias ") {
std::string response;
std::string alias;
if (msg->get_payload().size() == 7) {
response = "you must enter an alias.";
con->send(encode_message("server",response));
return;
} else {
alias = msg->get_payload().substr(7);
}
response = m_connections[con] + " is now known as "+alias;
// store alias pre-escaped so we don't have to do this replacing every time this
// user sends a message
// escape json characters
boost::algorithm::replace_all(alias,"\\","\\\\");
boost::algorithm::replace_all(alias,"\"","\\\"");
// escape html characters
boost::algorithm::replace_all(alias,"&","&");
boost::algorithm::replace_all(alias,"<","<");
boost::algorithm::replace_all(alias,">",">");
m_connections[con] = alias;
// set alias
send_to_all(serialize_state());
send_to_all(encode_message("server",response));
return;
}
// catch other slash commands
if ((msg->get_payload())[0] == '/') {
con->send(encode_message("server","unrecognized command"));
return;
}
// create json message to send based on msg
send_to_all(encode_message(m_connections[con],msg->get_payload()));
}
示例5: on_message
void websocketIO::on_message(websocketpp::connection_hdl hdl, message_ptr msg) {
boost::property_tree::ptree json;
std::istringstream iss(msg->get_payload());
boost::property_tree::read_json(iss, json);
std::string func = json.get<std::string> ("func");
if(messages.find(func) != messages.end()){
messages[func](this, msg->get_payload());
}
}
示例6: on_message
void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) {
client::connection_ptr con = c->get_con_from_hdl(hdl);
if (con->get_resource() == "/getCaseCount") {
std::cout << "Detected " << msg->get_payload() << " test cases."
<< std::endl;
case_count = atoi(msg->get_payload().c_str());
} else {
c->send(hdl, msg->get_payload(), msg->get_opcode());
}
}
示例7: on_message
void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
std::cout << "on_message called with hdl: " << hdl.lock().get()
<< " and message: " << msg->get_payload()
<< std::endl;
try {
s->send(hdl, msg->get_payload(), msg->get_opcode());
} catch (const websocketpp::lib::error_code& e) {
std::cout << "Echo failed because: " << e
<< "(" << e.message() << ")" << std::endl;
}
}
示例8: onMessage
void WebClient::onMessage(Client* c, websocketpp::connection_hdl hdl, message_ptr pMsg) {
Client::connection_ptr con = c->get_con_from_hdl(hdl);
std::string res_s = con->get_resource();
if (res_s != "/codenjoy-contest/ws?user=" + userName) {
res_s = "WebClient::onMessage(...) Server answer is not right: " + res_s;
throw std::runtime_error(res_s.c_str());
}
std::string buffer_got = pMsg->get_payload();
String boardString;
#ifdef _WIN32
boardString.resize(MultiByteToWideChar(CP_UTF8, 0, &buffer_got[0], buffer_got.length(),
NULL, 0));
MultiByteToWideChar(CP_UTF8, 0, &buffer_got[0], buffer_got.length(),
&boardString[0], boardString.capacity());
#else //Assume linux
boardString = buffer_got;
#endif
if (boardString.substr(0, 6) == LL("board=")) {
boardString = boardString.substr(6, boardString.length() - 6);
while (*boardString.rbegin() == LL('\0')) {
boardString.pop_back();
}
Board b(boardString);
String answer = solver->get(b);
std::string utf_answer;
#ifdef _WIN32
utf_answer.resize(WideCharToMultiByte(CP_UTF8, 0, &answer[0], answer.length(),
NULL, 0, NULL, NULL));
WideCharToMultiByte(CP_UTF8, 0, &answer[0], answer.length(),
&utf_answer[0], utf_answer.capacity(), NULL, NULL);
if (utf_answer == "") { // This happens if bomberman's still dead
if (answer != LL("")) {
throw std::runtime_error("WebClient::onMessage(...): Conversion from Char to utf8 error!");
}
return;
}
#else // Assume linux
utf_answer = answer;
#endif
pMsg->set_opcode(websocketpp::frame::opcode::text);
pMsg->set_payload(utf_answer);
std::cout << "Sending ACTION: " << pMsg->get_payload() << std::endl;
websocketpp::lib::error_code err;
c->send(hdl, pMsg->get_payload(), pMsg->get_opcode(), err);
}
}
示例9: on_message
void websocket_server::on_message(ws_socket* socket_, websocketpp::connection_hdl hdl, message_ptr msg) {
if(msg->get_payload() == "CC"){
cc_hdl_ = hdl;
clientConnected = true;
BOOST_LOG_TRIVIAL(info) << "Control Center connected via websocket";
}
else if (msg->get_payload() == "AL"){
al_hdl_ = hdl;
proxyConnected = true;
BOOST_LOG_TRIVIAL(info) << "Al-Proxy connected via websocket";
}
}
开发者ID:flair2005,项目名称:gesture-recognition-for-human-robot-interaction,代码行数:14,代码来源:websocket_server.cpp
示例10: on_message
void on_message(connection_ptr con, message_ptr msg) {
if(msg->get_payload()=="skeleton") {
con->send(getImageData(),msg->get_opcode());
} else if(msg->get_payload()=="depth") {
con->send(getDepthMap(true),msg->get_opcode());
} else if(msg->get_payload()=="rgb") {
con->send(getRGBImage(true),msg->get_opcode());
} else if(msg->get_payload()=="savergb") {
con->send(saveRGBImage(),msg->get_opcode());
} else if(msg->get_payload()=="savedepth") {
con->send(saveDepthMap(),msg->get_opcode());
} else {
con->send("Unknown client request",msg->get_opcode());
}
}
示例11: rcvMessage
void WSConnection::rcvMessage (message_ptr msg, bool& msgRejected, bool& runQueue)
{
ScopedLockType sl (m_receiveQueueMutex);
if (m_isDead)
{
msgRejected = false;
runQueue = false;
return;
}
if ((m_receiveQueue.size () >= 1000) || (msg->get_payload().size() > 1000000))
{
msgRejected = true;
runQueue = false;
}
else
{
msgRejected = false;
m_receiveQueue.push_back (msg);
if (m_receiveQueueRunning)
runQueue = false;
else
{
runQueue = true;
m_receiveQueueRunning = true;
}
}
}
示例12: on_message
// Define a callback to handle incoming messages
void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
try {
s->send(hdl, msg->get_payload(), msg->get_opcode());
} catch (const websocketpp::lib::error_code& e) {
}
}
示例13: on_message
void on_message(ws_client* c, leveldb::DB* db,
websocketpp::connection_hdl hdl, message_ptr msg) {
static int count = 0;
ws_client::connection_ptr con = c->get_con_from_hdl(hdl);
cout << "Received: " << msg->get_payload() << endl;
leveldb::WriteOptions opts;
stringstream key;
key << (count++);
db->Put(opts, key.str(), msg->get_payload());
// if (con->get_resource() == "/getCaseCount") {
// std::cout << "Detected " << msg->get_payload() << " test cases."
// << std::endl;
// case_count = atoi(msg->get_payload().c_str());
// } else {
// c->send(hdl, msg->get_payload(), msg->get_opcode());
// }
}
示例14: on_message
// Define a callback to handle incoming messages
void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
std::cout << "on_message called with hdl: " << hdl.lock().get()
<< " and message: " << msg->get_payload()
<< std::endl;
// check for a special command to instruct the server to stop listening so
// it can be cleanly exited.
if (msg->get_payload() == "stop-listening") {
s->stop_listening();
return;
}
try {
s->send(hdl, msg->get_payload(), msg->get_opcode());
} catch (const websocketpp::lib::error_code& e) {
std::cout << "Echo failed because: " << e
<< "(" << e.message() << ")" << std::endl;
}
}
示例15: on_message
// Define a callback to handle incoming messages
void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
std::cout << " and message: " << msg->get_payload() <<std::endl ;
std::cout << " opcode " << msg->get_opcode() <<std::endl ;
// s->send(hdl, msg->get_payload(), msg->get_opcode());
const char* msge = "{\"GESTURE\":\"Move Left\"}";
s->send(hdl, msge, websocketpp::frame::opcode::text);
}