本文整理汇总了C++中SocketPtr::send_data方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketPtr::send_data方法的具体用法?C++ SocketPtr::send_data怎么用?C++ SocketPtr::send_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketPtr
的用法示例。
在下文中一共展示了SocketPtr::send_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: info
void
send_data( const SocketPtr &in_socket, const std::string &in_msg ) {
if( in_socket->get_is_connected() )
{
MemInfo info( in_msg.c_str(), in_msg.length() + 1 );
in_socket->send_data( info );
}
}
示例2: reply
void
DataServer::on_data_received(
const SocketPtr &in_socket, const MemInfo &in_msg ) {
const DataServiceMessage *pMsg
= reinterpret_cast<const DataServiceMessage *>(
in_msg.get_data());
DataServiceMessage reply( DATA_SERVICE_GENERAL_REPLY );
bool status = false;
switch( pMsg->m_header.m_type ) {
case DataMessageType::DATA_SERVICE_REGISTER:
{
std::string buf = pMsg->m_data;
std::istringstream ifs( buf );
boost::archive::text_iarchive ia( ifs );
ServiceRequestData data;
ia & data;
status = on_service_register_request(
data.m_service_name,
data.m_hostname, data.m_port );
break;
}
case DataMessageType::DATA_SERVICE_UNREGISTER:
{
std::string buf = pMsg->m_data;
std::istringstream ifs( buf );
boost::archive::text_iarchive ia( ifs );
ServiceRequestData data;
ia & data;
status = on_service_unregister_request(
data.m_service_name,
data.m_hostname, data.m_port );
break;
}
case DataMessageType::DATA_SERVICE_INFO_REQUEST:
{
std::string buf = pMsg->m_data;
std::istringstream ifs( buf );
boost::archive::text_iarchive ia( ifs );
ServiceRequestData data;
ia & data;
ServiceInfoPtr info;
status = on_service_info_request( data.m_service_name, info );
if( info ) {
std::ostringstream sout;
boost::archive::text_oarchive oa(sout);
oa & info;
std::strncpy( reply.m_data,
sout.str().c_str(), sout.str().size());
}
reply.m_header.m_type = DATA_SERVICE_INFO_REPLY;
break;
}
default:
{
}
}
reply.m_status = status;
MemInfo replyMsg( reinterpret_cast<char *>( &reply ),
sizeof( DataServiceMessage ) );
in_socket->send_data( replyMsg );
}