int nng_dial(nng_socket s, const char *url, nng_dialer *dp, int flags);
nng_dial() function creates a newly initialized
associated with socket s, and configured to dial the
address specified by url, and starts it.
If the value of dp is not
the newly created dialer is stored at the address indicated by dp.
Dialers initiate a remote connection to a listener. Upon a successful connection being established, they create a pipe, add it to the socket, and then wait for that pipe to be closed. When the pipe is closed, the dialer attempts to re-establish the connection. Dialers will also periodically retry a connection automatically if an attempt to connect asynchronously fails.
|While it is convenient to think of dialers as “clients”, the relationship between the listener or dialer is orthogonal to any server or client status that might be associated with a given protocol. For example, a req socket might have associated dialers, but might also have associated listeners. It may even have some of each at the same time!
Normally, the first attempt to connect to the address indicated by url is done synchronously, including any necessary name resolution. As a result, a failure, such as if the connection is refused, will be returned immediately, and no further action will be taken.
However, if the special value
supplied in flags, then the connection attempt is made asynchronously.
Furthermore, if the connection was closed for a synchronously dialed connection, the dialer will still attempt to redial asynchronously.
NNG_FLAG_NONBLOCK can help an application be more resilient,
it also generally makes diagnosing failures somewhat more difficult.
This function returns 0 on success, and non-zero otherwise.
An invalid url was specified.
The socket s is not open.
The remote peer refused the connection.
The remote peer reset the connection.
An invalid set of flags or an invalid url was specified.
Insufficient memory is available.
Authentication or authorization failure.
A protocol error occurred.
The remote address is not reachable.