You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					172 lines
				
				5.2 KiB
			
		
		
			
		
	
	
					172 lines
				
				5.2 KiB
			| 
								 
											6 years ago
										 
									 | 
							
								'\" t
							 | 
						||
| 
								 | 
							
								.\"     Title: zmq_connect
							 | 
						||
| 
								 | 
							
								.\"    Author: [see the "AUTHORS" section]
							 | 
						||
| 
								 | 
							
								.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
							 | 
						||
| 
								 | 
							
								.\"      Date: 09/14/2016
							 | 
						||
| 
								 | 
							
								.\"    Manual: 0MQ Manual
							 | 
						||
| 
								 | 
							
								.\"    Source: 0MQ 4.1.5
							 | 
						||
| 
								 | 
							
								.\"  Language: English
							 | 
						||
| 
								 | 
							
								.\"
							 | 
						||
| 
								 | 
							
								.TH "ZMQ_CONNECT" "3" "09/14/2016" "0MQ 4\&.1\&.5" "0MQ Manual"
							 | 
						||
| 
								 | 
							
								.\" -----------------------------------------------------------------
							 | 
						||
| 
								 | 
							
								.\" * Define some portability stuff
							 | 
						||
| 
								 | 
							
								.\" -----------------------------------------------------------------
							 | 
						||
| 
								 | 
							
								.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
							 | 
						||
| 
								 | 
							
								.\" http://bugs.debian.org/507673
							 | 
						||
| 
								 | 
							
								.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
							 | 
						||
| 
								 | 
							
								.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
							 | 
						||
