% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/R_zmq_socket.r
\name{Socket Functions}
\alias{Socket Functions}
\alias{zmq.socket}
\alias{zmq.close}
\alias{zmq.bind}
\alias{zmq.connect}
\alias{zmq.disconnect}
\alias{zmq.setsockopt}
\alias{zmq.getsockopt}
\title{Socket Functions}
\usage{
zmq.socket(ctx, type = ZMQ.ST()$REP)

zmq.close(socket)

zmq.bind(socket, endpoint, MC = ZMQ.MC())

zmq.connect(socket, endpoint, MC = ZMQ.MC())

zmq.disconnect(socket, endpoint, MC = ZMQ.MC())

zmq.setsockopt(socket, option.name, option.value, MC = ZMQ.MC())

zmq.getsockopt(socket, option.name, option.value, MC = ZMQ.MC())
}
\arguments{
\item{ctx}{a ZMQ context}

\item{type}{a socket type}

\item{socket}{a ZMQ socket}

\item{endpoint}{a ZMQ socket endpoint}

\item{MC}{a message control, see \code{\link{ZMQ.MC}()} for details}

\item{option.name}{an option name to the socket}

\item{option.value}{an option value to the option name}
}
\value{
\code{zmq.socket()} returns an R external pointer (\code{socket})
generated by ZMQ C API pointing to a socket if successful, otherwise returns
an R \code{NULL} and sets \code{errno} to the error value, see ZeroMQ manual
for details.

\code{zmq.close()} destroys the socket reference/pointer (\code{socket}) and
returns 0 if successful, otherwise returns -1 and sets \code{errno} to the
error value, see ZeroMQ manual for details.

\code{zmq.bind()} binds the socket to specific \code{endpoint} and returns 0
if successful, otherwise returns -1 and sets \code{errno} to the error
value, see ZeroMQ manual for details.

\code{zmq.connect()} connects the socket to specific \code{endpoint} and
returns 0 if successful, otherwise returns -1 and sets \code{errno} to the
error value, see ZeroMQ manual for details.

\code{zmq.setsockopt()} sets/changes the socket option and returns 0 if
successful, otherwise returns -1 and sets \code{errno} to the error value,
see ZeroMQ manual for details.

\code{zmq.getsockopt()} returns the value of socket option,
see ZeroMQ manual for details.
}
\description{
Socket functions
}
\details{
\code{zmq.socket()} initials a ZMQ socket given a ZMQ context \code{ctx} and
a socket \code{type}. See \code{\link{ZMQ.ST}()} for the possible values of
\code{type}. ZMQ defines several patterns for the socket type and utilize
them to communicate in different ways including request-reply,
publish-subscribe, pipeline, exclusive pair, and naive patterns.

\code{zmq.close()} destroys the ZMQ socket.

\code{zmq.bind()} binds the socket to a local endpoint and then accepts
incoming connections on that endpoint. See \code{endpoint} next for details.

\code{zmq.connect()} connects the socket to a remote endpoint and then
accepts outgoing connections on that endpoint. See \code{endpoint} next for
details.

\code{endpoint} is a string consisting of a transport :// followed by an
address. The transport specifies the underlying protocol to use. The address
specifies the transport-specific address to bind to.  pbdZMQ/ZMQ provides
the following transports: \tabular{ll}{ Transport \tab Usage \cr \code{tcp}
\tab unicast transport using TCP \cr \code{ipc} \tab local inter-process
communication transport \cr \code{inproc} \tab local in-process
(inter-thread) communication transport \cr \code{pgm,epgm} \tab reliable
multicast transport using PGM } *** warning: \code{epgm} is not turned on by
default in the pbdZMQ's internal ZeroMQ library. \cr *** warning: \code{ipc}
is not supported in Windows system.

\code{zmq.setsockopt()} is to set/change socket options.

\code{zmq.getsockopt()} is to get socket options and returns
\code{option.value}.
}
\examples{
\dontrun{
### Using request-reply pattern.

### At the server, run next in background or the other windows.
library(pbdZMQ, quietly = TRUE)

context <- zmq.ctx.new()
responder <- zmq.socket(context, ZMQ.ST()$REP)
zmq.bind(responder, "tcp://*:5555")
zmq.close(responder)
zmq.ctx.destroy(context)


### At a client, run next in foreground.
library(pbdZMQ, quietly = TRUE)

context <- zmq.ctx.new()
requester <- zmq.socket(context, ZMQ.ST()$REQ)
zmq.connect(requester, "tcp://localhost:5555")
zmq.close(requester)
zmq.ctx.destroy(context)
}

}
\references{
ZeroMQ/4.1.0 API Reference:
\url{https://libzmq.readthedocs.io/en/zeromq4-1/}

Programming with Big Data in R Website: \url{https://pbdr.org/}
}
\seealso{
\code{\link{zmq.ctx.new}()}, \code{\link{zmq.ctx.destroy}()}.
}
\author{
Wei-Chen Chen \email{wccsnow@gmail.com}.
}
\keyword{programming}
