mco_iot_comm_connect_async

Call connect() on the specified address asynchronously.

For an overview see page ARF Applications in C

Prototype

    MCO_RET mco_iot_comm_connect_async(mco_iot_comm_h comm,
                    const char *address,
                    timer_unit timeout,
                    unsigned int n_attempts,
                    timer_unit interval,
                    mco_sock_params_t *params);

Arguments

comm
The communicator object.
address
The IP address to listen on (in format "iface:port").
timeout
The connect() timeout (in milliseconds).
n_attempts
The number of connection attempts — how many times connect() is called.
interval
The interval (in milliseconds) between connect() attempts.
params
The socket parameters defined for network communication.

Description

This function calls connect() on the specified address asynchronously and returns immediately before the connection has been established. If the connection has been established successfully, the onConnect() callback is called. Otherwise the onDestroy() callback is invoked.

Return Codes

MCO_S_OK
Connection successfully created.
MCO_E_IOT_INVALID_HANDLE
The communicator handle comm is invalid.
MCO_E_NOMEM
Unable to allocate memory for internal structures.
MCO_E_NW_*
Network error: unable to parse the address, create the socket, bind the socket or listen on the socket.

Example

The code snippet below connects asynchronously to address 192.168.0.1:15000 with a connect timeout of 2 seconds, and 10 connect attempts with 1 second interval between attempts:

    int main(int argc, char *argv[])
    {
        ...
        CHECK(mco_iot_comm_connect_async(comm, "192.168.0.1:15000", 2000, 10, 1000, 0));
        ...
    }

Files

Header file:
mcoiot.h
Source file:
mcoiotcomm.c
Library:
libmcoiotcomm.a