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


C++ TcpSocket::sendString方法代码示例

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


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

示例1: own_thread

void Client::own_thread()
{
    TcpSocket sock;
    sock.connect( m_host, m_port );

    unsigned int version = 1;
    unsigned int options = 0;

    sock.send( version );
    sock.send( options );
    // first send size of name.
    sock.sendString( m_name );

    unsigned int images = 0;
    unsigned int width = 0;
    unsigned int height = 0;
    unsigned int bpp = 0;
    try
    {
        sock.receive( images );
        sock.receive( width );
        sock.receive( height );
        sock.receive( bpp );
    } catch( std::string a_error )
    {
        std::cerr << a_error << std::endl;
        return ;
    }
    std::cout << "DEBUG: " << "images: " << images << " w: " << width << " h: " << height << " bpp: " << bpp << std::endl;

    std::unique_ptr< sepia::Writer > data = std::unique_ptr< sepia::Writer >( new sepia::Writer( m_name, images, width, height, bpp ) );


    int more = 0; // more data available if true.
    while( !m_terminate )
    {
        for( int i = 0; i < data->getGroupHeader()->count; i++ )
        {
            sock.receive( *data->getHeader( i ) );
            sock.receive( data->getAddress( i ), data->getSize( i ) );
        }
        data->update();
    }
}
开发者ID:SorcererX,项目名称:SepiaStream,代码行数:44,代码来源:client.cpp

示例2: main

int main()
{
    TcpServer server;

    if (server.listen(2000) != AbstractSocket::Done)
    {
        perror("Error :");
        return -1;
    }

    TcpSocket* s = server.accept();

    if (s == NULL)
    {
        cout << "Error: cannot accept conection" << endl;
        return -1;
    }

    cout << "Connected client" << endl;
    int i = 4;
    i++;
    cout << "Remote host : " << s->getRemotePort() << endl;
    cout << s->getLocalPort() << endl;
    cout << server.getRemoteAddress().toString() << endl;
    cout << s->getRemoteAddress().toString() << endl;
    s->sendInt32(10);
    sleep(2);
    s->sendString("hello");
    s->sendCharArray("world", 5);
    Frame f;
    f << "This is a frame " << 666 << '\n';

    if (s->sendFrame(f) != AbstractSocket::Done)
        perror("error on send frame");

    delete s;
    server.close();
    s->close();
    return 1;
}
开发者ID:AnXi-TieGuanYin-Tea,项目名称:CPPWrappers,代码行数:40,代码来源:Server.cpp


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