Class ZMQ.Socket
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Enclosing class:
ZMQ
Where conventional sockets transfer streams of bytes or discrete datagrams, ØMQ sockets transfer discrete messages.
Key differences to conventional sockets
Generally speaking, conventional sockets present a synchronous interface to either connection-oriented reliable byte streams (SOCK_STREAM), or connection-less unreliable datagrams (SOCK_DGRAM).In comparison, ØMQ sockets present an abstraction of an asynchronous message queue, with the exact queueing semantics depending on the socket type in use. Where conventional sockets transfer streams of bytes or discrete datagrams, ØMQ sockets transfer discrete messages.
ØMQ sockets being asynchronous means that the timings of the physical connection setup and tear down, reconnect and effective delivery are transparent to the user and organized by ØMQ itself. Further, messages may be queued in the event that a peer is unavailable to receive them.
Conventional sockets allow only strict one-to-one (two peers), many-to-one (many clients, one server), or in some cases one-to-many (multicast) relationships. With the exception of
ZMQ.PAIR
, ØMQ sockets may be connected to multiple endpoints using connect(String)
,
while simultaneously accepting incoming connections from multiple endpoints bound to the socket using bind(String)
,
thus allowing many-to-many relationships.
Thread safety
ØMQ sockets are not thread safe. Applications MUST NOT use a socket from multiple threads except after migrating a socket from one thread to another with a "full fence" memory barrier.ØMQ sockets are not Thread.interrupt safe. Applications MUST NOT interrupt threads using ØMQ sockets.
Messaging patterns
- Request-reply
The request-reply pattern is used for sending requests from aZMQ.REQ
client to one or moreZMQ.REP
services, and receiving subsequent replies to each request sent. The request-reply pattern is formally defined by http://rfc.zeromq.org/spec:28.ZMQ.REQ
,ZMQ.REP
,ZMQ.DEALER
,ZMQ.ROUTER
socket types belong to this pattern. - Publish-subscribe
The publish-subscribe pattern is used for one-to-many distribution of data from a single publisher to multiple subscribers in a fan out fashion. The publish-subscribe pattern is formally defined by http://rfc.zeromq.org/spec:29.ZMQ.SUB
,ZMQ.PUB
,ZMQ.XSUB
,ZMQ.XPUB
socket types belong to this pattern. - Pipeline
The pipeline pattern is used for distributing data to nodes arranged in a pipeline. Data always flows down the pipeline, and each stage of the pipeline is connected to at least one node. When a pipeline stage is connected to multiple nodes data is round-robined among all connected nodes. The pipeline pattern is formally defined by http://rfc.zeromq.org/spec:30.ZMQ.PUSH
,ZMQ.PULL
socket types belong to this pattern. - Exclusive pair
The exclusive pair pattern is used to connect a peer to precisely one other peer. This pattern is used for inter-thread communication across the inproc transport, usingZMQ.PAIR
socket type. The exclusive pair pattern is formally defined by http://rfc.zeromq.org/spec:31. - Native
The native pattern is used for communicating with TCP peers and allows asynchronous requests and replies in either direction, usingZMQ.STREAM
socket type.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Socket
(ZContext context, SocketType type) Class constructor.protected
Socket
(ZMQ.Context context, int type) Deprecated.protected
Socket
(ZMQ.Context context, SocketType type) Class constructor.protected
Socket
(SocketBase base) Wrap an already existing socket -
Method Summary
Modifier and TypeMethodDescriptionbase()
DO NOT USE if you're trying to build a special proxyboolean
Bind to network interface.int
bindToRandomPort
(String addr) Bind to network interface to a random port.int
bindToRandomPort
(String addr, int min, int max) Bind to network interface to a random port.void
close()
This is an explicit "destructor".boolean
Connects the socket to an endpoint and then accepts incoming connections on that endpoint.int
connectPeer
(String addr) create outgoing connection from socket and return the connection routing id in thread-safe and atomic way.Create aZMQ.CancellationToken
to cancel send/receive operations for this socket.boolean
disconnect
(String addr) Disconnect from remote application.int
errno()
long
boolean
Deprecated.the naming is inconsistent with jzmq, please usegetCurveServer()
insteadboolean
Deprecated.the naming is inconsistent with jzmq, please usegetPlainServer()
insteadint
The ZMQ_BACKLOG option shall retrieve the maximum length of the queue of outstanding peer connections for the specified socket; this only applies to connection-oriented transports.boolean
If in conflate mode, a socket shall keep only one message in its inbound/outbound queue, this message being the last message received/the last message to be sent.getCtx()
byte[]
Retrieves the current long term public key for the socket in binary format of 32 bytes.byte[]
Retrieves the current long term secret key for the socket in binary format of 32 bytes.boolean
Tells if the socket will act as server for CURVE security.byte[]
Retrieves the current server key for the socket in binary format of 32 bytes.boolean
Deprecated.usesetImmediate(boolean)
instead (inverted logic: immediate = true <==> delay attach on connect = false)int
The 'ZMQ_EVENTS' option shall retrieve event flags for the specified socket.getFD()
The 'ZMQ_FD' option shall retrieve file descriptor associated with the 0MQ socket.int
The ZMQ_HANDSHAKE_IVL option shall retrieve the maximum handshake interval for the specified socket.byte[]
The ZMQ_HEARTBEAT_CONTEXT option shall set the ping context of the peer for ZMTP heartbeats.int
The ZMQ_HEARTBEAT_IVL option shall set the interval between sending ZMTP heartbeats for the specified socket.int
The ZMQ_HEARTBEAT_TIMEOUT option shall set how long to wait before timing-out a connection after sending a PING ZMTP command and not receiving any traffic.int
The ZMQ_HEARTBEAT_TTL option shall set the timeout on the remote peer for ZMTP heartbeats.int
getHWM()
Deprecated.byte[]
boolean
Retrieve the state of the attach on connect value.boolean
Deprecated.useisIPv6()
instead (inverted logic: ipv4 = true <==> ipv6 = false)boolean
getIPv6()
Retrieve the IPv6 option for the socket.The ZMQ_LAST_ENDPOINT option shall retrieve the last endpoint bound for TCP and IPC transports.int
The 'ZMQ_LINGER' option shall retrieve the period for pending outbound messages to linger in memory after closing the socket.long
The option shall retrieve limit for the inbound messages.The ZMQ_MECHANISM option shall retrieve the current security mechanism for the socket.int
Gets the limit threshold where messages of a given size will be allocated using Direct ByteBuffer.long
The ZMQ_PLAIN_PASSWORD option shall retrieve the last password set for the PLAIN security mechanism.boolean
Returns the ZMQ_PLAIN_SERVER option, if any, previously set on the socket.The ZMQ_PLAIN_USERNAME option shall retrieve the last username set for the PLAIN security mechanism.long
getRate()
int
The ZMQ_RCVHWM option shall return the high water mark for inbound messages on the specified socket.int
The ZMQ_RCVBUF option shall retrieve the underlying kernel receive buffer size for the specified socket.int
Retrieve the timeout for recv operation on the socket.int
The ZMQ_RECONNECT_IVL option shall retrieve the initial reconnection interval for the specified socket.int
The ZMQ_RECONNECT_IVL_MAX option shall retrieve the maximum reconnection interval for the specified socket.long
The ZMQ_RECOVERY_IVL option shall retrieve the recovery interval for multicast transports using the specified socket.boolean
Deprecated.boolean
Deprecated.Return the customSelectorProvider
chooser.The ZMQ_SELFADDR_PROPERTY_NAME option shall retrieve the metadata record used to store the self address.int
The ZMQ_SNDBUF option shall retrieve the underlying kernel transmit buffer size for the specified socket.int
Retrieve the timeout for send operation on the socket.int
The ZMQ_SNDHWM option shall return the high water mark for outbound messages on the specified socket.The 'ZMQ_TYPE option shall retrieve the socket type for the specified 'socket'.The ZMQ_SOCKS_PROXY option shall retrieve the SOCKS5 proxy address in string format.long
getSwap()
Deprecated.int
long
long
long
long
Deprecated.int
getTos()
Retrieve the IP_TOS option for the socket.int
getType()
The 'ZMQ_TYPE option shall retrieve the socket type for the specified 'socket'.The ZMQ_ZAP_DOMAIN option shall retrieve the last ZAP domain set for the socket.The ZMQ_ZAP_DOMAIN option shall retrieve the last ZAP domain set for the socket.boolean
Deprecated.boolean
The 'ZMQ_RCVMORE' option shall return a boolean value indicating if the multi-part message currently being read from the specified 'socket' has more message parts to follow.boolean
Deprecated.the naming is inconsistent with jzmq, please usegetCurveServer()
insteadboolean
Deprecated.the naming is inconsistent with jzmq, please usegetPlainServer()
insteadboolean
If in conflate mode, a socket shall keep only one message in its inbound/outbound queue, this message being the last message received/the last message to be sent.boolean
Retrieve the state of the attach on connect value.boolean
isIPv6()
Retrieve the IPv6 option for the socket.boolean
Joins a group.boolean
Leaves a group.protected void
mayRaise()
boolean
Start a monitoring socket where events can be received.byte[]
recv()
Receives a message.int
recv
(byte[] buffer, int offset, int len, int flags) Receives a message in to a specified buffer.byte[]
recv
(int flags) Receives a message.byte[]
recv
(int flags, ZMQ.CancellationToken cancellationToken) Receives a message, the call be canceled by calling cancellationTokenZMQ.CancellationToken.cancel()
.Object[]
recvBinaryPicture
(String picture) Receive a binary encoded 'picture' message from the socket (or actor).int
recvByteBuffer
(ByteBuffer buffer, int flags) Receives a message into the specified ByteBuffer.recvMsg()
Receives a message.recvMsg
(int flags) Receives a message.Object[]
recvPicture
(String picture) Receive a 'picture' message to the socket (or actor).recvStr()
recvStr
(int flags) Receives a message as a string.boolean
send
(byte[] data) Queues a message created from data, so it can be sent.boolean
send
(byte[] data, int flags) Queues a message created from data, so it can be sent.boolean
send
(byte[] data, int off, int length, int flags) Queues a message created from data, so it can be sent.boolean
send
(byte[] data, int flags, ZMQ.CancellationToken cancellationToken) Queues a message created from data, so it can be sent, the call be canceled by calling cancellationTokenZMQ.CancellationToken.cancel()
.boolean
Queues a message created from data, so it can be sent.boolean
Queues a message created from data.boolean
sendBinaryPicture
(String picture, Object... args) Queues a binary encoded 'picture' message to the socket (or actor), so it can be sent.int
sendByteBuffer
(ByteBuffer data, int flags) Queues a message created from data, so it can be sent.boolean
sendMore
(byte[] data) Queues a multi-part message created from data, so it can be sent.boolean
Queues a multi-part message created from data, so it can be sent.boolean
Queues a message created from data, so it can be sent.boolean
Queues a message created from data, so it can be sent.boolean
sendMsgMore
(Msg msg) Queues a multi-part message created from data, so it can be sent.boolean
sendPicture
(String picture, Object... args) Queues a 'picture' message to the socket (or actor), so it can be sent.boolean
setAffinity
(long value) Get the Affinity.boolean
setAsServerCurve
(boolean server) Deprecated.the naming is inconsistent with jzmq, please usesetCurveServer(boolean)
insteadboolean
setAsServerPlain
(boolean server) Deprecated.the naming is inconsistent with jzmq, please usesetPlainServer(boolean)
insteadboolean
setBacklog
(int value) The ZMQ_BACKLOG option shall set the maximum length of the queue of outstanding peer connections for the specified socket; this only applies to connection-oriented transports.boolean
setBacklog
(long value) Deprecated.this option uses integer range, usesetBacklog(int)
instead.boolean
setConflate
(boolean conflate) If set, a socket shall keep only one message in its inbound/outbound queue, this message being the last message received/the last message to be sent.boolean
setConnectRid
(byte[] rid) The ZMQ_CONNECT_RID option sets the peer id of the next host connected via the connect() call, and immediately readies that connection for data transfer with the named id.boolean
setConnectRid
(String rid) The ZMQ_CONNECT_RID option sets the peer id of the next host connected via the connect() call, and immediately readies that connection for data transfer with the named id.boolean
setCurvePublicKey
(byte[] key) Sets the socket's long term public key.boolean
setCurveSecretKey
(byte[] key) Sets the socket's long term secret key.boolean
setCurveServer
(boolean server) Defines whether the socket will act as server for CURVE security, see zmq_curve(7).boolean
setCurveServerKey
(byte[] key) Sets the socket's long term server key.boolean
setDecoder
(Class<? extends IDecoder> cls) Deprecated.boolean
setDelayAttachOnConnect
(boolean value) Deprecated.usesetImmediate(boolean)
instead (warning, the boolean is inverted)boolean
setEncoder
(Class<? extends IEncoder> cls) Deprecated.boolean
setEventHook
(ZEvent.ZEventConsummer consumer, int events) Register a custom event consumer.boolean
setHandshakeIvl
(int maxHandshakeIvl) The ZMQ_HANDSHAKE_IVL option shall set the maximum handshake interval for the specified socket.boolean
setHeartbeatContext
(byte[] pingContext) The ZMQ_HEARTBEAT_CONTEXT option shall set the ping context of the peer for ZMTP heartbeats.boolean
setHeartbeatIvl
(int heartbeatIvl) The ZMQ_HEARTBEAT_IVL option shall set the interval between sending ZMTP heartbeats for the specified socket.boolean
setHeartbeatTimeout
(int heartbeatTimeout) The ZMQ_HEARTBEAT_TIMEOUT option shall set how long to wait before timing-out a connection after sending a PING ZMTP command and not receiving any traffic.boolean
setHeartbeatTtl
(int heartbeatTtl) The ZMQ_HEARTBEAT_TTL option shall set the timeout on the remote peer for ZMTP heartbeats.boolean
setHelloMsg
(byte[] helloMsg) When set, the socket will automatically send a hello message when a new connection is made or accepted.boolean
setHWM
(int hwm) The 'ZMQ_HWM' option shall set the high water mark for the specified 'socket'.boolean
setHWM
(long hwm) Deprecated.this option uses integer range, usesetHWM(int)
insteadboolean
setIdentity
(byte[] identity) The 'ZMQ_IDENTITY' option shall set the identity of the specified 'socket'.boolean
setImmediate
(boolean value) Accept messages immediately or only when connections are madeboolean
setIPv4Only
(boolean v4only) Deprecated.usesetIPv6(boolean)
instead (inverted logic: ipv4 = true <==> ipv6 = false)boolean
setIPv6
(boolean v6) Set the IPv6 option for the socket.boolean
setLinger
(int value) The ZMQ_LINGER option shall set the linger period for the specified socket.boolean
setLinger
(long value) Deprecated.the linger option has only integer range, usesetLinger(int)
insteadboolean
setMaxMsgSize
(long value) Limits the size of the inbound message.boolean
setMsgAllocationHeapThreshold
(int threshold) Sets the limit threshold where messages of a given size will be allocated using Direct ByteBuffer.boolean
setMsgAllocator
(MsgAllocator allocator) Sets a custom message allocator.boolean
setMulticastHops
(long value) Sets the time-to-live field in every multicast packet sent from this socket.boolean
setMulticastLoop
(boolean multicastLoop) Deprecated.boolean
setPlainPassword
(byte[] password) Sets the password for outgoing connections over TCP or IPC.boolean
setPlainPassword
(String password) Sets the password for outgoing connections over TCP or IPC.boolean
setPlainServer
(boolean server) Defines whether the socket will act as server for PLAIN security, see zmq_plain(7).boolean
setPlainUsername
(byte[] username) Sets the username for outgoing connections over TCP or IPC.boolean
setPlainUsername
(String username) Sets the username for outgoing connections over TCP or IPC.boolean
setProbeRouter
(boolean probe) When set to true, the socket will automatically send an empty message when a new connection is made or accepted.boolean
setRate
(long value) The 'ZMQ_RATE' option shall set the maximum send or receive data rate for multicast transports such as in the man page of zmq_pgm[7] using the specified 'socket'.boolean
setRcvHWM
(int value) The ZMQ_RCVHWM option shall set the high water mark for inbound messages on the specified socket.boolean
setRcvHWM
(long value) Deprecated.this option uses integer range, usesetRcvHWM(int)
insteadboolean
setReceiveBufferSize
(int value) The 'ZMQ_RCVBUF' option shall set the underlying kernel receive buffer size for the 'socket' to the specified size in bytes.boolean
setReceiveBufferSize
(long value) Deprecated.this option uses integer range, usesetReceiveBufferSize(int)
insteadboolean
setReceiveTimeOut
(int value) Sets the timeout for receive operation on the socket.boolean
setReconnectIVL
(int value) The ZMQ_RECONNECT_IVL option shall set the initial reconnection interval for the specified socket.boolean
setReconnectIVL
(long value) Deprecated.reconnect interval option uses integer range, usesetReconnectIVL(int)
insteadboolean
setReconnectIVLMax
(int value) The ZMQ_RECONNECT_IVL_MAX option shall set the maximum reconnection interval for the specified socket.boolean
setReconnectIVLMax
(long value) Deprecated.this option uses integer range, usesetReconnectIVLMax(int)
insteadboolean
setRecoveryInterval
(long value) The 'ZMQ_RECOVERY_IVL' option shall set the recovery interval for multicast transports using the specified 'socket'.boolean
setReqCorrelate
(boolean correlate) The default behavior of REQ sockets is to rely on the ordering of messages to match requests and responses and that is usually sufficient.boolean
setReqRelaxed
(boolean relaxed) By default, a REQ socket does not allow initiating a new request with zmq_send(3) until the reply to the previous one has been received.boolean
setRouterHandover
(boolean handover) If two clients use the same identity when connecting to a ROUTER, the results shall depend on the ZMQ_ROUTER_HANDOVER option setting.boolean
setRouterMandatory
(boolean mandatory) Sets the ROUTER socket behavior when an unroutable message is encountered.boolean
setRouterRaw
(boolean raw) Sets the raw mode on the ROUTER, when set to true.boolean
Set a customSelectorProvider
chooser.boolean
setSelfAddressPropertyName
(String recordName) Sets the field name where the self address will be stored.boolean
setSendBufferSize
(int value) The 'ZMQ_SNDBUF' option shall set the underlying kernel transmit buffer size for the 'socket' to the specified size in bytes.boolean
setSendBufferSize
(long value) Deprecated.this option uses integer range, usesetSendBufferSize(int)
insteadboolean
setSendTimeOut
(int value) Sets the timeout for send operation on the socket.boolean
setSndHWM
(int value) The ZMQ_SNDHWM option shall set the high water mark for outbound messages on the specified socket.boolean
setSndHWM
(long value) Deprecated.this option uses integer range, usesetSndHWM(int)
insteadboolean
setSocksProxy
(byte[] proxy) Sets the SOCKS5 proxy address that shall be used by the socket for the TCP connection(s).boolean
setSocksProxy
(String proxy) Sets the SOCKS5 proxy address that shall be used by the socket for the TCP connection(s).boolean
setSwap
(long value) Deprecated.boolean
setTCPKeepAlive
(int optVal) Override SO_KEEPALIVE socket option (where supported by OS) to enable keep-alive packets for a socket connection.boolean
setTCPKeepAlive
(long value) Deprecated.boolean
setTCPKeepAliveCount
(long value) Override TCP_KEEPCNT socket option (where supported by OS).boolean
setTCPKeepAliveIdle
(long value) Override TCP_KEEPCNT (or TCP_KEEPALIVE on some OS) socket option (where supported by OS).boolean
setTCPKeepAliveInterval
(long value) Override TCP_KEEPINTVL socket option (where supported by OS).boolean
setTos
(int value) Sets the ToS fields (Differentiated services (DS) and Explicit Congestion Notification (ECN) field of the IP header.boolean
setXpubManual
(boolean manual) boolean
setXpubNoDrop
(boolean noDrop) Sets the XPUB socket behaviour to return error EAGAIN if SENDHWM is reached and the message could not be send.boolean
setXpubVerbose
(boolean verbose) Sets the XPUB socket behavior on new subscriptions and unsubscriptions.boolean
setXpubVerboser
(boolean verboser) boolean
setZapDomain
(byte[] domain) Sets the domain for ZAP (ZMQ RFC 27) authentication.boolean
setZapDomain
(String domain) Sets the domain for ZAP (ZMQ RFC 27) authentication.boolean
setZAPDomain
(byte[] domain) Sets the domain for ZAP (ZMQ RFC 27) authentication.boolean
setZAPDomain
(String domain) Sets the domain for ZAP (ZMQ RFC 27) authentication.boolean
subscribe
(byte[] topic) The 'ZMQ_SUBSCRIBE' option shall establish a new message filter on a 'ZMQ_SUB' socket.boolean
The 'ZMQ_SUBSCRIBE' option shall establish a new message filter on a 'ZMQ_SUB' socket.toString()
boolean
Stop accepting connections on a socket.boolean
unsubscribe
(byte[] topic) The 'ZMQ_UNSUBSCRIBE' option shall remove an existing message filter on a 'ZMQ_SUB' socket.boolean
unsubscribe
(String topic) The 'ZMQ_UNSUBSCRIBE' option shall remove an existing message filter on a 'ZMQ_SUB' socket.
-
Constructor Details
-
Socket
Class constructor.- Parameters:
context
- a 0MQ context previously created.type
- the socket type.
-
Socket
Class constructor.- Parameters:
context
- a 0MQ context previously created.type
- the socket type.
-
Socket
Deprecated.Class constructor.- Parameters:
context
- a 0MQ context previously created.type
- the socket type.
-
Socket
Wrap an already existing socket- Parameters:
base
- an already generated socket
-
-
Method Details
-
base
DO NOT USE if you're trying to build a special proxy- Returns:
- raw zmq.SocketBase
-
close
public void close()This is an explicit "destructor". It can be called to ensure the corresponding 0MQ Socket has been disposed of. If the socket was created from a org.zeromq.ZContext, it will remove the reference to this socket from it.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getType
public int getType()The 'ZMQ_TYPE option shall retrieve the socket type for the specified 'socket'. The socket type is specified at socket creation time and cannot be modified afterwards.- Returns:
- the socket type.
-
getSocketType
The 'ZMQ_TYPE option shall retrieve the socket type for the specified 'socket'. The socket type is specified at socket creation time and cannot be modified afterwards.- Returns:
- the socket type as an enum.
-
getCtx
- Returns:
- the low level
Ctx
associated with this socket.
-
getLinger
public int getLinger()The 'ZMQ_LINGER' option shall retrieve the period for pending outbound messages to linger in memory after closing the socket. Value of -1 means infinite. Pending messages will be kept until they are fully transferred to the peer. Value of 0 means that all the pending messages are dropped immediately when socket is closed. Positive value means number of milliseconds to keep trying to send the pending messages before discarding them.- Returns:
- the linger period.
- See Also:
-
setLinger
Deprecated.the linger option has only integer range, usesetLinger(int)
insteadThe ZMQ_LINGER option shall set the linger period for the specified socket. The linger period determines how long pending messages which have yet to be sent to a peer shall linger in memory after a socket is disconnected with disconnect or closed with close, and further affects the termination of the socket's context with Ctx#term. The following outlines the different behaviours:A value of -1 specifies an infinite linger period. Pending messages shall not be discarded after a call to disconnect() or close(); attempting to terminate the socket's context with Ctx#term() shall block until all pending messages have been sent to a peer.
The value of 0 specifies no linger period. Pending messages shall be discarded immediately after a call to disconnect() or close().
Positive values specify an upper bound for the linger period in milliseconds. Pending messages shall not be discarded after a call to disconnect() or close(); attempting to terminate the socket's context with Ctx#term() shall block until either all pending messages have been sent to a peer, or the linger period expires, after which any pending messages shall be discarded.
- Parameters:
value
- the linger period in milliseconds.- Returns:
- true if the option was set, otherwise false
- See Also:
-
setLinger
public boolean setLinger(int value) The ZMQ_LINGER option shall set the linger period for the specified socket. The linger period determines how long pending messages which have yet to be sent to a peer shall linger in memory after a socket is disconnected with disconnect or closed with close, and further affects the termination of the socket's context with Ctx#term. The following outlines the different behaviours:A value of -1 specifies an infinite linger period. Pending messages shall not be discarded after a call to disconnect() or close(); attempting to terminate the socket's context with Ctx#term() shall block until all pending messages have been sent to a peer.
The value of 0 specifies no linger period. Pending messages shall be discarded immediately after a call to disconnect() or close().
Positive values specify an upper bound for the linger period in milliseconds. Pending messages shall not be discarded after a call to disconnect() or close(); attempting to terminate the socket's context with Ctx#term() shall block until either all pending messages have been sent to a peer, or the linger period expires, after which any pending messages shall be discarded.
- Parameters:
value
- the linger period in milliseconds.- Returns:
- true if the option was set, otherwise false
- See Also:
-
getReconnectIVL
public int getReconnectIVL()The ZMQ_RECONNECT_IVL option shall retrieve the initial reconnection interval for the specified socket. The reconnection interval is the period ØMQ shall wait between attempts to reconnect disconnected peers when using connection-oriented transports. The value -1 means no reconnection.CAUTION: The reconnection interval may be randomized by ØMQ to prevent reconnection storms in topologies with a large number of peers per socket.
- Returns:
- the reconnectIVL.
- See Also:
-
setReconnectIVL
Deprecated.reconnect interval option uses integer range, usesetReconnectIVL(int)
insteadThe ZMQ_RECONNECT_IVL option shall set the initial reconnection interval for the specified socket. The reconnection interval is the period ØMQ shall wait between attempts to reconnect disconnected peers when using connection-oriented transports. The value -1 means no reconnection.- Returns:
- true if the option was set, otherwise false
- See Also:
-
setReconnectIVL
public boolean setReconnectIVL(int value) The ZMQ_RECONNECT_IVL option shall set the initial reconnection interval for the specified socket. The reconnection interval is the period ØMQ shall wait between attempts to reconnect disconnected peers when using connection-oriented transports. The value -1 means no reconnection.- Returns:
- true if the option was set, otherwise false.
- See Also:
-
getBacklog
public int getBacklog()The ZMQ_BACKLOG option shall retrieve the maximum length of the queue of outstanding peer connections for the specified socket; this only applies to connection-oriented transports. For details refer to your operating system documentation for the listen function.- Returns:
- the the maximum length of the queue of outstanding peer connections.
- See Also:
-
setBacklog
Deprecated.this option uses integer range, usesetBacklog(int)
instead.The ZMQ_BACKLOG option shall set the maximum length of the queue of outstanding peer connections for the specified socket; this only applies to connection-oriented transports. For details refer to your operating system documentation for the listen function.- Parameters:
value
- the maximum length of the queue of outstanding peer connections.- Returns:
- true if the option was set, otherwise false.
- See Also:
-
setBacklog
public boolean setBacklog(int value) The ZMQ_BACKLOG option shall set the maximum length of the queue of outstanding peer connections for the specified socket; this only applies to connection-oriented transports. For details refer to your operating system documentation for the listen function.- Parameters:
value
- the maximum length of the queue of outstanding peer connections.- Returns:
- true if the option was set, otherwise false.
- See Also:
-
getHandshakeIvl
public int getHandshakeIvl()The ZMQ_HANDSHAKE_IVL option shall retrieve the maximum handshake interval for the specified socket. Handshaking is the exchange of socket configuration information (socket type, identity, security) that occurs when a connection is first opened, only for connection-oriented transports. If handshaking does not complete within the configured time, the connection shall be closed. The value 0 means no handshake time limit.- Returns:
- the maximum handshake interval.
- See Also:
-
getHeartbeatIvl
public int getHeartbeatIvl()The ZMQ_HEARTBEAT_IVL option shall set the interval between sending ZMTP heartbeats for the specified socket. If this option is set and is greater than 0, then a PING ZMTP command will be sent every ZMQ_HEARTBEAT_IVL milliseconds.- Returns:
- heartbeat interval in milliseconds
-
getHeartbeatTimeout
public int getHeartbeatTimeout()The ZMQ_HEARTBEAT_TIMEOUT option shall set how long to wait before timing-out a connection after sending a PING ZMTP command and not receiving any traffic. This option is only valid if ZMQ_HEARTBEAT_IVL is also set, and is greater than 0. The connection will time out if there is no traffic received after sending the PING command, but the received traffic does not have to be a PONG command - any received traffic will cancel the timeout.- Returns:
- heartbeat timeout in milliseconds
-
getHeartbeatTtl
public int getHeartbeatTtl()The ZMQ_HEARTBEAT_TTL option shall set the timeout on the remote peer for ZMTP heartbeats. If this option is greater than 0, the remote side shall time out the connection if it does not receive any more traffic within the TTL period. This option does not have any effect if ZMQ_HEARTBEAT_IVL is not set or is 0. Internally, this value is rounded down to the nearest decisecond, any value less than 100 will have no effect.- Returns:
- heartbeat time-to-live in milliseconds
-
getHeartbeatContext
public byte[] getHeartbeatContext()The ZMQ_HEARTBEAT_CONTEXT option shall set the ping context of the peer for ZMTP heartbeats.This API is in DRAFT state and is subject to change at ANY time until declared stable.
If this option is set, every ping message sent for heartbeat will contain this context.
- Returns:
- the context to be sent with ping messages. Empty array by default.
-
setHandshakeIvl
public boolean setHandshakeIvl(int maxHandshakeIvl) The ZMQ_HANDSHAKE_IVL option shall set the maximum handshake interval for the specified socket. Handshaking is the exchange of socket configuration information (socket type, identity, security) that occurs when a connection is first opened, only for connection-oriented transports. If handshaking does not complete within the configured time, the connection shall be closed. The value 0 means no handshake time limit.- Parameters:
maxHandshakeIvl
- the maximum handshake interval- Returns:
- true if the option was set, otherwise false
- See Also:
-
setHeartbeatIvl
public boolean setHeartbeatIvl(int heartbeatIvl) The ZMQ_HEARTBEAT_IVL option shall set the interval between sending ZMTP heartbeats for the specified socket. If this option is set and is greater than 0, then a PING ZMTP command will be sent every ZMQ_HEARTBEAT_IVL milliseconds.- Parameters:
heartbeatIvl
- heartbeat interval in milliseconds- Returns:
- true if the option was set, otherwise false
-
setHeartbeatTimeout
public boolean setHeartbeatTimeout(int heartbeatTimeout) The ZMQ_HEARTBEAT_TIMEOUT option shall set how long to wait before timing-out a connection after sending a PING ZMTP command and not receiving any traffic. This option is only valid if ZMQ_HEARTBEAT_IVL is also set, and is greater than 0. The connection will time out if there is no traffic received after sending the PING command, but the received traffic does not have to be a PONG command - any received traffic will cancel the timeout.- Parameters:
heartbeatTimeout
- heartbeat timeout in milliseconds- Returns:
- true if the option was set, otherwise false
-
setHeartbeatTtl
public boolean setHeartbeatTtl(int heartbeatTtl) The ZMQ_HEARTBEAT_TTL option shall set the timeout on the remote peer for ZMTP heartbeats. If this option is greater than 0, the remote side shall time out the connection if it does not receive any more traffic within the TTL period. This option does not have any effect if ZMQ_HEARTBEAT_IVL is not set or is 0. Internally, this value is rounded down to the nearest decisecond, any value less than 100 will have no effect.- Parameters:
heartbeatTtl
- heartbeat time-to-live in milliseconds- Returns:
- true if the option was set, otherwise false
-
setHeartbeatContext
public boolean setHeartbeatContext(byte[] pingContext) The ZMQ_HEARTBEAT_CONTEXT option shall set the ping context of the peer for ZMTP heartbeats.This API is in DRAFT state and is subject to change at ANY time until declared stable.
If this option is set, every ping message sent for heartbeat will contain this context.
- Parameters:
pingContext
- the context to be sent with ping messages.- Returns:
- true if the option was set, otherwise false
-
getTos
public int getTos()Retrieve the IP_TOS option for the socket.- Returns:
- the value of the Type-Of-Service set for the socket.
- See Also:
-
setTos
public boolean setTos(int value) Sets the ToS fields (Differentiated services (DS) and Explicit Congestion Notification (ECN) field of the IP header. The ToS field is typically used to specify a packets priority. The availability of this option is dependent on intermediate network equipment that inspect the ToS field andprovide a path for low-delay, high-throughput, highly-reliable service, etc.- Returns:
- true if the option was set, otherwise false.
- See Also:
-
getReconnectIVLMax
public int getReconnectIVLMax()The ZMQ_RECONNECT_IVL_MAX option shall retrieve the maximum reconnection interval for the specified socket. This is the maximum period ØMQ shall wait between attempts to reconnect. On each reconnect attempt, the previous interval shall be doubled untill ZMQ_RECONNECT_IVL_MAX is reached. This allows for exponential backoff strategy. Default value means no exponential backoff is performed and reconnect interval calculations are only based on ZMQ_RECONNECT_IVL.- Returns:
- the reconnectIVLMax.
- See Also:
-
setReconnectIVLMax
Deprecated.this option uses integer range, usesetReconnectIVLMax(int)
insteadThe ZMQ_RECONNECT_IVL_MAX option shall set the maximum reconnection interval for the specified socket. This is the maximum period ØMQ shall wait between attempts to reconnect. On each reconnect attempt, the previous interval shall be doubled until ZMQ_RECONNECT_IVL_MAX is reached. This allows for exponential backoff strategy. Default value means no exponential backoff is performed and reconnect interval calculations are only based on ZMQ_RECONNECT_IVL.- Returns:
- true if the option was set, otherwise false
- See Also:
-
setReconnectIVLMax
public boolean setReconnectIVLMax(int value) The ZMQ_RECONNECT_IVL_MAX option shall set the maximum reconnection interval for the specified socket. This is the maximum period ØMQ shall wait between attempts to reconnect. On each reconnect attempt, the previous interval shall be doubled until ZMQ_RECONNECT_IVL_MAX is reached. This allows for exponential backoff strategy. Default value means no exponential backoff is performed and reconnect interval calculations are only based on ZMQ_RECONNECT_IVL.- Returns:
- true if the option was set, otherwise false
- See Also:
-
getMaxMsgSize
public long getMaxMsgSize()The option shall retrieve limit for the inbound messages. If a peer sends a message larger than ZMQ_MAXMSGSIZE it is disconnected. Value of -1 means no limit.- Returns:
- the maxMsgSize.
- See Also:
-
setMaxMsgSize
public boolean setMaxMsgSize(long value) Limits the size of the inbound message. If a peer sends a message larger than ZMQ_MAXMSGSIZE it is disconnected. Value of -1 means no limit.- Returns:
- true if the option was set, otherwise false
- See Also:
-
getSndHWM
public int getSndHWM()The ZMQ_SNDHWM option shall return the high water mark for outbound messages on the specified socket. The high water mark is a hard limit on the maximum number of outstanding messages ØMQ shall queue in memory for any single peer that the specified socket is communicating with. A value of zero means no limit. If this limit has been reached the socket shall enter an exceptional state and depending on the socket type, ØMQ shall take appropriate action such as blocking or dropping sent messages. Refer to the individual socket descriptions in zmq_socket(3) for details on the exact action taken for each socket type.- Returns:
- the SndHWM.
- See Also:
-
setSndHWM
Deprecated.this option uses integer range, usesetSndHWM(int)
insteadThe ZMQ_SNDHWM option shall set the high water mark for outbound messages on the specified socket. The high water mark is a hard limit on the maximum number of outstanding messages ØMQ shall queue in memory for any single peer that the specified socket is communicating with. A value of zero means no limit. If this limit has been reached the socket shall enter an exceptional state and depending on the socket type, ØMQ shall take appropriate action such as blocking or dropping sent messages. Refer to the individual socket descriptions in zmq_socket(3) for details on the exact action taken for each socket type.CAUTION: ØMQ does not guarantee that the socket will accept as many as ZMQ_SNDHWM messages, and the actual limit may be as much as 60-70% lower depending on the flow of messages on the socket.
- Returns:
- true if the option was set, otherwise false.
- See Also:
-
setSndHWM
public boolean setSndHWM(int value) The ZMQ_SNDHWM option shall set the high water mark for outbound messages on the specified socket. The high water mark is a hard limit on the maximum number of outstanding messages ØMQ shall queue in memory for any single peer that the specified socket is communicating with. A value of zero means no limit. If this limit has been reached the socket shall enter an exceptional state and depending on the socket type, ØMQ shall take appropriate action such as blocking or dropping sent messages. Refer to the individual socket descriptions in zmq_socket(3) for details on the exact action taken for each socket type.CAUTION: ØMQ does not guarantee that the socket will accept as many as ZMQ_SNDHWM messages, and the actual limit may be as much as 60-70% lower depending on the flow of messages on the socket.
- Parameters:
value
-- Returns:
- true if the option was set, otherwise false.
- See Also:
-
getRcvHWM
public int getRcvHWM()The ZMQ_RCVHWM option shall return the high water mark for inbound messages on the specified socket. The high water mark is a hard limit on the maximum number of outstanding messages ØMQ shall queue in memory for any single peer that the specified socket is communicating with. A value of zero means no limit. If this limit has been reached the socket shall enter an exceptional state and depending on the socket type, ØMQ shall take appropriate action such as blocking or dropping sent messages. Refer to the individual socket descriptions in zmq_socket(3) for details on the exact action taken for each socket type.- Returns:
- the recvHWM period.
- See Also:
-
setRcvHWM
Deprecated.this option uses integer range, usesetRcvHWM(int)
insteadThe ZMQ_RCVHWM option shall set the high water mark for inbound messages on the specified socket. The high water mark is a hard limit on the maximum number of outstanding messages ØMQ shall queue in memory for any single peer that the specified socket is communicating with. A value of zero means no limit. If this limit has been reached the socket shall enter an exceptional state and depending on the socket type, ØMQ shall take appropriate action such as blocking or dropping sent messages. Refer to the individual socket descriptions in zmq_socket(3) for details on the exact action taken for each socket type.- Returns:
- true if the option was set, otherwise false
- See Also:
-
setRcvHWM
public boolean setRcvHWM(int value) The ZMQ_RCVHWM option shall set the high water mark for inbound messages on the specified socket. The high water mark is a hard limit on the maximum number of outstanding messages ØMQ shall queue in memory for any single peer that the specified socket is communicating with. A value of zero means no limit. If this limit has been reached the socket shall enter an exceptional state and depending on the socket type, ØMQ shall take appropriate action such as blocking or dropping sent messages. Refer to the individual socket descriptions in zmq_socket(3) for details on the exact action taken for each socket type.- Parameters:
value
-- Returns:
- true if the option was set, otherwise false.
- See Also:
-
getHWM
Deprecated.- Returns:
- the High Water Mark.
- See Also:
-
setHWM
Deprecated.this option uses integer range, usesetHWM(int)
insteadThe 'ZMQ_HWM' option shall set the high water mark for the specified 'socket'. The high water mark is a hard limit on the maximum number of outstanding messages 0MQ shall queue in memory for any single peer that the specified 'socket' is communicating with.If this limit has been reached the socket shall enter an exceptional state and depending on the socket type, 0MQ shall take appropriate action such as blocking or dropping sent messages. Refer to the individual socket descriptions in the man page of zmq_socket[3] for details on the exact action taken for each socket type.
- Parameters:
hwm
- the number of messages to queue.- Returns:
- true if the option was set, otherwise false.
-
setHWM
public boolean setHWM(int hwm) The 'ZMQ_HWM' option shall set the high water mark for the specified 'socket'. The high water mark is a hard limit on the maximum number of outstanding messages 0MQ shall queue in memory for any single peer that the specified 'socket' is communicating with.If this limit has been reached the socket shall enter an exceptional state and depending on the socket type, 0MQ shall take appropriate action such as blocking or dropping sent messages. Refer to the individual socket descriptions in the man page of zmq_socket[3] for details on the exact action taken for each socket type.
- Parameters:
hwm
- the number of messages to queue.- Returns:
- true if the option was set, otherwise false
-
getSwap
Deprecated.- Returns:
- the number of messages to swap at most.
- See Also:
-
setConflate
public boolean setConflate(boolean conflate) If set, a socket shall keep only one message in its inbound/outbound queue, this message being the last message received/the last message to be sent. Ignores ZMQ_RCVHWM and ZMQ_SNDHWM options. Does not support multi-part messages, in particular, only one part of it is kept in the socket internal queue.- Parameters:
conflate
- true to keep only one message, false for standard behaviour.- Returns:
- true if the option was set, otherwise false.
- See Also:
-
isConflate
public boolean isConflate()If in conflate mode, a socket shall keep only one message in its inbound/outbound queue, this message being the last message received/the last message to be sent. Ignores ZMQ_RCVHWM and ZMQ_SNDHWM options. Does not support multi-part messages, in particular, only one part of it is kept in the socket internal queue.- Returns:
- true to keep only one message, false for standard behaviour.
- See Also:
-
getConflate
public boolean getConflate()If in conflate mode, a socket shall keep only one message in its inbound/outbound queue, this message being the last message received/the last message to be sent. Ignores ZMQ_RCVHWM and ZMQ_SNDHWM options. Does not support multi-part messages, in particular, only one part of it is kept in the socket internal queue.- Returns:
- true to keep only one message, false for standard behaviour.
- See Also:
-
setSwap
Deprecated.Get the Swap. The 'ZMQ_SWAP' option shall set the disk offload (swap) size for the specified 'socket'. A socket which has 'ZMQ_SWAP' set to a non-zero value may exceed its high water mark; in this case outstanding messages shall be offloaded to storage on disk rather than held in memory.- Parameters:
value
- The value of 'ZMQ_SWAP' defines the maximum size of the swap space in bytes.
-
getAffinity
public long getAffinity()- Returns:
- the affinity.
- See Also:
-
setAffinity
public boolean setAffinity(long value) Get the Affinity. The 'ZMQ_AFFINITY' option shall set the I/O thread affinity for newly created connections on the specified 'socket'.Affinity determines which threads from the 0MQ I/O thread pool associated with the socket's _context_ shall handle newly created connections. A value of zero specifies no affinity, meaning that work shall be distributed fairly among all 0MQ I/O threads in the thread pool. For non-zero values, the lowest bit corresponds to thread 1, second lowest bit to thread 2 and so on. For example, a value of 3 specifies that subsequent connections on 'socket' shall be handled exclusively by I/O threads 1 and 2.
See also in the man page of init[3] for details on allocating the number of I/O threads for a specific _context_.
- Parameters:
value
- the io_thread affinity.- Returns:
- true if the option was set, otherwise false
-
getIdentity
public byte[] getIdentity()- Returns:
- the Identitiy.
- See Also:
-
setIdentity
public boolean setIdentity(byte[] identity) The 'ZMQ_IDENTITY' option shall set the identity of the specified 'socket'. Socket identity determines if existing 0MQ infastructure (_message queues_, _forwarding devices_) shall be identified with a specific application and persist across multiple runs of the application.If the socket has no identity, each run of an application is completely separate from other runs. However, with identity set the socket shall re-use any existing 0MQ infrastructure configured by the previous run(s). Thus the application may receive messages that were sent in the meantime, _message queue_ limits shall be shared with previous run(s) and so on.
Identity should be at least one byte and at most 255 bytes long. Identities starting with binary zero are reserved for use by 0MQ infrastructure.
- Parameters:
identity
-- Returns:
- true if the option was set, otherwise false
-
getRate
public long getRate()- Returns:
- the Rate.
- See Also:
-
setRate
public boolean setRate(long value) The 'ZMQ_RATE' option shall set the maximum send or receive data rate for multicast transports such as in the man page of zmq_pgm[7] using the specified 'socket'.- Parameters:
value
- maximum send or receive data rate for multicast, default 100- Returns:
- true if the option was set, otherwise false
-
getRecoveryInterval
public long getRecoveryInterval()The ZMQ_RECOVERY_IVL option shall retrieve the recovery interval for multicast transports using the specified socket. The recovery interval determines the maximum time in milliseconds that a receiver can be absent from a multicast group before unrecoverable data loss will occur.- Returns:
- the RecoveryIntervall.
- See Also:
-
setRecoveryInterval
public boolean setRecoveryInterval(long value) The 'ZMQ_RECOVERY_IVL' option shall set the recovery interval for multicast transports using the specified 'socket'. The recovery interval determines the maximum time in seconds that a receiver can be absent from a multicast group before unrecoverable data loss will occur.CAUTION: Exercise care when setting large recovery intervals as the data needed for recovery will be held in memory. For example, a 1 minute recovery interval at a data rate of 1Gbps requires a 7GB in-memory buffer. {Purpose of this Method}
- Parameters:
value
- recovery interval for multicast in milliseconds, default 10000- Returns:
- true if the option was set, otherwise false.
- See Also:
-
setReqCorrelate
public boolean setReqCorrelate(boolean correlate) The default behavior of REQ sockets is to rely on the ordering of messages to match requests and responses and that is usually sufficient. When this option is set to true, the REQ socket will prefix outgoing messages with an extra frame containing a request id. That means the full message is (request id, identity, 0, user frames…). The REQ socket will discard all incoming messages that don't begin with these two frames. See also ZMQ_REQ_RELAXED.- Parameters:
correlate
- Whether to enable outgoing request ids.- Returns:
- true if the option was set, otherwise false
- See Also:
-
getReqCorrelate
Deprecated.The default behavior of REQ sockets is to rely on the ordering of messages to match requests and responses and that is usually sufficient. When this option is set to true, the REQ socket will prefix outgoing messages with an extra frame containing a request id. That means the full message is (request id, identity, 0, user frames…). The REQ socket will discard all incoming messages that don't begin with these two frames.- Returns:
- state of the ZMQ_REQ_CORRELATE option.
- See Also:
-
setReqRelaxed
public boolean setReqRelaxed(boolean relaxed) By default, a REQ socket does not allow initiating a new request with zmq_send(3) until the reply to the previous one has been received. When set to true, sending another message is allowed and has the effect of disconnecting the underlying connection to the peer from which the reply was expected, triggering a reconnection attempt on transports that support it. The request-reply state machine is reset and a new request is sent to the next available peer. If set to true, also enable ZMQ_REQ_CORRELATE to ensure correct matching of requests and replies. Otherwise a late reply to an aborted request can be reported as the reply to the superseding request.- Parameters:
relaxed
-- Returns:
- true if the option was set, otherwise false
- See Also:
-
getReqRelaxed
Deprecated.By default, a REQ socket does not allow initiating a new request with zmq_send(3) until the reply to the previous one has been received. When set to true, sending another message is allowed and has the effect of disconnecting the underlying connection to the peer from which the reply was expected, triggering a reconnection attempt on transports that support it. The request-reply state machine is reset and a new request is sent to the next available peer. If set to true, also enable ZMQ_REQ_CORRELATE to ensure correct matching of requests and replies. Otherwise a late reply to an aborted request can be reported as the reply to the superseding request.- Returns:
- state of the ZMQ_REQ_RELAXED option.
- See Also:
-
hasMulticastLoop
Deprecated.- Returns:
- the Multicast Loop.
- See Also:
-
setMulticastLoop
Deprecated.The 'ZMQ_MCAST_LOOP' option shall control whether data sent via multicast transports using the specified 'socket' can also be received by the sending host via loopback. A value of zero disables the loopback functionality, while the default value of 1 enables the loopback functionality. Leaving multicast loopback enabled when it is not required can have a negative impact on performance. Where possible, disable 'ZMQ_MCAST_LOOP' in production environments.- Parameters:
multicastLoop
-
-
getMulticastHops
public long getMulticastHops()- Returns:
- the Multicast Hops.
- See Also:
-
setMulticastHops
public boolean setMulticastHops(long value) Sets the time-to-live field in every multicast packet sent from this socket. The default is 1 which means that the multicast packets don't leave the local network.- Parameters:
value
- time-to-live field in every multicast packet, default 1
-
getReceiveTimeOut
public int getReceiveTimeOut()Retrieve the timeout for recv operation on the socket. If the value is 0, recv will return immediately, with null if there is no message to receive. If the value is -1, it will block until a message is available. For all other values, it will wait for a message for that amount of time before returning with a null and an EAGAIN error.- Returns:
- the Receive Timeout in milliseconds.
- See Also:
-
setReceiveTimeOut
public boolean setReceiveTimeOut(int value) Sets the timeout for receive operation on the socket. If the value is 0, recv will return immediately, with null if there is no message to receive. If the value is -1, it will block until a message is available. For all other values, it will wait for a message for that amount of time before returning with a null and an EAGAIN error.- Parameters:
value
- Timeout for receive operation in milliseconds. Default -1 (infinite)- Returns:
- true if the option was set, otherwise false.
- See Also:
-
getSendTimeOut
public int getSendTimeOut()Retrieve the timeout for send operation on the socket. If the value is 0, send will return immediately, with a false and an EAGAIN error if the message cannot be sent. If the value is -1, it will block until the message is sent. For all other values, it will try to send the message for that amount of time before returning with false and an EAGAIN error.- Returns:
- the Send Timeout in milliseconds.
- See Also:
-
setSendTimeOut
public boolean setSendTimeOut(int value) Sets the timeout for send operation on the socket. If the value is 0, send will return immediately, with a false if the message cannot be sent. If the value is -1, it will block until the message is sent. For all other values, it will try to send the message for that amount of time before returning with false and an EAGAIN error.- Parameters:
value
- Timeout for send operation in milliseconds. Default -1 (infinite)- Returns:
- true if the option was set, otherwise false.
- See Also:
-
setTCPKeepAlive
Deprecated.Override SO_KEEPALIVE socket option (where supported by OS) to enable keep-alive packets for a socket connection. Possible values are -1, 0, 1. The default value -1 will skip all overrides and do the OS default.- Parameters:
value
- The value of 'ZMQ_TCP_KEEPALIVE' to turn TCP keepalives on (1) or off (0).- Returns:
- true if the option was set, otherwise false.
-
getTCPKeepAliveSetting
Deprecated.- Returns:
- the keep alive setting.
- See Also:
-
setTCPKeepAliveCount
public boolean setTCPKeepAliveCount(long value) Override TCP_KEEPCNT socket option (where supported by OS). The default value -1 will skip all overrides and do the OS default.- Parameters:
value
- The value of 'ZMQ_TCP_KEEPALIVE_CNT' defines the number of keepalives before death.- Returns:
- true if the option was set, otherwise false.
-
getTCPKeepAliveCount
public long getTCPKeepAliveCount()- Returns:
- the keep alive count.
- See Also:
-
setTCPKeepAliveInterval
public boolean setTCPKeepAliveInterval(long value) Override TCP_KEEPINTVL socket option (where supported by OS). The default value -1 will skip all overrides and do the OS default.- Parameters:
value
- The value of 'ZMQ_TCP_KEEPALIVE_INTVL' defines the interval between keepalives. Unit is OS dependent.- Returns:
- true if the option was set, otherwise false.
-
getTCPKeepAliveInterval
public long getTCPKeepAliveInterval()- Returns:
- the keep alive interval.
- See Also:
-
setTCPKeepAliveIdle
public boolean setTCPKeepAliveIdle(long value) Override TCP_KEEPCNT (or TCP_KEEPALIVE on some OS) socket option (where supported by OS). The default value -1 will skip all overrides and do the OS default.- Parameters:
value
- The value of 'ZMQ_TCP_KEEPALIVE_IDLE' defines the interval between the last data packet sent over the socket and the first keepalive probe. Unit is OS dependent.- Returns:
- true if the option was set, otherwise false
-
getTCPKeepAliveIdle
public long getTCPKeepAliveIdle()- Returns:
- the keep alive idle value.
- See Also:
-
getSendBufferSize
public int getSendBufferSize()The ZMQ_SNDBUF option shall retrieve the underlying kernel transmit buffer size for the specified socket. For details refer to your operating system documentation for the SO_SNDBUF socket option.- Returns:
- the kernel send buffer size.
- See Also:
-
setSendBufferSize
Deprecated.this option uses integer range, usesetSendBufferSize(int)
insteadThe 'ZMQ_SNDBUF' option shall set the underlying kernel transmit buffer size for the 'socket' to the specified size in bytes. A value of zero means leave the OS default unchanged. For details please refer to your operating system documentation for the 'SO_SNDBUF' socket option.- Parameters:
value
- underlying kernel transmit buffer size for the 'socket' in bytes A value of zero means leave the OS default unchanged.- Returns:
- true if the option was set, otherwise false
- See Also:
-
setSendBufferSize
public boolean setSendBufferSize(int value) The 'ZMQ_SNDBUF' option shall set the underlying kernel transmit buffer size for the 'socket' to the specified size in bytes. A value of zero means leave the OS default unchanged. For details please refer to your operating system documentation for the 'SO_SNDBUF' socket option.- Parameters:
value
- underlying kernel transmit buffer size for the 'socket' in bytes A value of zero means leave the OS default unchanged.- Returns:
- true if the option was set, otherwise false
- See Also:
-
getReceiveBufferSize
public int getReceiveBufferSize()The ZMQ_RCVBUF option shall retrieve the underlying kernel receive buffer size for the specified socket. For details refer to your operating system documentation for the SO_RCVBUF socket option.- Returns:
- the kernel receive buffer size.
- See Also:
-
setReceiveBufferSize
Deprecated.this option uses integer range, usesetReceiveBufferSize(int)
insteadThe 'ZMQ_RCVBUF' option shall set the underlying kernel receive buffer size for the 'socket' to the specified size in bytes. For details refer to your operating system documentation for the 'SO_RCVBUF' socket option.- Parameters:
value
- Underlying kernel receive buffer size for the 'socket' in bytes. A value of zero means leave the OS default unchanged.- Returns:
- true if the option was set, otherwise false
- See Also:
-
setReceiveBufferSize
public boolean setReceiveBufferSize(int value) The 'ZMQ_RCVBUF' option shall set the underlying kernel receive buffer size for the 'socket' to the specified size in bytes. For details refer to your operating system documentation for the 'SO_RCVBUF' socket option.- Parameters:
value
- Underlying kernel receive buffer size for the 'socket' in bytes. A value of zero means leave the OS default unchanged.- Returns:
- true if the option was set, otherwise false
- See Also:
-
hasReceiveMore
public boolean hasReceiveMore()The 'ZMQ_RCVMORE' option shall return a boolean value indicating if the multi-part message currently being read from the specified 'socket' has more message parts to follow. If there are no message parts to follow or if the message currently being read is not a multi-part message a value of zero shall be returned. Otherwise, a value of 1 shall be returned.- Returns:
- true if there are more messages to receive.
-
getFD
The 'ZMQ_FD' option shall retrieve file descriptor associated with the 0MQ socket. The descriptor can be used to integrate 0MQ socket into an existing event loop. It should never be used for anything else than polling -- such as reading or writing. The descriptor signals edge-triggered IN event when something has happened within the 0MQ socket. It does not necessarily mean that the messages can be read or written. Check ZMQ_EVENTS option to find out whether the 0MQ socket is readable or writeable.- Returns:
- the underlying file descriptor.
-
getEvents
public int getEvents()The 'ZMQ_EVENTS' option shall retrieve event flags for the specified socket. If a message can be read from the socket ZMQ_POLLIN flag is set. If message can be written to the socket ZMQ_POLLOUT flag is set.- Returns:
- the mask of outstanding events.
-
subscribe
public boolean subscribe(byte[] topic) The 'ZMQ_SUBSCRIBE' option shall establish a new message filter on a 'ZMQ_SUB' socket. Newly created 'ZMQ_SUB' sockets shall filter out all incoming messages, therefore you should call this option to establish an initial message filter.An empty 'option_value' of length zero shall subscribe to all incoming messages. A non-empty 'option_value' shall subscribe to all messages beginning with the specified prefix. Mutiple filters may be attached to a single 'ZMQ_SUB' socket, in which case a message shall be accepted if it matches at least one filter.
- Parameters:
topic
-- Returns:
- true if the option was set, otherwise false
-
subscribe
The 'ZMQ_SUBSCRIBE' option shall establish a new message filter on a 'ZMQ_SUB' socket. Newly created 'ZMQ_SUB' sockets shall filter out all incoming messages, therefore you should call this option to establish an initial message filter.An empty 'option_value' of length zero shall subscribe to all incoming messages. A non-empty 'option_value' shall subscribe to all messages beginning with the specified prefix. Mutiple filters may be attached to a single 'ZMQ_SUB' socket, in which case a message shall be accepted if it matches at least one filter.
- Parameters:
topic
-- Returns:
- true if the option was set, otherwise false
-
unsubscribe
public boolean unsubscribe(byte[] topic) The 'ZMQ_UNSUBSCRIBE' option shall remove an existing message filter on a 'ZMQ_SUB' socket. The filter specified must match an existing filter previously established with the 'ZMQ_SUBSCRIBE' option. If the socket has several instances of the same filter attached the 'ZMQ_UNSUBSCRIBE' option shall remove only one instance, leaving the rest in place and functional.- Parameters:
topic
-- Returns:
- true if the option was set, otherwise false
-
unsubscribe
The 'ZMQ_UNSUBSCRIBE' option shall remove an existing message filter on a 'ZMQ_SUB' socket. The filter specified must match an existing filter previously established with the 'ZMQ_SUBSCRIBE' option. If the socket has several instances of the same filter attached the 'ZMQ_UNSUBSCRIBE' option shall remove only one instance, leaving the rest in place and functional.- Parameters:
topic
-- Returns:
- true if the option was set, otherwise false
-
join
Joins a group. Opposite action isleave(String)
- Parameters:
group
- the name of the group to join. Limited to 16 characters.- Returns:
- true if the group was no already joined, otherwise false.
-
leave
Leaves a group. Opposite action isjoin(String)
- Parameters:
group
- the name of the group to leave. Limited to 16 characters.- Returns:
- false if the group was not joined before, otherwise true.
-
setEncoder
Deprecated.Set custom Encoder- Parameters:
cls
-- Returns:
- true if the option was set, otherwise false
-
setDecoder
Deprecated.Set custom Decoder- Parameters:
cls
-- Returns:
- true if the option was set, otherwise false
-
setMsgAllocationHeapThreshold
public boolean setMsgAllocationHeapThreshold(int threshold) Sets the limit threshold where messages of a given size will be allocated using Direct ByteBuffer. It means that after this limit, there will be a slight penalty cost at the creation, but the subsequent operations will be faster. Set to 0 or negative to disable the threshold mechanism.- Parameters:
threshold
- the threshold to set for the size limit of messages. 0 or negative to disable this system.- Returns:
- true if the option was set, otherwise false.
-
getMsgAllocationHeapThreshold
public int getMsgAllocationHeapThreshold()Gets the limit threshold where messages of a given size will be allocated using Direct ByteBuffer. It means that after this limit, there will be a slight penalty cost at the creation, but the subsequent operations will be faster.- Returns:
- the threshold
-
setMsgAllocator
Sets a custom message allocator.- Parameters:
allocator
- the custom allocator.- Returns:
- true if the option was set, otherwise false.
-
setSelectorChooser
Set a customSelectorProvider
chooser.- Parameters:
chooser
- the custom chooser.- Returns:
- true if the option was set, otherwise false.
-
getSelectorProviderChooser
Return the customSelectorProvider
chooser.- Returns:
- the
SelectorProvider
chooser.
-
setConnectRid
The ZMQ_CONNECT_RID option sets the peer id of the next host connected via the connect() call, and immediately readies that connection for data transfer with the named id. This option applies only to the first subsequent call to connect(), calls thereafter use default connection behavior. Typical use is to set this socket option ahead of each connect() attempt to a new host. Each connection MUST be assigned a unique name. Assigning a name that is already in use is not allowed. Useful when connecting ROUTER to ROUTER, or STREAM to STREAM, as it allows for immediate sending to peers. Outbound id framing requirements for ROUTER and STREAM sockets apply. The peer id should be from 1 to 255 bytes long and MAY NOT start with binary zero.- Parameters:
rid
- the peer id of the next host.- Returns:
- true if the option was set, otherwise false.
-
setConnectRid
public boolean setConnectRid(byte[] rid) The ZMQ_CONNECT_RID option sets the peer id of the next host connected via the connect() call, and immediately readies that connection for data transfer with the named id. This option applies only to the first subsequent call to connect(), calls thereafter use default connection behavior. Typical use is to set this socket option ahead of each connect() attempt to a new host. Each connection MUST be assigned a unique name. Assigning a name that is already in use is not allowed. Useful when connecting ROUTER to ROUTER, or STREAM to STREAM, as it allows for immediate sending to peers. Outbound id framing requirements for ROUTER and STREAM sockets apply. The peer id should be from 1 to 255 bytes long and MAY NOT start with binary zero.- Parameters:
rid
- the peer id of the next host.- Returns:
- true if the option was set, otherwise false.
-
setRouterRaw
public boolean setRouterRaw(boolean raw) Sets the raw mode on the ROUTER, when set to true. When the ROUTER socket is in raw mode, and when using the tcp:// transport, it will read and write TCP data without ØMQ framing. This lets ØMQ applications talk to non-ØMQ applications. When using raw mode, you cannot set explicit identities, and the ZMQ_SNDMORE flag is ignored when sending data messages. In raw mode you can close a specific connection by sending it a zero-length message (following the identity frame).- Parameters:
raw
- true to set the raw mode on the ROUTER.- Returns:
- true if the option was set, otherwise false.
-
setProbeRouter
public boolean setProbeRouter(boolean probe) When set to true, the socket will automatically send an empty message when a new connection is made or accepted. You may set this on REQ, DEALER, or ROUTER sockets connected to a ROUTER socket. The application must filter such empty messages. The ZMQ_PROBE_ROUTER option in effect provides the ROUTER application with an event signaling the arrival of a new peer.- Parameters:
probe
- true to send automatically an empty message when a new connection is made or accepted.- Returns:
- true if the option was set, otherwise false.
-
setRouterMandatory
public boolean setRouterMandatory(boolean mandatory) Sets the ROUTER socket behavior when an unroutable message is encountered. A value of false is the default and discards the message silently when it cannot be routed or the peers SNDHWM is reached. A value of true returns an EHOSTUNREACH error code if the message cannot be routed or EAGAIN error code if the SNDHWM is reached and ZMQ_DONTWAIT was used. Without ZMQ_DONTWAIT it will block until the SNDTIMEO is reached or a spot in the send queue opens up.- Parameters:
mandatory
- A value of false is the default and discards the message silently when it cannot be routed. A value of true returns an EHOSTUNREACH error code if the message cannot be routed.- Returns:
- true if the option was set, otherwise false.
-
setRouterHandover
public boolean setRouterHandover(boolean handover) If two clients use the same identity when connecting to a ROUTER, the results shall depend on the ZMQ_ROUTER_HANDOVER option setting. If that is not set (or set to the default of false), the ROUTER socket shall reject clients trying to connect with an already-used identity. If that option is set to true, the ROUTER socket shall hand-over the connection to the new client and disconnect the existing one.- Parameters:
handover
- A value of false, (default) the ROUTER socket shall reject clients trying to connect with an already-used identity A value of true, the ROUTER socket shall hand-over the connection to the new client and disconnect the existing one- Returns:
- true if the option was set, otherwise false.
-
setXpubVerbose
public boolean setXpubVerbose(boolean verbose) Sets the XPUB socket behavior on new subscriptions and unsubscriptions.- Parameters:
verbose
- A value of false is the default and passes only new subscription messages to upstream. A value of true passes all subscription messages upstream.- Returns:
- true if the option was set, otherwise false.
-
setXpubNoDrop
public boolean setXpubNoDrop(boolean noDrop) Sets the XPUB socket behaviour to return error EAGAIN if SENDHWM is reached and the message could not be send. A value of false is the default and drops the message silently when the peers SNDHWM is reached. A value of true returns an EAGAIN error code if the SNDHWM is reached and ZMQ_DONTWAIT was used.- Parameters:
noDrop
-- Returns:
- true if the option was set, otherwise false.
-
setXpubManual
public boolean setXpubManual(boolean manual) -
setXpubVerboser
public boolean setXpubVerboser(boolean verboser) -
getIPv4Only
Deprecated.useisIPv6()
instead (inverted logic: ipv4 = true <==> ipv6 = false)- Returns:
- the IPV4ONLY
- See Also:
-
isIPv6
public boolean isIPv6()Retrieve the IPv6 option for the socket. A value of true means IPv6 is enabled on the socket, while false means the socket will use only IPv4. When IPv6 is enabled the socket will connect to, or accept connections from, both IPv4 and IPv6 hosts.- Returns:
- the IPV6 configuration.
- See Also:
-
getIPv6
public boolean getIPv6()Retrieve the IPv6 option for the socket. A value of true means IPv6 is enabled on the socket, while false means the socket will use only IPv4. When IPv6 is enabled the socket will connect to, or accept connections from, both IPv4 and IPv6 hosts.- Returns:
- the IPV6 configuration.
- See Also:
-
setIPv4Only
Deprecated.usesetIPv6(boolean)
instead (inverted logic: ipv4 = true <==> ipv6 = false)The 'ZMQ_IPV4ONLY' option shall set the underlying native socket type. An IPv6 socket lets applications connect to and accept connections from both IPv4 and IPv6 hosts.- Parameters:
v4only
- A value of true will use IPv4 sockets, while the value of false will use IPv6 sockets- Returns:
- true if the option was set, otherwise false
-
setIPv6
public boolean setIPv6(boolean v6) Set the IPv6 option for the socket.
A value of true means IPv6 is enabled on the socket, while false means the socket will use only IPv4. When IPv6 is enabled the socket will connect to, or accept connections from, both IPv4 and IPv6 hosts.
The default value is false, unless the following system properties are set:
- java.net.preferIPv4Stack=false
- java.net.preferIPv6Addresses=true
- Parameters:
v6
- A value of true will use IPv6 sockets, while the value of false will use IPv4 sockets only- Returns:
- true if the option was set, otherwise false
- See Also:
-
getTCPKeepAlive
public int getTCPKeepAlive()- Returns:
- the keep alive setting.
- See Also:
-
setTCPKeepAlive
public boolean setTCPKeepAlive(int optVal) Override SO_KEEPALIVE socket option (where supported by OS) to enable keep-alive packets for a socket connection. Possible values are -1, 0, 1. The default value -1 will skip all overrides and do the OS default.- Parameters:
optVal
- The value of 'ZMQ_TCP_KEEPALIVE' to turn TCP keepalives on (1) or off (0).- Returns:
- true if the option was set, otherwise false
-
getDelayAttachOnConnect
Deprecated.usesetImmediate(boolean)
instead (inverted logic: immediate = true <==> delay attach on connect = false)- See Also:
-
setDelayAttachOnConnect
Deprecated.usesetImmediate(boolean)
instead (warning, the boolean is inverted)Accept messages only when connections are madeIf set to true, will delay the attachment of a pipe on connect until the underlying connection has completed. This will cause the socket to block if there are no other connections, but will prevent queues from filling on pipes awaiting connection
- Parameters:
value
- The value of 'ZMQ_DELAY_ATTACH_ON_CONNECT'. Default false.- Returns:
- true if the option was set
-
isImmediate
public boolean isImmediate()Retrieve the state of the attach on connect value. If false, will delay the attachment of a pipe on connect until the underlying connection has completed. This will cause the socket to block if there are no other connections, but will prevent queues from filling on pipes awaiting connection.- See Also:
-
getImmediate
public boolean getImmediate()Retrieve the state of the attach on connect value. If false, will delay the attachment of a pipe on connect until the underlying connection has completed. This will cause the socket to block if there are no other connections, but will prevent queues from filling on pipes awaiting connection.- See Also:
-
setImmediate
public boolean setImmediate(boolean value) Accept messages immediately or only when connections are madeBy default queues will fill on outgoing connections even if the connection has not completed. This can lead to "lost" messages on sockets with round-robin routing (REQ, PUSH, DEALER). If this option is set to false, messages shall be queued only to completed connections. This will cause the socket to block if there are no other connections, but will prevent queues from filling on pipes awaiting connection.
- Parameters:
value
- The value of 'ZMQ_IMMEDIATE'. Default true.- Returns:
- true if the option was set, otherwise false.
- See Also:
-
setSocksProxy
Sets the SOCKS5 proxy address that shall be used by the socket for the TCP connection(s). Does not support SOCKS5 authentication. If the endpoints are domain names instead of addresses they shall not be resolved and they shall be forwarded unchanged to the SOCKS proxy service in the client connection request message (address type 0x03 domain name).- Parameters:
proxy
-- Returns:
- true if the option was set, otherwise false.
- See Also:
-
setSocksProxy
public boolean setSocksProxy(byte[] proxy) Sets the SOCKS5 proxy address that shall be used by the socket for the TCP connection(s). Does not support SOCKS5 authentication. If the endpoints are domain names instead of addresses they shall not be resolved and they shall be forwarded unchanged to the SOCKS proxy service in the client connection request message (address type 0x03 domain name).- Parameters:
proxy
-- Returns:
- true if the option was set, otherwise false.
- See Also:
-
getSocksProxy
The ZMQ_SOCKS_PROXY option shall retrieve the SOCKS5 proxy address in string format. The returned value MAY be empty.- Returns:
- the SOCKS5 proxy address in string format
- See Also:
-
getLastEndpoint
The ZMQ_LAST_ENDPOINT option shall retrieve the last endpoint bound for TCP and IPC transports. The returned value will be a string in the form of a ZMQ DSN. Note that if the TCP host is INADDR_ANY, indicated by a *, then the returned address will be 0.0.0.0 (for IPv4). -
setZapDomain
Sets the domain for ZAP (ZMQ RFC 27) authentication. For NULL security (the default on all tcp:// connections), ZAP authentication only happens if you set a non-empty domain. For PLAIN and CURVE security, ZAP requests are always made, if there is a ZAP handler present. See http://rfc.zeromq.org/spec:27 for more details.- Parameters:
domain
- the domain of ZAP authentication- Returns:
- true if the option was set
- See Also:
-
setZapDomain
public boolean setZapDomain(byte[] domain) Sets the domain for ZAP (ZMQ RFC 27) authentication. For NULL security (the default on all tcp:// connections), ZAP authentication only happens if you set a non-empty domain. For PLAIN and CURVE security, ZAP requests are always made, if there is a ZAP handler present. See http://rfc.zeromq.org/spec:27 for more details.- Parameters:
domain
- the domain of ZAP authentication- Returns:
- true if the option was set
- See Also:
-
getZapDomain
The ZMQ_ZAP_DOMAIN option shall retrieve the last ZAP domain set for the socket. The returned value MAY be empty.- Returns:
- the domain of ZAP authentication
- See Also:
-
setZAPDomain
Sets the domain for ZAP (ZMQ RFC 27) authentication. For NULL security (the default on all tcp:// connections), ZAP authentication only happens if you set a non-empty domain. For PLAIN and CURVE security, ZAP requests are always made, if there is a ZAP handler present. See http://rfc.zeromq.org/spec:27 for more details.- Parameters:
domain
- the domain of ZAP authentication- Returns:
- true if the option was set
- See Also:
-
setZAPDomain
public boolean setZAPDomain(byte[] domain) Sets the domain for ZAP (ZMQ RFC 27) authentication. For NULL security (the default on all tcp:// connections), ZAP authentication only happens if you set a non-empty domain. For PLAIN and CURVE security, ZAP requests are always made, if there is a ZAP handler present. See http://rfc.zeromq.org/spec:27 for more details.- Parameters:
domain
- the domain of ZAP authentication- Returns:
- true if the option was set
- See Also:
-
getZAPDomain
The ZMQ_ZAP_DOMAIN option shall retrieve the last ZAP domain set for the socket. The returned value MAY be empty.- Returns:
- the domain of ZAP authentication
- See Also:
-
getSelfAddressPropertyName
The ZMQ_SELFADDR_PROPERTY_NAME option shall retrieve the metadata record used to store the self address. The returned value MAY be null or empty.- Returns:
- the meta record name
- See Also:
-
setSelfAddressPropertyName
Sets the field name where the self address will be stored. If set to null or empty string, it will not be stored- Parameters:
recordName
- the name of the field- Returns:
- true if the option was set
- See Also:
-
setAsServerPlain
Deprecated.the naming is inconsistent with jzmq, please usesetPlainServer(boolean)
insteadDefines whether the socket will act as server for PLAIN security, see zmq_plain(7). A value of true means the socket will act as PLAIN server. A value of false means the socket will not act as PLAIN server, and its security role then depends on other option settings. Setting this to false shall reset the socket security to NULL.- Parameters:
server
- true if the role of the socket should be server for PLAIN security.- Returns:
- true if the option was set, otherwise false.
- See Also:
-
setPlainServer
public boolean setPlainServer(boolean server) Defines whether the socket will act as server for PLAIN security, see zmq_plain(7). A value of true means the socket will act as PLAIN server. A value of false means the socket will not act as PLAIN server, and its security role then depends on other option settings. Setting this to false shall reset the socket security to NULL.- Parameters:
server
- true if the role of the socket should be server for PLAIN security.- Returns:
- true if the option was set, otherwise false.
- See Also:
-
isAsServerPlain
Deprecated.the naming is inconsistent with jzmq, please usegetPlainServer()
insteadReturns the ZMQ_PLAIN_SERVER option, if any, previously set on the socket.- Returns:
- true if the role of the socket should be server for the PLAIN mechanism.
- See Also:
-
getAsServerPlain
Deprecated.the naming is inconsistent with jzmq, please usegetPlainServer()
insteadReturns the ZMQ_PLAIN_SERVER option, if any, previously set on the socket.- Returns:
- true if the role of the socket should be server for the PLAIN mechanism.
- See Also:
-
getPlainServer
public boolean getPlainServer()Returns the ZMQ_PLAIN_SERVER option, if any, previously set on the socket.- Returns:
- true if the role of the socket should be server for the PLAIN mechanism.
- See Also:
-
setPlainUsername
Sets the username for outgoing connections over TCP or IPC. If you set this to a non-null value, the security mechanism used for connections shall be PLAIN, see zmq_plain(7). If you set this to a null value, the security mechanism used for connections shall be NULL, see zmq_null(3).- Parameters:
username
- the username to set.- Returns:
- true if the option was set, otherwise false.
-
setPlainPassword
Sets the password for outgoing connections over TCP or IPC. If you set this to a non-null value, the security mechanism used for connections shall be PLAIN, see zmq_plain(7). If you set this to a null value, the security mechanism used for connections shall be NULL, see zmq_null(3).- Parameters:
password
- the password to set.- Returns:
- true if the option was set, otherwise false.
-
setPlainUsername
public boolean setPlainUsername(byte[] username) Sets the username for outgoing connections over TCP or IPC. If you set this to a non-null value, the security mechanism used for connections shall be PLAIN, see zmq_plain(7). If you set this to a null value, the security mechanism used for connections shall be NULL, see zmq_null(3).- Parameters:
username
- the username to set.- Returns:
- true if the option was set, otherwise false.
-
setPlainPassword
public boolean setPlainPassword(byte[] password) Sets the password for outgoing connections over TCP or IPC. If you set this to a non-null value, the security mechanism used for connections shall be PLAIN, see zmq_plain(7). If you set this to a null value, the security mechanism used for connections shall be NULL, see zmq_null(3).- Parameters:
password
- the password to set.- Returns:
- true if the option was set, otherwise false.
-
getPlainUsername
The ZMQ_PLAIN_USERNAME option shall retrieve the last username set for the PLAIN security mechanism.- Returns:
- the plain username.
-
getPlainPassword
The ZMQ_PLAIN_PASSWORD option shall retrieve the last password set for the PLAIN security mechanism. The returned value MAY be empty.- Returns:
- the plain password.
-
setAsServerCurve
Deprecated.the naming is inconsistent with jzmq, please usesetCurveServer(boolean)
insteadDefines whether the socket will act as server for CURVE security, see zmq_curve(7). A value of true means the socket will act as CURVE server. A value of false means the socket will not act as CURVE server, and its security role then depends on other option settings. Setting this to false shall reset the socket security to NULL. When you set this you must also set the server's secret key using the ZMQ_CURVE_SECRETKEY option. A server socket does not need to know its own public key.- Parameters:
server
- true if the role of the socket should be server for CURVE mechanism- Returns:
- true if the option was set
- See Also:
-
setCurveServer
public boolean setCurveServer(boolean server) Defines whether the socket will act as server for CURVE security, see zmq_curve(7). A value of true means the socket will act as CURVE server. A value of false means the socket will not act as CURVE server, and its security role then depends on other option settings. Setting this to false shall reset the socket security to NULL. When you set this you must also set the server's secret key using the ZMQ_CURVE_SECRETKEY option. A server socket does not need to know its own public key.- Parameters:
server
- true if the role of the socket should be server for CURVE mechanism- Returns:
- true if the option was set
- See Also:
-
isAsServerCurve
Deprecated.the naming is inconsistent with jzmq, please usegetCurveServer()
insteadTells if the socket will act as server for CURVE security.- Returns:
- true if the role of the socket should be server for CURVE mechanism.
- See Also:
-
getCurveServer
public boolean getCurveServer()Tells if the socket will act as server for CURVE security.- Returns:
- true if the role of the socket should be server for CURVE mechanism.
- See Also:
-
getAsServerCurve
Deprecated.the naming is inconsistent with jzmq, please usegetCurveServer()
insteadTells if the socket will act as server for CURVE security.- Returns:
- true if the role of the socket should be server for CURVE mechanism.
- See Also:
-
setCurvePublicKey
public boolean setCurvePublicKey(byte[] key) Sets the socket's long term public key. You must set this on CURVE client sockets, see zmq_curve(7). You can provide the key as 32 binary bytes, or as a 40-character string encoded in the Z85 encoding format. The public key must always be used with the matching secret key. To generate a public/secret key pair, useCurve.keypair()
orCurve.keypairZ85()
.- Parameters:
key
- the curve public key- Returns:
- true if the option was set, otherwise false
- See Also:
-
setCurveServerKey
public boolean setCurveServerKey(byte[] key) Sets the socket's long term server key. You must set this on CURVE client sockets, see zmq_curve(7). You can provide the key as 32 binary bytes, or as a 40-character string encoded in the Z85 encoding format. This key must have been generated together with the server's secret key. To generate a public/secret key pair, useCurve.keypair()
orCurve.keypairZ85()
.- Parameters:
key
- the curve server key- Returns:
- true if the option was set, otherwise false
- See Also:
-
setCurveSecretKey
public boolean setCurveSecretKey(byte[] key) Sets the socket's long term secret key. You must set this on both CURVE client and server sockets, see zmq_curve(7). You can provide the key as 32 binary bytes, or as a 40-character string encoded in the Z85 encoding format. To generate a public/secret key pair, useCurve.keypair()
orCurve.keypairZ85()
.- Parameters:
key
- the curve secret key- Returns:
- true if the option was set, otherwise false
- See Also:
-
getCurvePublicKey
public byte[] getCurvePublicKey()Retrieves the current long term public key for the socket in binary format of 32 bytes.- Returns:
- key the curve public key
- See Also:
-
getCurveServerKey
public byte[] getCurveServerKey()Retrieves the current server key for the socket in binary format of 32 bytes.- Returns:
- key the curve server key
- See Also:
-
getCurveSecretKey
public byte[] getCurveSecretKey()Retrieves the current long term secret key for the socket in binary format of 32 bytes.- Returns:
- key the curve secret key
- See Also:
-
getMechanism
The ZMQ_MECHANISM option shall retrieve the current security mechanism for the socket.- Returns:
- the current mechanism.
-
setHelloMsg
public boolean setHelloMsg(byte[] helloMsg) When set, the socket will automatically send a hello message when a new connection is made or accepted. You may set this on DEALER or ROUTER sockets. The combination with ZMQ_HEARTBEAT_IVL is powerful and simplify protocols, as now heartbeat and sending the hello message can be left out of protocols and be handled by zeromq.- Parameters:
helloMsg
-- Returns:
- true if the option was set, otherwise false
-
bind
Bind to network interface. Start listening for new connections.- Parameters:
addr
- the endpoint to bind to.- Returns:
- true if the socket was bound, otherwise false.
-
bindToRandomPort
Bind to network interface to a random port. Start listening for new connections.- Parameters:
addr
- the endpoint to bind to.
-
bindToRandomPort
Bind to network interface to a random port. Start listening for new connections.- Parameters:
addr
- the endpoint to bind to.min
- The minimum port in the range of ports to try.max
- The maximum port in the range of ports to try.
-
connect
Connects the socket to an endpoint and then accepts incoming connections on that endpoint.The 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 connect to.ØMQ provides the the following transports:
- tcp - unicast transport using TCP
- ipc - local inter-process communication transport
- inproc - local in-process (inter-thread) communication transport
For most transports and socket types the connection is not performed immediately but as needed by ØMQ.
Thus a successful call to connect(String) 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 server socket is bound and a client socket is connected to it does not matter.
The first exception is when using the inproc:// transport: you must callbind(String)
before calling connect().
The second exception are ZMQ_PAIR sockets, which do not automatically reconnect to endpoints.Following a connect(), for socket types except for ZMQ_ROUTER, the socket enters its normal ready state.
By contrast, following abind(String)
alone, the socket enters a mute state in which the socket blocks or drops messages according to the socket type.
A ZMQ_ROUTER socket enters its normal ready state for a specific peer only when handshaking is complete for that peer, which may take an arbitrary time.- Parameters:
addr
- the endpoint to connect to.- Returns:
- true if the socket was connected, otherwise false.
-
disconnect
Disconnect from remote application.- Parameters:
addr
- the endpoint to disconnect from.- Returns:
- true if successful.
-
unbind
Stop accepting connections on a socket.- Parameters:
addr
- the endpoint to unbind from.- Returns:
- true if successful.
-
connectPeer
create outgoing connection from socket and return the connection routing id in thread-safe and atomic way. The function is supported only on theSocketType.PEER
orSocketType.RAW
socket types and would return `0` with 'errno' set to 'ENOTSUP' otherwise.- Parameters:
addr
- the endpoint of the remote socket.- Returns:
- the endpoint routing ID.
-
sendMsg
Queues a message created from data, so it can be sent.- Parameters:
msg
- theMsg
to send. The message is either a single-part message by itself, or the last part of a multi-part message.- Returns:
- true when it has been queued on the socket and ØMQ has assumed responsibility for the message. This does not indicate that the message has been transmitted to the network.
-
sendMsgMore
Queues a multi-part message created from data, so it can be sent.- Parameters:
msg
- the message to send. further message parts are to follow.- Returns:
- true when it has been queued on the socket and ØMQ has assumed responsibility for the message. This does not indicate that the message has been transmitted to the network.
-
sendMsg
Queues a message created from data, so it can be sent.- Parameters:
msg
- theMsg
to send. The message is either a single-part message by itself, or the last part of a multi-part message.flags
- a combination (with + or |) of the flags defined below:DONTWAIT
: For socket types (DEALER
,PUSH
) that block when there are no available peers (or all peers have full high-water mark), specifies that the operation should be performed in non-blocking mode. If the message cannot be queued on the socket, the method shall fail with errno set to EAGAIN.SNDMORE
: Specifies that the message being sent is a multi-part message, and that further message parts are to follow.- 0 : blocking send of a single-part message or the last of a multi-part message
- Returns:
- true when it has been queued on the socket and ØMQ has assumed responsibility for the message. This does not indicate that the message has been transmitted to the network.
-
send
Queues a message created from data, so it can be sent.- Parameters:
data
- the data to send. The data is either a single-part message by itself, or the last part of a multi-part message.- Returns:
- true when it has been queued on the socket and ØMQ has assumed responsibility for the message. This does not indicate that the message has been transmitted to the network.
-
sendMore
Queues a multi-part message created from data, so it can be sent.- Parameters:
data
- the data to send. further message parts are to follow.- Returns:
- true when it has been queued on the socket and ØMQ has assumed responsibility for the message. This does not indicate that the message has been transmitted to the network.
-
send
Queues a message created from data.- Parameters:
data
- the data to send.flags
- a combination (with + or |) of the flags defined below:DONTWAIT
: For socket types (DEALER
,PUSH
) that block when there are no available peers (or all peers have full high-water mark), specifies that the operation should be performed in non-blocking mode. If the message cannot be queued on the socket, the method shall fail with errno set to EAGAIN.SNDMORE
: Specifies that the message being sent is a multi-part message, and that further message parts are to follow.- 0 : blocking send of a single-part message or the last of a multi-part message
- Returns:
- true when it has been queued on the socket and ØMQ has assumed responsibility for the message. This does not indicate that the message has been transmitted to the network.
-
send
public boolean send(byte[] data) Queues a message created from data, so it can be sent.- Parameters:
data
- the data to send. The data is either a single-part message by itself, or the last part of a multi-part message.- Returns:
- true when it has been queued on the socket and ØMQ has assumed responsibility for the message. This does not indicate that the message has been transmitted to the network.
-
sendMore
public boolean sendMore(byte[] data) Queues a multi-part message created from data, so it can be sent.- Parameters:
data
- the data to send. further message parts are to follow.- Returns:
- true when it has been queued on the socket and ØMQ has assumed responsibility for the message. This does not indicate that the message has been transmitted to the network.
-
send
public boolean send(byte[] data, int flags) Queues a message created from data, so it can be sent.- Parameters:
data
- the data to send.flags
- a combination (with + or |) of the flags defined below:DONTWAIT
: For socket types (DEALER
,PUSH
) that block when there are no available peers (or all peers have full high-water mark), specifies that the operation should be performed in non-blocking mode. If the message cannot be queued on the socket, the method shall fail with errno set to EAGAIN.SNDMORE
: Specifies that the message being sent is a multi-part message, and that further message parts are to follow.- 0 : blocking send of a single-part message or the last of a multi-part message
- Returns:
- true when it has been queued on the socket and ØMQ has assumed responsibility for the message. This does not indicate that the message has been transmitted to the network.
-
send
Queues a message created from data, so it can be sent, the call be canceled by calling cancellationTokenZMQ.CancellationToken.cancel()
. If the operation is canceled a ZMQException is thrown with error code set toZError.ECANCELED
.- Parameters:
data
- the data to send.flags
- a combination (with + or |) of the flags defined below:DONTWAIT
: For socket types (DEALER
,PUSH
) that block when there are no available peers (or all peers have full high-water mark), specifies that the operation should be performed in non-blocking mode. If the message cannot be queued on the socket, the method shall fail with errno set to EAGAIN.SNDMORE
: Specifies that the message being sent is a multi-part message, and that further message parts are to follow.- 0 : blocking send of a single-part message or the last of a multi-part message
- Returns:
- true when it has been queued on the socket and ØMQ has assumed responsibility for the message. This does not indicate that the message has been transmitted to the network.
-
send
public boolean send(byte[] data, int off, int length, int flags) Queues a message created from data, so it can be sent.- Parameters:
data
- the data to send.off
- the index of the first byte to be sent.length
- the number of bytes to be sent.flags
- a combination (with + or |) of the flags defined below:DONTWAIT
: For socket types (DEALER
,PUSH
) that block when there are no available peers (or all peers have full high-water mark), specifies that the operation should be performed in non-blocking mode. If the message cannot be queued on the socket, the method shall fail with errno set to EAGAIN.SNDMORE
: Specifies that the message being sent is a multi-part message, and that further message parts are to follow.- 0 : blocking send of a single-part message or the last of a multi-part message
- Returns:
- true when it has been queued on the socket and ØMQ has assumed responsibility for the message. This does not indicate that the message has been transmitted to the network.
-
sendByteBuffer
Queues a message created from data, so it can be sent.- Parameters:
data
- ByteBuffer payloadflags
- a combination (with + or |) of the flags defined below:DONTWAIT
: For socket types (DEALER
,PUSH
) that block when there are no available peers (or all peers have full high-water mark), specifies that the operation should be performed in non-blocking mode. If the message cannot be queued on the socket, the method shall fail with errno set to EAGAIN.SNDMORE
: Specifies that the message being sent is a multi-part message, and that further message parts are to follow.- 0 : blocking send of a single-part message or the last of a multi-part message
- Returns:
- the number of bytes queued, -1 on error
-
sendPicture
Queues a 'picture' message to the socket (or actor), so it can be sent.- Parameters:
picture
- The picture is a string that defines the type of each frame. This makes it easy to send a complex multiframe message in one call. The picture can contain any of these characters, each corresponding to zero or one arguments:Type of arguments i = int (stores signed integer) 1 = byte (stores 8-bit unsigned integer) 2 = int (stores 16-bit unsigned integer) 4 = long (stores 32-bit unsigned integer) 8 = long (stores 64-bit unsigned integer) s = String b = byte[] f = ZFrame m = ZMsg (sends all frames in the ZMsg) z = sends zero-sized frame (0 arguments) Also see
recvPicture(String)
} how to recv a multiframe picture.args
- Arguments according to the picture- Returns:
- true if successful, false if sending failed for any reason
-
sendBinaryPicture
Queues a binary encoded 'picture' message to the socket (or actor), so it can be sent. This method is similar tosendPicture(String, Object...)
, except the arguments are encoded in a binary format that is compatible with zproto, and is designed to reduce memory allocations.- Parameters:
picture
- The picture argument is a string that defines the type of each argument. Supports these argument types:Type of arguments pattern java type zproto type 1 int type = "number" size = "1" 2 int type = "number" size = "2" 4 long type = "number" size = "3" 8 long type = "number" size = "4" s String, 0-255 chars type = "string" S String, 0-2^32-1 chars type = "longstr" c byte[], 0-2^32-1 bytes type = "chunk" f ZFrame type = "frame" m ZMsg type = "msg" args
- Arguments according to the picture- Returns:
- true when it has been queued on the socket and ØMQ has assumed responsibility for the message. This does not indicate that the message has been transmitted to the network.
- API Note
- Does not change or take ownership of any arguments.
-
recvMsg
Receives a message.- Returns:
- the message received; null on error.
-
recvMsg
Receives a message.- Parameters:
flags
- either:DONTWAIT
: Specifies that the operation should be performed in non-blocking mode. If there are no messages available on the specified socket, the method shall fail with errno set to EAGAIN and return null.- 0 : receive operation blocks until one message is successfully retrieved,
or stops when timeout set by
setReceiveTimeOut(int)
expires.
- Returns:
- the message received; null on error.
-
recv
public byte[] recv()Receives a message.- Returns:
- the message received, as an array of bytes; null on error.
-
recv
public byte[] recv(int flags) Receives a message.If possible, a reference to the data is returned, without copy. Otherwise a new byte array will be allocated and the data will be copied.
- Parameters:
flags
- either:DONTWAIT
: Specifies that the operation should be performed in non-blocking mode. If there are no messages available on the specified socket, the method shall fail with errno set to EAGAIN and return null.- 0 : receive operation blocks until one message is successfully retrieved,
or stops when timeout set by
setReceiveTimeOut(int)
expires.
- Returns:
- the message received, as an array of bytes; null on error.
-
recv
Receives a message, the call be canceled by calling cancellationTokenZMQ.CancellationToken.cancel()
. If the operation is canceled a ZMQException is thrown with error code set toZError.ECANCELED
.If possible, a reference to the data is returned, without copy. Otherwise a new byte array will be allocated and the data will be copied.
- Parameters:
flags
- either:DONTWAIT
: Specifies that the operation should be performed in non-blocking mode. If there are no messages available on the specified socket, the method shall fail with errno set to EAGAIN and return null.- 0 : receive operation blocks until one message is successfully retrieved,
or stops when timeout set by
setReceiveTimeOut(int)
expires.
cancellationToken
- token to control cancellation of the receive operation. The token can be created by callingcreateCancellationToken()
.- Returns:
- the message received, as an array of bytes; null on error.
-
recv
public int recv(byte[] buffer, int offset, int len, int flags) Receives a message in to a specified buffer.- Parameters:
buffer
- byte[] to copy zmq message payload in to.offset
- offset in buffer to write datalen
- max bytes to write to buffer. If len is smaller than the incoming message size, the message will be truncated.flags
- either:DONTWAIT
: Specifies that the operation should be performed in non-blocking mode. If there are no messages available on the specified socket, the method shall fail with errno set to EAGAIN and return null.- 0 : receive operation blocks until one message is successfully retrieved,
or stops when timeout set by
setReceiveTimeOut(int)
expires.
- Returns:
- the number of bytes read, -1 on error
-
recvByteBuffer
Receives a message into the specified ByteBuffer.- Parameters:
buffer
- the buffer to copy the zmq message payload intoflags
- either:DONTWAIT
: Specifies that the operation should be performed in non-blocking mode. If there are no messages available on the specified socket, the method shall fail with errno set to EAGAIN and return null.- 0 : receive operation blocks until one message is successfully retrieved,
or stops when timeout set by
setReceiveTimeOut(int)
expires.
- Returns:
- the number of bytes read, -1 on error
-
recvStr
- Returns:
- the message received, as a String object; null on no message.
-
recvStr
Receives a message as a string.- Parameters:
flags
- either:DONTWAIT
: Specifies that the operation should be performed in non-blocking mode. If there are no messages available on the specified socket, the method shall fail with errno set to EAGAIN and return null.- 0 : receive operation blocks until one message is successfully retrieved,
or stops when timeout set by
setReceiveTimeOut(int)
expires.
- Returns:
- the message received, as a String object; null on no message.
-
recvPicture
Receive a 'picture' message to the socket (or actor).- Parameters:
picture
- The picture is a string that defines the type of each frame. This makes it easy to recv a complex multiframe message in one call. The picture can contain any of these characters, each corresponding to zero or one elements in the result:Type of arguments i = int (stores signed integer) 1 = int (stores 8-bit unsigned integer) 2 = int (stores 16-bit unsigned integer) 4 = long (stores 32-bit unsigned integer) 8 = long (stores 64-bit unsigned integer) s = String b = byte[] f = ZFrame (creates zframe) m = ZMsg (creates a zmsg with the remaing frames) z = null, asserts empty frame (0 arguments) sendPicture(String, Object...)
how to send a multiframe picture.- Returns:
- the picture elements as object array
-
recvBinaryPicture
Receive a binary encoded 'picture' message from the socket (or actor). This method is similar torecv()
, except the arguments are encoded in a binary format that is compatible with zproto, and is designed to reduce memory allocations.- Parameters:
picture
- The picture argument is a string that defines the type of each argument. SeesendBinaryPicture(String, Object...)
for the supported argument types.- Returns:
- the picture elements as object array
-
monitor
Start a monitoring socket where events can be received.Lets an application thread track socket events (like connects) on a ZeroMQ socket. Each call to this method creates a
ZMQ.PAIR
socket and binds that to the specified inproc:// endpoint. To collect the socket events, you must create your own PAIR socket, and connect that to the endpoint.
Supports only connection-oriented transports, that is, TCP, IPC.- Parameters:
addr
- the endpoint to receive events from. (must be inproc transport)events
- the events of interest. A bitmask of the socket events you wish to monitor. To monitor all events, use the event valueZMQ.EVENT_ALL
.- Returns:
- true if monitor socket setup is successful
- Throws:
ZMQException
-
setEventHook
Register a custom event consumer.- Parameters:
consumer
- The event consumer.events
- the events of interest. A bitmask of the socket events you wish to monitor. To monitor all events, use the event valueZMQ.EVENT_ALL
.- Returns:
- true if consumer setup is successful
- Throws:
ZMQException
-
mayRaise
protected void mayRaise() -
errno
public int errno() -
toString
-
createCancellationToken
Create aZMQ.CancellationToken
to cancel send/receive operations for this socket.- Returns:
- a new cancellation token associated with this socket.
-
Socket(Context, SocketType)