public static class ZMQ.Socket extends Object implements Closeable
Modifier | Constructor and Description |
---|---|
protected |
Socket(ZMQ.Context context,
int type)
Class constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
bind(String addr)
Bind to network interface.
|
int |
bindToRandomPort(String addr)
Bind to network interface to a random port.
|
int |
bindToRandomPort(String addr,
int min_port)
Bind to network interface to a random port.
|
int |
bindToRandomPort(String addr,
int min_port,
int max_port)
Bind to network interface to a random port.
|
int |
bindToRandomPort(String addr,
int min_port,
int max_port,
int max_tries)
Bind to network interface to a random port.
|
void |
close()
This is an explicit "destructor".
|
void |
connect(String addr)
Connect to remote application.
|
protected void |
construct(ZMQ.Context ctx,
int type)
Initialize the JNI interface
|
protected void |
destroy()
Free all resources used by JNI interface.
|
void |
disconnect(String addr)
Disconnect from a remote application.
|
long |
getAffinity() |
long |
getBacklog() |
protected byte[] |
getBytesSockopt(int option)
Get the socket option value, as a byte array.
|
boolean |
getConflate()
Indicate whether socket should keep only last received/to be sent message in its inbound/outbound queue.
|
long |
getEvents()
The 'ZMQ_EVENTS' option shall retrieve event flags for the specified socket.
|
long |
getFD()
The 'ZMQ_FD' option shall retrieve file descriptor associated with the 0MQ socket.
|
long |
getHWM() |
byte[] |
getIdentity() |
boolean |
getImmediate()
Indicate whether socket should only queue messages to completed connections.
|
boolean |
getIPv4Only() |
long |
getLinger() |
protected long |
getLongSockopt(int option)
Get the socket option value, as a long.
|
long |
getMaxMsgSize() |
long |
getMulticastHops() |
byte[] |
getPlainPassword() |
boolean |
getPlainServer() |
byte[] |
getPlainUsername() |
long |
getRate() |
long |
getRcvHWM() |
long |
getReceiveBufferSize() |
int |
getReceiveTimeOut() |
long |
getReconnectIVL() |
long |
getReconnectIVLMax() |
long |
getRecoveryInterval() |
long |
getSendBufferSize() |
int |
getSendTimeOut() |
long |
getSndHWM() |
long |
getSwap() |
long |
getTCPKeepAliveCount() |
long |
getTCPKeepAliveIdle() |
long |
getTCPKeepAliveInterval() |
long |
getTCPKeepAliveSetting() |
int |
getType()
The 'ZMQ_TYPE option shall retrieve the socket type for the specified 'socket'.
|
boolean |
hasMulticastLoop() |
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.
|
boolean |
monitor(String addr,
int events)
Start a monitoring socket where events can be received.
|
byte[] |
recv()
Receive a message.
|
int |
recv(byte[] buffer,
int offset,
int len,
int flags)
Receive a message in to a specified buffer.
|
byte[] |
recv(int flags)
Receive a message.
|
int |
recvByteBuffer(ByteBuffer buffer,
int flags)
Receive a message
|
String |
recvStr()
Deprecated.
use
recvStr(Charset) instead. |
String |
recvStr(Charset charset)
Receive a message as a String with a given Charset.
|
String |
recvStr(int flags)
Deprecated.
use
recvStr(int, Charset) instead. |
String |
recvStr(int flags,
Charset charset)
Receive a message as a String.
|
int |
recvZeroCopy(ByteBuffer buffer,
int len,
int flags)
Zero copy recv
|
boolean |
send(byte[] msg,
int flags)
Send a message.
|
boolean |
send(byte[] msg,
int offset,
int flags)
Send a message.
|
boolean |
send(byte[] msg,
int offset,
int len,
int flags) |
boolean |
send(String msg)
Send a String.
|
boolean |
send(String msg,
int flags)
Send a String.
|
int |
sendByteBuffer(ByteBuffer bb,
int flags)
Send a message
|
boolean |
sendMore(String msg)
Send a String.
|
boolean |
sendZeroCopy(ByteBuffer buffer,
int len,
int flags)
Perform a zero copy send.
|
void |
setAffinity(long affinity)
Get the Affinity.
|
void |
setBacklog(long backlog) |
protected void |
setBytesSockopt(int option,
byte[] optval)
Set the socket option value, given as a byte array.
|
void |
setConflate(boolean conflate)
Sets whether socket should keep only last received/to be sent message in its inbound/outbound queue.
|
void |
setGSSAPIPlainText(boolean isPlaintext) |
void |
setGSSAPIPrincipal(byte[] principal) |
void |
setGSSAPIServer(boolean isServer) |
void |
setGSSAPIServicePrincipal(byte[] principal) |
void |
setHWM(long hwm)
The 'ZMQ_HWM' option shall set the high water mark for the specified 'socket'.
|
void |
setIdentity(byte[] identity)
The 'ZMQ_IDENTITY' option shall set the identity of the specified 'socket'.
|
void |
setImmediate(boolean immediate)
Sets whether socket should only queue messages to completed connections.
|
void |
setIPv4Only(boolean v4only)
The 'ZMQ_IPV4ONLY' option shall set the underlying native socket type.
|
void |
setLinger(long linger)
The 'ZMQ_LINGER' option shall retrieve the period for pending outbound messages to linger in memory after
closing the socket.
|
protected void |
setLongSockopt(int option,
long optval)
Set the socket option value, given as a long.
|
void |
setMaxMsgSize(long maxMsgSize) |
void |
setMulticastHops(long mcast_hops)
Sets the time-to-live field in every multicast packet sent from this socket.
|
void |
setMulticastLoop(boolean mcast_loop)
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.
|
void |
setPlainPassword(byte[] password)
Sets the password used for the PLAIN security mechanism.
|
void |
setPlainServer(boolean plain)
Sets if the socket is for a server using the PLAIN security mechanism.
|
void |
setPlainUsername(byte[] username)
Sets the username used for the PLAIN security mechanism.
|
void |
setProbeRouter(boolean isProbeRouter)
Sets whether the socket should automatically send an empty message
when a new connection is made or accepted.
|
void |
setRate(long rate)
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'.
|
void |
setRcvHWM(long rcvHWM) |
void |
setReceiveBufferSize(long rcvbuf)
The 'ZMQ_RCVBUF' option shall set the underlying kernel receive buffer size for the 'socket' to the specified
size in bytes.
|
void |
setReceiveTimeOut(int timeout)
Sets the timeout for receive operation on the socket.
|
void |
setReconnectIVL(long reconnectIVL) |
void |
setReconnectIVLMax(long reconnectIVLMax) |
void |
setRecoveryInterval(long recovery_ivl)
The 'ZMQ_RECOVERY_IVL' option shall set the recovery interval for multicast transports using the specified
'socket'.
|
void |
setReqCorrelate(boolean isCorrelate) |
void |
setReqRelaxed(boolean isRelaxed) |
void |
setRouterMandatory(boolean mandatory)
Sets the ROUTER socket behavior when an unroutable message is encountered.
|
void |
setSendBufferSize(long sndbuf)
The 'ZMQ_SNDBUF' option shall set the underlying kernel transmit buffer size for the 'socket' to the
specified size in bytes.
|
void |
setSendTimeOut(int timeout)
Sets the timeout for send operation on the socket.
|
void |
setSndHWM(long sndHWM) |
void |
setSwap(long swap)
Get the Swap.
|
void |
setTCPKeepAlive(long optVal)
Override SO_KEEPALIVE socket option (where supported by OS) to enable keep-alive packets for a socket
connection.
|
void |
setTCPKeepAliveCount(long optVal)
Override TCP_KEEPCNT socket option (where supported by OS).
|
void |
setTCPKeepAliveIdle(long optVal)
Override TCP_KEEPCNT (or TCP_KEEPALIVE on some OS) socket option (where supported by OS).
|
void |
setTCPKeepAliveInterval(long optVal)
Override TCP_KEEPINTVL socket option (where supported by OS).
|
void |
setXpubVerbose(boolean verbose)
Sets the XPUB socket behavior on new subscriptions and unsubscriptions.
|
void |
setZAPDomain(byte[] domain)
Sets the domain for ZAP (ZMQ RFC 27) authentication.
|
void |
subscribe(byte[] topic)
The 'ZMQ_SUBSCRIBE' option shall establish a new message filter on a 'ZMQ_SUB' socket.
|
void |
unbind(String addr)
Unbind from network interface.
|
void |
unsubscribe(byte[] topic)
The 'ZMQ_UNSUBSCRIBE' option shall remove an existing message filter on a 'ZMQ_SUB' socket.
|
protected Socket(ZMQ.Context context, int type)
context
- a 0MQ context previously created.type
- the socket type.public void close()
close
in interface Closeable
close
in interface AutoCloseable
public int getType()
public long getLinger()
setLinger(long)
public long getReconnectIVL()
setReconnectIVL(long)
public long getBacklog()
setBacklog(long)
public long getReconnectIVLMax()
setReconnectIVLMax(long)
public long getMaxMsgSize()
setMaxMsgSize(long)
public long getSndHWM()
setSndHWM(long)
public long getRcvHWM()
setRcvHWM(long)
public long getHWM()
setHWM(long)
public long getSwap()
setSwap(long)
public long getAffinity()
setAffinity(long)
public long getTCPKeepAliveSetting()
setTCPKeepAlive(long)
public long getTCPKeepAliveIdle()
setTCPKeepAliveIdle(long)
public long getTCPKeepAliveInterval()
setTCPKeepAliveInterval(long)
public long getTCPKeepAliveCount()
setTCPKeepAliveCount(long)
public byte[] getIdentity()
setIdentity(byte[])
public long getRate()
setRate(long)
public long getRecoveryInterval()
setRecoveryInterval(long)
public boolean hasMulticastLoop()
setMulticastLoop(boolean)
public void setMulticastHops(long mcast_hops)
mcast_hops
- public long getMulticastHops()
setMulticastHops(long)
public void setReceiveTimeOut(int timeout)
timeout
- Timeout for receive operation in milliseconds. Default -1 (infinite)public int getReceiveTimeOut()
setReceiveTimeOut(int)
public void setSendTimeOut(int timeout)
timeout
- Timeout for send operation in milliseconds. Default -1 (infinite)public int getSendTimeOut()
setSendTimeOut(int)
public long getSendBufferSize()
setSendBufferSize(long)
public long getReceiveBufferSize()
setReceiveBufferSize(long)
public boolean getIPv4Only()
setIPv4Only(boolean)
public boolean getPlainServer()
setPlainServer(boolean)
public byte[] getPlainUsername()
setPlainUsername(byte[])
public byte[] getPlainPassword()
setPlainPassword(byte[])
public boolean hasReceiveMore()
public long getFD()
public long getEvents()
public void setLinger(long linger)
linger
- the linger period.public void setReconnectIVL(long reconnectIVL)
public void setBacklog(long backlog)
public void setReconnectIVLMax(long reconnectIVLMax)
public void setMaxMsgSize(long maxMsgSize)
public void setSndHWM(long sndHWM)
public void setRcvHWM(long rcvHWM)
public void setHWM(long hwm)
hwm
- the number of messages to queue.public void setSwap(long swap)
swap
- The value of 'ZMQ_SWAP' defines the maximum size of the swap space in bytes.public void setAffinity(long affinity)
affinity
- the affinity.public void setTCPKeepAlive(long optVal)
optVal
- The value of 'ZMQ_TCP_KEEPALIVE' to turn TCP keepalives on (1) or off (0).public void setTCPKeepAliveCount(long optVal)
optVal
- The value of 'ZMQ_TCP_KEEPALIVE_CNT' defines the number of keepalives before death.public void setTCPKeepAliveInterval(long optVal)
optVal
- The value of 'ZMQ_TCP_KEEPALIVE_INTVL' defines the interval between keepalives. Unit is OS
dependant.public void setTCPKeepAliveIdle(long optVal)
optVal
- 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 dependant.public void setIdentity(byte[] identity)
identity
- public void subscribe(byte[] topic)
topic
- public void unsubscribe(byte[] topic)
topic
- public void setRate(long rate)
rate
- public void setRecoveryInterval(long recovery_ivl)
recovery_ivl
- public void setMulticastLoop(boolean mcast_loop)
mcast_loop
- public void setSendBufferSize(long sndbuf)
sndbuf
- public void setReceiveBufferSize(long rcvbuf)
rcvbuf
- public void setIPv4Only(boolean v4only)
v4only
- A value of true will use IPv4 sockets, while the value of false will use IPv6 socketspublic void setRouterMandatory(boolean mandatory)
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.public void setXpubVerbose(boolean verbose)
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.public void setPlainServer(boolean plain)
plain
- whether or not to use PLAIN securitypublic void setPlainUsername(byte[] username)
username
- null terminated string in server charsetpublic void setPlainPassword(byte[] password)
password
- null terminated string in server charsetpublic void setZAPDomain(byte[] domain)
domain
- 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.public void setGSSAPIServer(boolean isServer)
public void setGSSAPIPrincipal(byte[] principal)
public void setGSSAPIServicePrincipal(byte[] principal)
public void setGSSAPIPlainText(boolean isPlaintext)
public void setConflate(boolean conflate)
conflate
- A value of false is the default which means socket preserves all messages with respect
to the RECVHWM and SENDHWM options. A value of true means only last message is kept ignoring
the RECVHWM and SENDHWM options.public boolean getConflate()
public boolean getImmediate()
public void setImmediate(boolean immediate)
immediate
- A value of false is the default which means socket will not queue messages to
to incomplete connections. This will cause the socket to block if there are no other connections,
but will prevent queues from filling on pipes awaiting connection.public void setReqRelaxed(boolean isRelaxed)
public void setReqCorrelate(boolean isCorrelate)
public void setProbeRouter(boolean isProbeRouter)
isProbeRouter
- if true
, the socket will automatically
send an empty message when a new connection is made or
accepted; if false
, no such message will be sentpublic void bind(String addr)
addr
- the endpoint to bind to.public int bindToRandomPort(String addr)
addr
- the endpoint to bind to.public int bindToRandomPort(String addr, int min_port)
addr
- the endpoint to bind to.min_port
- The minimum port in the range of ports to try.public int bindToRandomPort(String addr, int min_port, int max_port)
addr
- the endpoint to bind to.min_port
- The minimum port in the range of ports to try.max_port
- The maximum port in the range of ports to try.public int bindToRandomPort(String addr, int min_port, int max_port, int max_tries)
addr
- the endpoint to bind to.min_port
- The minimum port in the range of ports to try.max_port
- The maximum port in the range of ports to try.max_tries
- The number of attempt to bind.public void unbind(String addr)
addr
- the endpoint to unbind from.public void connect(String addr)
addr
- the endpoint to connect to.public void disconnect(String addr)
addr
- the endpoint to disconnect from.public boolean monitor(String addr, int events) throws ZMQException
addr
- the endpoint to receive events from. (must be inproc transport)events
- the events of interest.ZMQException
public boolean send(byte[] msg, int offset, int flags)
msg
- the message to send, as an array of bytes.offset
- the offset of the message to send.flags
- the flags to apply to the send operation.public boolean send(byte[] msg, int offset, int len, int flags)
msg
- offset
- len
- flags
- public boolean sendZeroCopy(ByteBuffer buffer, int len, int flags)
buffer
- len
- flags
- public boolean send(byte[] msg, int flags)
msg
- the message to send, as an array of bytes.flags
- the flags to apply to the send operation.public boolean send(String msg)
msg
- the message to send, as a String.public boolean sendMore(String msg)
msg
- the message to send, as a String.public boolean send(String msg, int flags)
msg
- the message to send, as a String.flags
- the flags to apply to the send operation.public int sendByteBuffer(ByteBuffer bb, int flags)
bb
- ByteBuffer payloadflags
- the flags to apply to the send operationpublic byte[] recv(int flags)
flags
- the flags to apply to the receive operation.public int recv(byte[] buffer, int offset, int len, int flags)
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
- the flags to apply to the receive operation.public int recvZeroCopy(ByteBuffer buffer, int len, int flags)
buffer
- len
- flags
- public final byte[] recv()
@Deprecated public String recvStr()
recvStr(Charset)
instead.public String recvStr(Charset charset)
charset
- the charset of the resulting string.@Deprecated public String recvStr(int flags)
recvStr(int, Charset)
instead.flags
- the flags to apply to the receive operation.public String recvStr(int flags, Charset charset)
flags
- the flags to apply to the receive operation.charset
- the charset of the resulting string.public int recvByteBuffer(ByteBuffer buffer, int flags)
buffer
- flags
- protected void construct(ZMQ.Context ctx, int type)
protected void destroy()
protected long getLongSockopt(int option)
option
- ID of the option to set.protected byte[] getBytesSockopt(int option)
option
- ID of the option to set.protected void setLongSockopt(int option, long optval)
option
- ID of the option to set.optval
- value (as a long) to set the option to.protected void setBytesSockopt(int option, byte[] optval)
option
- ID of the option to set.optval
- value (as a byte array) to set the option to.