Call connect() on the specified address asynchronously.
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);
| 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 |
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.
| 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 |
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));
...
}