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


C++ TCPSocket::bind方法代码示例

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


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

示例1: TCPSOCKET_BIND_ADDRESS_INVALID

void TCPSOCKET_BIND_ADDRESS_INVALID()
{
    SKIP_IF_TCP_UNSUPPORTED();
    TCPSocket *sock = new TCPSocket;
    if (!sock) {
        TEST_FAIL();
        return;
    }
    TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
    nsapi_error_t bind_result = NSAPI_ERROR_OK;
    if (get_ip_version() == NSAPI_IPv4) {
        bind_result = sock->bind("190.2.3.4", 1024);
    } else if (get_ip_version() == NSAPI_IPv6) {
        bind_result = sock->bind("fe80::ff01", 1024);
    } else {
        TEST_FAIL_MESSAGE("This stack is neither IPv4 nor IPv6");
    }
    if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
        TEST_IGNORE_MESSAGE("bind() not supported");
    } else {
        TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, bind_result);
    }

    delete sock;
}
开发者ID:0xc0170,项目名称:mbed,代码行数:25,代码来源:tcpsocket_bind_address_invalid.cpp

示例2: TCPSOCKET_BIND_ADDRESS

void TCPSOCKET_BIND_ADDRESS()
{
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
    int count = fetch_stats();
    for (int j = 0; j < count; j++) {
        TEST_ASSERT_EQUAL(SOCK_CLOSED,  tcp_stats[j].state);
    }
#endif

    TCPSocket *sock = new TCPSocket;
    if (!sock) {
        TEST_FAIL();
    }
    TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
    SocketAddress sockAddr = SocketAddress(get_interface()->get_ip_address(), 80);
    TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->bind(sockAddr));

    delete sock;

#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
    count = fetch_stats();
    for (int j = 0; j < count; j++) {
        TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
    }
#endif
}
开发者ID:MarceloSalazar,项目名称:mbed-os,代码行数:26,代码来源:tcpsocket_bind_address.cpp

示例3: Init

bool Init()
{
    cout << "connecting to TCP " << gHost << ":" << gPort << " unum " << unum << "\n";

    try
        {
            Addr local(INADDR_ANY,INADDR_ANY);
            gSocket.bind(local);
        }

    catch (BindErr error)
        {
            cerr << "failed to bind socket with '"
                 << error.what() << "'" << endl;

            gSocket.close();
            return false;
        }

    try
        {
            Addr server(gPort,gHost);
            gSocket.connect(server);
        }

    catch (ConnectErr error)
        {
            cerr << "connection failed with: '"
                 << error.what() << "'" << endl;
            gSocket.close();
            return false;
        }

    return true;
}
开发者ID:unfabio,项目名称:furosimspark,代码行数:35,代码来源:main.cpp

示例4: TCPSOCKET_BIND_WRONG_TYPE

void TCPSOCKET_BIND_WRONG_TYPE()
{
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED
    int count = fetch_stats();
    for (int j = 0; j < count; j++) {
        TEST_ASSERT_EQUAL(SOCK_CLOSED,  tcp_stats[j].state);
    }
#endif

    TCPSocket *sock = new TCPSocket;
    if (!sock) {
        TEST_FAIL();
        return;
    }
    TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
    char addr_bytes[16] = {0xfe, 0x80, 0xff, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    SocketAddress sockAddr;
    if (get_ip_version() == NSAPI_IPv4) {
        sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
    } else if (get_ip_version() == NSAPI_IPv6) {
        sockAddr = SocketAddress(addr_bytes, NSAPI_IPv6, 80);
    } else {
        TEST_FAIL_MESSAGE("This stack is neither IPv4 nor IPv6");
    }
    nsapi_error_t bind_result = sock->bind(sockAddr);
    if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
        TEST_IGNORE_MESSAGE("bind() not supported");
    } else {
        TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, bind_result);
    }

    delete sock;

#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED
    count = fetch_stats();
    for (int j = 0; j < count; j++) {
        TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
    }
#endif
}
开发者ID:donatieng,项目名称:mbed,代码行数:40,代码来源:tcpsocket_bind_wrong_type.cpp


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