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


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

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


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

示例1: tcpSocketTest

bool SocketTest::tcpSocketTest()
{
    SimpleServer server;
    server.start();
    System::Sleep(500);
    TEST_ASSERT(server.start_flag)
    TEST_ASSERT_MSG(server.bind_flag, server.msg.text())
    TEST_ASSERT_MSG(!server.aborted, server.msg.text())
    // create tcp socket
    TcpSocket client;
    client.connect(TCP_TEST_HOST, TCP_TEST_PORT);
    TEST_ASSERT(client.getRemoteAddress().getPort() == TCP_TEST_PORT);
    client.send(TEST_MESSAGE1);
    TEST_ASSERT_MSG(!server.aborted, server.msg.text())
    System::Sleep(100);
    TEST_ASSERT_MSG(!server.aborted, server.msg.text())    
    TEST_ASSERT(server.msg1_flag)
    // test if something is already running on a port
    Socket psocket;
    TEST_THROWS(psocket.bind(TCP_TEST_PORT), Net::Errors::SocketException);
    
    String in;
    client.readUntil(in, '!');
    TEST_ASSERT(in == TEST_MESSAGE2);
    client.readUntil(in, '.', 2000);
    TEST_ASSERT_MSG(in == TEST_MESSAGE3, in.text());
    client.readUntil(in, '!', 2000);
    TEST_ASSERT(in == TEST_MESSAGE4);
    client.readUntil(in, "#@", 2000);
    TEST_ASSERT(in == TEST_MESSAGE5);
    return true;
}
开发者ID:311labs,项目名称:SRL,代码行数:32,代码来源:SocketTest.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::getRemoteAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。