| 
								 | 
							
								.ie \n(.g .ds Aq \(aq
							 | 
						||
| 
								 | 
							
								.el       .ds Aq '
							 | 
						||
| 
								 | 
							
								.\" -----------------------------------------------------------------
							 | 
						||
| 
								 | 
							
								.\" * set default formatting
							 | 
						||
| 
								 | 
							
								.\" -----------------------------------------------------------------
							 | 
						||
| 
								 | 
							
								.\" disable hyphenation
							 | 
						||
| 
								 | 
							
								.nh
							 | 
						||
| 
								 | 
							
								.\" disable justification (adjust text to left margin only)
							 | 
						||
| 
								 | 
							
								.ad l
							 | 
						||
| 
								 | 
							
								.\" -----------------------------------------------------------------
							 | 
						||
| 
								 | 
							
								.\" * MAIN CONTENT STARTS HERE *
							 | 
						||
| 
								 | 
							
								.\" -----------------------------------------------------------------
							 | 
						||
| 
								 | 
							
								.SH "NAME"
							 | 
						||
| 
								 | 
							
								zmq_connect \- create outgoing connection from socket
							 | 
						||
| 
								 | 
							
								.SH "SYNOPSIS"
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								\fBint zmq_connect (void \fR\fB\fI*socket\fR\fR\fB, const char \fR\fB\fI*endpoint\fR\fR\fB);\fR
							 | 
						||
| 
								 | 
							
								.SH "DESCRIPTION"
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								The \fIzmq_connect()\fR function connects the \fIsocket\fR to an \fIendpoint\fR and then accepts incoming connections on that endpoint\&.
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								The \fIendpoint\fR is a string consisting of a \fItransport\fR:// followed by an \fIaddress\fR\&. The \fItransport\fR specifies the underlying protocol to use\&. The \fIaddress\fR specifies the transport\-specific address to connect to\&.
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								0MQ provides the the following transports:
							 | 
						||
| 
								 | 
							
								.PP
							 | 
						||
| 
								 | 
							
								\fItcp\fR
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								unicast transport using TCP, see
							 | 
						||
| 
								 | 
							
								\fBzmq_tcp\fR(7)
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.PP
							 | 
						||
| 
								 | 
							
								\fIipc\fR
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								local inter\-process communication transport, see
							 | 
						||
| 
								 | 
							
								\fBzmq_ipc\fR(7)
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.PP
							 | 
						||
| 
								 | 
							
								\fIinproc\fR
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								local in\-process (inter\-thread) communication transport, see
							 | 
						||
| 
								 | 
							
								\fBzmq_inproc\fR(7)
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.PP
							 | 
						||
| 
								 | 
							
								\fIpgm\fR, \fIepgm\fR
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								reliable multicast transport using PGM, see
							 | 
						||
| 
								 | 
							
								\fBzmq_pgm\fR(7)
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								Every 0MQ socket type except \fIZMQ_PAIR\fR supports one\-to\-many and many\-to\-one semantics\&. The precise semantics depend on the socket type and are defined in \fBzmq_socket\fR(3)\&.
							 | 
						||
| 
								 | 
							
								.if n \{\
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								.it 1 an-trap
							 | 
						||
| 
								 | 
							
								.nr an-no-space-flag 1
							 | 
						||
| 
								 | 
							
								.nr an-break-flag 1
							 | 
						||
| 
								 | 
							
								.br
							 | 
						||
| 
								 | 
							
								.ps +1
							 | 
						||
| 
								 | 
							
								\fBNote\fR
							 | 
						||
| 
								 | 
							
								.ps -1
							 | 
						||
| 
								 | 
							
								.br
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								for most transports and socket types the connection is not performed immediately but as needed by 0MQ\&. Thus a successful call to \fIzmq_connect()\fR does not mean that the connection was or could actually be established\&. Because of this, for most transports and socket types the order in which a \fIserver\fR socket is bound and a \fIclient\fR socket is connected to it does not matter\&. The first exception is when using the inproc:// transport: you must call \fIzmq_bind()\fR before calling \fIzmq_connect()\fR\&. The second exception are \fIZMQ_PAIR\fR sockets, which do not automatically reconnect to endpoints\&.
							 | 
						||
| 
								 | 
							
								.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
							 | 
						||
| 
								 | 
							
								\fBNote\fR
							 | 
						||
| 
								 | 
							
								.ps -1
							 | 
						||
| 
								 | 
							
								.br
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								following a \fIzmq_connect()\fR, for socket types except for ZMQ_ROUTER, the socket enters its normal \fIready\fR state\&. By contrast, following a \fIzmq_bind()\fR alone, the socket enters a \fImute\fR state in which the socket blocks or drops messages according to the socket type, as defined in \fBzmq_socket\fR(3)\&. A ZMQ_ROUTER socket enters its normal \fIready\fR state for a specific peer only when handshaking is complete for that peer, which may take an arbitrary time\&.
							 | 
						||
| 
								 | 
							
								.sp .5v
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.SH "RETURN VALUE"
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								The \fIzmq_connect()\fR function returns zero if successful\&. Otherwise it returns \-1 and sets \fIerrno\fR to one of the values defined below\&.
							 | 
						||
| 
								 | 
							
								.SH "ERRORS"
							 | 
						||
| 
								 | 
							
								.PP
							 | 
						||
| 
								 | 
							
								\fBEINVAL\fR
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								The endpoint supplied is invalid\&.
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.PP
							 | 
						||
| 
								 | 
							
								\fBEPROTONOSUPPORT\fR
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								The requested
							 | 
						||
| 
								 | 
							
								\fItransport\fR
							 | 
						||
| 
								 | 
							
								protocol is not supported\&.
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.PP
							 | 
						||
| 
								 | 
							
								\fBENOCOMPATPROTO\fR
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								The requested
							 | 
						||
| 
								 | 
							
								\fItransport\fR
							 | 
						||
| 
								 | 
							
								protocol is not compatible with the socket type\&.
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.PP
							 | 
						||
| 
								 | 
							
								\fBETERM\fR
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								The 0MQ
							 | 
						||
| 
								 | 
							
								\fIcontext\fR
							 | 
						||
| 
								 | 
							
								associated with the specified
							 | 
						||
| 
								 | 
							
								\fIsocket\fR
							 | 
						||
| 
								 | 
							
								was terminated\&.
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.PP
							 | 
						||
| 
								 | 
							
								\fBENOTSOCK\fR
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								The provided
							 | 
						||
| 
								 | 
							
								\fIsocket\fR
							 | 
						||
| 
								 | 
							
								was invalid\&.
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.PP
							 | 
						||
| 
								 | 
							
								\fBEMTHREAD\fR
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								No I/O thread is available to accomplish the task\&.
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.SH "EXAMPLE"
							 | 
						||
| 
								 | 
							
								.PP
							 | 
						||
| 
								 | 
							
								\fBConnecting a subscriber socket to an in-process and a TCP transport\fR. 
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								.if n \{\
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								.nf
							 | 
						||
| 
								 | 
							
								/* Create a ZMQ_SUB socket */
							 | 
						||
| 
								 | 
							
								void *socket = zmq_socket (context, ZMQ_SUB);
							 | 
						||
| 
								 | 
							
								assert (socket);
							 | 
						||
| 
								 | 
							
								/* Connect it to an in\-process transport with the address \*(Aqmy_publisher\*(Aq */
							 | 
						||
| 
								 | 
							
								int rc = zmq_connect (socket, "inproc://my_publisher");
							 | 
						||
| 
								 | 
							
								assert (rc == 0);
							 | 
						||
| 
								 | 
							
								/* Connect it to the host server001, port 5555 using a TCP transport */
							 | 
						||
| 
								 | 
							
								rc = zmq_connect (socket, "tcp://server001:5555");
							 | 
						||
| 
								 | 
							
								assert (rc == 0);
							 | 
						||
| 
								 | 
							
								.fi
							 | 
						||
| 
								 | 
							
								.if n \{\
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								.SH "SEE ALSO"
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								\fBzmq_bind\fR(3) \fBzmq_socket\fR(3) \fBzmq\fR(7)
							 | 
						||
| 
								 | 
							
								.SH "AUTHORS"
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								This page was written by the 0MQ community\&. To make a change please read the 0MQ Contribution Policy at \m[blue]\fBhttp://www\&.zeromq\&.org/docs:contributing\fR\m[]\&.
							 |