org.zeromq
类 ZMQ.Socket

java.lang.Object
  继承者 org.zeromq.ZMQ.Socket
所有已实现的接口:
java.io.Closeable
包容类:
ZMQ

public static class ZMQ.Socket
extends java.lang.Object
implements java.io.Closeable

Inner class: Socket.


构造方法摘要
protected ZMQ.Socket(ZMQ.Context context, int type)
          Class constructor.
 
方法摘要
 void bind(java.lang.String addr)
          Bind to network interface.
 int bindToRandomPort(java.lang.String addr)
          Bind to network interface to a random port.
 int bindToRandomPort(java.lang.String addr, int min_port)
          Bind to network interface to a random port.
 int bindToRandomPort(java.lang.String addr, int min_port, int max_port)
          Bind to network interface to a random port.
 int bindToRandomPort(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.nio.ByteBuffer buffer, int flags)
          Receive a message
 java.lang.String recvStr()
          已过时。 use recvStr(Charset) instead.
 java.lang.String recvStr(java.nio.charset.Charset charset)
          Receive a message as a String with a given Charset.
 java.lang.String recvStr(int flags)
          已过时。 use recvStr(int, Charset) instead.
 java.lang.String recvStr(int flags, java.nio.charset.Charset charset)
          Receive a message as a String.
 int recvZeroCopy(java.nio.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(java.lang.String msg)
          Send a String.
 boolean send(java.lang.String msg, int flags)
          Send a String.
 int sendByteBuffer(java.nio.ByteBuffer bb, int flags)
          Send a message
 boolean sendMore(java.lang.String msg)
          Send a String.
 boolean sendZeroCopy(java.nio.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(java.lang.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.
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

ZMQ.Socket

protected ZMQ.Socket(ZMQ.Context context,
                     int type)
Class constructor.

参数:
context - a 0MQ context previously created.
type - the socket type.
方法详细信息

close

public void close()
This is an explicit "destructor". It can be called to ensure the corresponding 0MQ Socket has been disposed of.

指定者:
接口 java.io.Closeable 中的 close

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.

返回:
the socket type.
从以下版本开始:
2.1.0

getLinger

public long getLinger()
返回:
the linger period.
从以下版本开始:
2.1.0
另请参见:
setLinger(long)

getReconnectIVL

public long getReconnectIVL()
返回:
the reconnectIVL.
从以下版本开始:
3.0.0
另请参见:
setReconnectIVL(long)

getBacklog

public long getBacklog()
返回:
the backlog.
从以下版本开始:
3.0.0
另请参见:
setBacklog(long)

getReconnectIVLMax

public long getReconnectIVLMax()
返回:
the reconnectIVLMax.
从以下版本开始:
3.0.0
另请参见:
setReconnectIVLMax(long)

getMaxMsgSize

public long getMaxMsgSize()
返回:
the maxMsgSize.
从以下版本开始:
3.0.0
另请参见:
setMaxMsgSize(long)

getSndHWM

public long getSndHWM()
返回:
the SndHWM.
从以下版本开始:
3.0.0
另请参见:
setSndHWM(long)

getRcvHWM

public long getRcvHWM()
返回:
the recvHWM period.
从以下版本开始:
3.0.0
另请参见:
setRcvHWM(long)

getHWM

public long getHWM()
返回:
the High Water Mark.
另请参见:
setHWM(long)

getSwap

public long getSwap()
返回:
the number of messages to swap at most.
另请参见:
setSwap(long)

getAffinity

public long getAffinity()
返回:
the affinity.
另请参见:
setAffinity(long)

getTCPKeepAliveSetting

public long getTCPKeepAliveSetting()
返回:
the keep alive setting.
另请参见:
setTCPKeepAlive(long)

getTCPKeepAliveIdle

public long getTCPKeepAliveIdle()
返回:
the keep alive idle value.
另请参见:
setTCPKeepAliveIdle(long)

getTCPKeepAliveInterval

public long getTCPKeepAliveInterval()
返回:
the keep alive interval.
另请参见:
setTCPKeepAliveInterval(long)

getTCPKeepAliveCount

public long getTCPKeepAliveCount()
返回:
the keep alive count.
另请参见:
setTCPKeepAliveCount(long)

getIdentity

public byte[] getIdentity()
返回:
the Identitiy.
另请参见:
setIdentity(byte[])

getRate

public long getRate()
返回:
the Rate.
另请参见:
setRate(long)

getRecoveryInterval

public long getRecoveryInterval()
返回:
the RecoveryIntervall.
另请参见:
setRecoveryInterval(long)

hasMulticastLoop

public boolean hasMulticastLoop()
返回:
the Multicast Loop.
另请参见:
setMulticastLoop(boolean)

setMulticastHops

public void setMulticastHops(long mcast_hops)
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.

参数:
mcast_hops -

getMulticastHops

public long getMulticastHops()
返回:
the Multicast Hops.
另请参见:
setMulticastHops(long)

setReceiveTimeOut

public void setReceiveTimeOut(int timeout)
Sets the timeout for receive operation on the socket. If the value is 0, recv will return immediately, with a EAGAIN error 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 an EAGAIN error.

参数:
timeout - Timeout for receive operation in milliseconds. Default -1 (infinite)

getReceiveTimeOut

public int getReceiveTimeOut()
返回:
the Receive Timeout in milliseconds
另请参见:
setReceiveTimeOut(int)

setSendTimeOut

public void setSendTimeOut(int timeout)
Sets the timeout for send operation on the socket. If the value is 0, send will return immediately, with a 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 an EAGAIN error.

参数:
timeout - Timeout for send operation in milliseconds. Default -1 (infinite)

getSendTimeOut

public int getSendTimeOut()
返回:
the Send Timeout. in milliseconds
另请参见:
setSendTimeOut(int)

getSendBufferSize

public long getSendBufferSize()
返回:
the kernel send buffer size.
另请参见:
setSendBufferSize(long)

getReceiveBufferSize

public long getReceiveBufferSize()
返回:
the kernel receive buffer size.
另请参见:
setReceiveBufferSize(long)

getIPv4Only

public boolean getIPv4Only()
返回:
the IPv4 only socket.
另请参见:
setIPv4Only(boolean)

getPlainServer

public boolean getPlainServer()
返回:
if the socket is setup for PLAIN security
另请参见:
setPlainServer(boolean)

getPlainUsername

public byte[] getPlainUsername()
返回:
null terminated byte array in server charset
另请参见:
setPlainUsername(byte[])

getPlainPassword

public byte[] getPlainPassword()
返回:
null terminated byte array in server charset
另请参见:
setPlainPassword(byte[])

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.

返回:
true if there are more messages to receive.

getFD

public long 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.

返回:
the underlying file descriptor.
从以下版本开始:
2.1.0

getEvents

public long 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.

返回:
the mask of outstanding events.
从以下版本开始:
2.1.0

setLinger

public void setLinger(long linger)
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.

参数:
linger - the linger period.
从以下版本开始:
2.1.0

setReconnectIVL

public void setReconnectIVL(long reconnectIVL)
从以下版本开始:
3.0.0

setBacklog

public void setBacklog(long backlog)
从以下版本开始:
3.0.0

setReconnectIVLMax

public void setReconnectIVLMax(long reconnectIVLMax)
从以下版本开始:
3.0.0

setMaxMsgSize

public void setMaxMsgSize(long maxMsgSize)
从以下版本开始:
3.0.0

setSndHWM

public void setSndHWM(long sndHWM)
从以下版本开始:
3.0.0

setRcvHWM

public void setRcvHWM(long rcvHWM)
从以下版本开始:
3.0.0

setHWM

public void setHWM(long 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.

参数:
hwm - the number of messages to queue.

setSwap

public void setSwap(long swap)
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.

参数:
swap - The value of 'ZMQ_SWAP' defines the maximum size of the swap space in bytes.

setAffinity

public void setAffinity(long affinity)
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 zmq_init[3] for details on allocating the number of I/O threads for a specific _context_.

参数:
affinity - the affinity.

setTCPKeepAlive

public void setTCPKeepAlive(long 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.

参数:
optVal - The value of 'ZMQ_TCP_KEEPALIVE' to turn TCP keepalives on (1) or off (0).

setTCPKeepAliveCount

public void setTCPKeepAliveCount(long optVal)
Override TCP_KEEPCNT socket option (where supported by OS). The default value -1 will skip all overrides and do the OS default.

参数:
optVal - The value of 'ZMQ_TCP_KEEPALIVE_CNT' defines the number of keepalives before death.

setTCPKeepAliveInterval

public void setTCPKeepAliveInterval(long optVal)
Override TCP_KEEPINTVL socket option (where supported by OS). The default value -1 will skip all overrides and do the OS default.

参数:
optVal - The value of 'ZMQ_TCP_KEEPALIVE_INTVL' defines the interval between keepalives. Unit is OS dependant.

setTCPKeepAliveIdle

public void setTCPKeepAliveIdle(long optVal)
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.

参数:
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.

setIdentity

public void 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.

参数:
identity -

subscribe

public void 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.

参数:
topic -

unsubscribe

public void 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.

参数:
topic -

setRate

public 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'.

参数:
rate -

setRecoveryInterval

public void setRecoveryInterval(long recovery_ivl)
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 (before version 3.0.0) or milliseconds (version 3.0.0 and after) 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}

参数:
recovery_ivl -

setMulticastLoop

public 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. 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.

参数:
mcast_loop -

setSendBufferSize

public 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. 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.

参数:
sndbuf -

setReceiveBufferSize

public 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. A value of zero means leave the OS default unchanged. For details refer to your operating system documentation for the 'SO_RCVBUF' socket option.

参数:
rcvbuf -

setIPv4Only

public void setIPv4Only(boolean v4only)
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.

参数:
v4only - A value of true will use IPv4 sockets, while the value of false will use IPv6 sockets

setRouterMandatory

public void setRouterMandatory(boolean mandatory)
Sets the ROUTER socket behavior when an unroutable message is encountered.

参数:
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.

setXpubVerbose

public void setXpubVerbose(boolean verbose)
Sets the XPUB socket behavior on new subscriptions and unsubscriptions.

参数:
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.
从以下版本开始:
3.2.2

setPlainServer

public void setPlainServer(boolean plain)
Sets if the socket is for a server using the PLAIN security mechanism.

参数:
plain - whether or not to use PLAIN security
从以下版本开始:
4.0.0
另请参见:
PLAIN RFC

setPlainUsername

public void setPlainUsername(byte[] username)
Sets the username used for the PLAIN security mechanism.

参数:
username - null terminated string in server charset
从以下版本开始:
4.0.0
另请参见:
PLAIN RFC

setPlainPassword

public void setPlainPassword(byte[] password)
Sets the password used for the PLAIN security mechanism.

参数:
password - null terminated string in server charset
从以下版本开始:
4.0.0
另请参见:
PLAIN RFC

setZAPDomain

public void setZAPDomain(byte[] domain)
Sets the domain for ZAP (ZMQ RFC 27) authentication.

参数:
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.

setGSSAPIServer

public void setGSSAPIServer(boolean isServer)

setGSSAPIPrincipal

public void setGSSAPIPrincipal(byte[] principal)

setGSSAPIServicePrincipal

public void setGSSAPIServicePrincipal(byte[] principal)

setGSSAPIPlainText

public void setGSSAPIPlainText(boolean isPlaintext)

setConflate

public void setConflate(boolean conflate)
Sets whether socket should keep only last received/to be sent message in its inbound/outbound queue.

参数:
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.
从以下版本开始:
4.0.0

getConflate

public boolean getConflate()
Indicate whether socket should keep only last received/to be sent message in its inbound/outbound queue.

返回:
true if should keep only last received/to be sent message in its inbound/outbound queue.
从以下版本开始:
4.0.0

getImmediate

public boolean getImmediate()
Indicate whether socket should only queue messages to completed connections.

返回:
true if should only queue messages to completed connections.
从以下版本开始:
3.2.0

setImmediate

public void setImmediate(boolean immediate)
Sets whether socket should only queue messages to completed connections.

参数:
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.
从以下版本开始:
3.2.0

setReqRelaxed

public void setReqRelaxed(boolean isRelaxed)

setReqCorrelate

public void setReqCorrelate(boolean isCorrelate)

setProbeRouter

public void setProbeRouter(boolean isProbeRouter)
Sets whether the socket should automatically send an empty message when a new connection is made or accepted. This may be set on REQ, DEALER, or ROUTER sockets connected to a ROUTER socket. The application must filter such empty messages.

参数:
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 sent
从以下版本开始:
4.0.0

bind

public void bind(java.lang.String addr)
Bind to network interface. Start listening for new connections.

参数:
addr - the endpoint to bind to.

bindToRandomPort

public int bindToRandomPort(java.lang.String addr)
Bind to network interface to a random port. Start listening for new connections.

参数:
addr - the endpoint to bind to.

bindToRandomPort

public int bindToRandomPort(java.lang.String addr,
                            int min_port)
Bind to network interface to a random port. Start listening for new connections.

参数:
addr - the endpoint to bind to.
min_port - The minimum port in the range of ports to try.

bindToRandomPort

public int bindToRandomPort(java.lang.String addr,
                            int min_port,
                            int max_port)
Bind to network interface to a random port. Start listening for new connections.

参数:
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.

bindToRandomPort

public int bindToRandomPort(java.lang.String addr,
                            int min_port,
                            int max_port,
                            int max_tries)
Bind to network interface to a random port. Start listening for new connections.

参数:
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.

unbind

public void unbind(java.lang.String addr)
Unbind from network interface. Stop listening for connections.

参数:
addr - the endpoint to unbind from.

connect

public void connect(java.lang.String addr)
Connect to remote application.

参数:
addr - the endpoint to connect to.

disconnect

public void disconnect(java.lang.String addr)
Disconnect from a remote application.

参数:
addr - the endpoint to disconnect from.

monitor

public boolean monitor(java.lang.String addr,
                       int events)
                throws ZMQException
Start a monitoring socket where events can be received.

参数:
addr - the endpoint to receive events from. (must be inproc transport)
events - the events of interest.
返回:
true if monitor socket setup is successful
抛出:
ZMQException

send

public boolean send(byte[] msg,
                    int offset,
                    int flags)
Send a message.

参数:
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.
返回:
true if send was successful, false otherwise.

send

public boolean send(byte[] msg,
                    int offset,
                    int len,
                    int flags)
参数:
msg -
offset -
len -
flags -
返回:

sendZeroCopy

public boolean sendZeroCopy(java.nio.ByteBuffer buffer,
                            int len,
                            int flags)
Perform a zero copy send. The buffer must be allocated using ByteBuffer.allocateDirect

参数:
buffer -
len -
flags -
返回:

send

public boolean send(byte[] msg,
                    int flags)
Send a message.

参数:
msg - the message to send, as an array of bytes.
flags - the flags to apply to the send operation.
返回:
true if send was successful, false otherwise.

send

public boolean send(java.lang.String msg)
Send a String.

参数:
msg - the message to send, as a String.
返回:
true if send was successful, false otherwise.

sendMore

public boolean sendMore(java.lang.String msg)
Send a String.

参数:
msg - the message to send, as a String.
返回:
true if send was successful, false otherwise.

send

public boolean send(java.lang.String msg,
                    int flags)
Send a String.

参数:
msg - the message to send, as a String.
flags - the flags to apply to the send operation.
返回:
true if send was successful, false otherwise.

sendByteBuffer

public int sendByteBuffer(java.nio.ByteBuffer bb,
                          int flags)
Send a message

参数:
bb - ByteBuffer payload
flags - the flags to apply to the send operation
返回:
the number of bytes sent

recv

public byte[] recv(int flags)
Receive a message.

参数:
flags - the flags to apply to the receive operation.
返回:
the message received, as an array of bytes; null on error.

recv

public int recv(byte[] buffer,
                int offset,
                int len,
                int flags)
Receive a message in to a specified buffer.

参数:
buffer - byte[] to copy zmq message payload in to.
offset - offset in buffer to write data
len - 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.
返回:
the number of bytes read, -1 on error

recvZeroCopy

public int recvZeroCopy(java.nio.ByteBuffer buffer,
                        int len,
                        int flags)
Zero copy recv

参数:
buffer -
len -
flags -
返回:
bytes read, -1 on error

recv

public byte[] recv()
Receive a message.

返回:
the message received, as an array of bytes; null on error.

recvStr

@Deprecated
public java.lang.String recvStr()
已过时。 use recvStr(Charset) instead.

Receive a message as a String with the default Charset.

返回:
the message received, as a String; null on error.

recvStr

public java.lang.String recvStr(java.nio.charset.Charset charset)
Receive a message as a String with a given Charset.

参数:
charset - the charset of the resulting string.
返回:
the message received, as a String; null on error.

recvStr

@Deprecated
public java.lang.String recvStr(int flags)
已过时。 use recvStr(int, Charset) instead.

Receive a message as a String with the default charset.

参数:
flags - the flags to apply to the receive operation.
返回:
the message received, as a String; null on error.

recvStr

public java.lang.String recvStr(int flags,
                                java.nio.charset.Charset charset)
Receive a message as a String.

参数:
flags - the flags to apply to the receive operation.
charset - the charset of the resulting string.
返回:
the message received, as a String; null on error.

recvByteBuffer

public int recvByteBuffer(java.nio.ByteBuffer buffer,
                          int flags)
Receive a message

参数:
buffer -
flags -
返回:
bytes read, -1 on error

construct

protected void construct(ZMQ.Context ctx,
                         int type)
Initialize the JNI interface


destroy

protected void destroy()
Free all resources used by JNI interface.


getLongSockopt

protected long getLongSockopt(int option)
Get the socket option value, as a long.

参数:
option - ID of the option to set.
返回:
The socket option value (as a long).

getBytesSockopt

protected byte[] getBytesSockopt(int option)
Get the socket option value, as a byte array.

参数:
option - ID of the option to set.
返回:
The socket option value (as a byte array).

setLongSockopt

protected void setLongSockopt(int option,
                              long optval)
Set the socket option value, given as a long.

参数:
option - ID of the option to set.
optval - value (as a long) to set the option to.

setBytesSockopt

protected void setBytesSockopt(int option,
                               byte[] optval)
Set the socket option value, given as a byte array.

参数:
option - ID of the option to set.
optval - value (as a byte array) to set the option to.