'\" t
.\"     Title: nn_connect
.\"    Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.26
.\"      Date: 2021-02-08
.\"    Manual: NNG Reference Manual
.\"    Source: \ \&
.\"  Language: English
.\"
.TH "NN_CONNECT" "3compat" "2021-02-08" "\ \&" "NNG Reference Manual"
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.ss \n[.ss] 0
.nh
.ad l
.de URL
\fI\\$2\fP <\\$1>\\$3
..
.als MTO URL
.if \n[.g] \{\
.  mso www.tmac
.  am URL
.    ad l
.  .
.  am MTO
.    ad l
.  .
.  LINKSTYLE blue R < >
.\}
.SH "NAME"
nn_connect \- connect to remote peer (compatible API)
.SH "SYNOPSIS"
.sp
.if n .RS 4
.nf
.fam C
#include <nanomsg/nn.h>

int nn_connect(int sock, const char *url)
.fam
.fi
.if n .RE
.SH "DESCRIPTION"
.sp
The \f(CRnn_connect()\fP function arranges for the socket \fIsock\fP to
initiate connection to a peer at the address specified by \fIurl\fP.
An identifier for this socket\(cqs association with the \fIurl\fP is
returned to the caller on success.
This identifier can be used with
\f(CRnn_shutdown()\fP to
remove the association later.
.if n .sp
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
.B Note
.ps -1
.br
.sp
This function is provided for API
compatibility with legacy \fIlibnanomsg\fP.
Consider using the relevant modern API instead.
.sp .5v
.RE
.if n .sp
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
.B Note
.ps -1
.br
.sp
The connect operation is performed asynchronously, and may not have
completed before this function returns control to the caller.
.sp .5v
.RE
.if n .sp
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
.B Important
.ps -1
.br
.sp
Only transports supported by legacy \fIlibnanomsg\fP may be
used with this function.
In particular, only the schemes \f(CRtcp://\fP, \f(CRipc://\fP, \f(CRinproc://\fP, and \f(CRws://\fP are
supported with this function.
(Use the modern API to use other schemes.)
.sp .5v
.RE
.SH "RETURN VALUES"
.sp
This function returns a positive identifier success, and \-1 on error.
.SH "ERRORS"
.sp
\f(CRECONNREFUSED\fP
.RS 4
The connection attempt was refused.
.RE
.sp
\f(CREBADF\fP
.RS 4
The socket \fIsock\fP is not open.
.RE
.sp
\f(CREINVAL\fP
.RS 4
An invalid \fIurl\fP was supplied.
.RE
.SH "SEE ALSO"
.sp
nn_bind(3compat),
nn_errno(3compat),
nn_shutdown(3compat),
nn_socket(3compat),
nn_compat(3compat),
nng(7)