Class ZSocket
- All Implemented Interfaces:
AutoCloseable
ZeroMQ 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 ZeroMQ itself. Further, messages may be queued in the event that a peer is unavailable to receive them.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionZSocket(int socketType) Create a ZeroMQ socketZSocket(SocketType socketType) Create a ZeroMQ socket -
Method Summary
Modifier and TypeMethodDescriptionbooleanCreates an endpoint for accepting connections and binds to it.voidclose()booleanConnects the socket to an endpoint and then accepts incoming connections on that endpoint.booleandisconnect(String endpoint) Disconnecting a socket from an endpoint.private ObjectgetOption(int option) Retrieve the socket type for the current 'socket'.intgetType()Retrieve the socket type for the current 'socket'.final booleanReturns a boolean value indicating if the multipart message currently being read from theSocketand has more message parts to follow.private voidmayRaise()byte[]receive()byte[]receive(int flags) receiveStringUtf8(int flags) intsend(byte[] b) intsend(byte[] b, int flags) booleanSend a framebooleansendMessage(ZMsg message) intsendStringUtf8(String str) intsendStringUtf8(String str, int flags) private voidvoidsubscribe(byte[] topic) voidbooleanStop accepting connections on a socket.voidunsubscribe(byte[] topic) voidunsubscribe(String topic)
-
Field Details
-
socketBase
-
isClosed
-
-
Constructor Details
-
ZSocket
public ZSocket(int socketType) Create a ZeroMQ socket- Parameters:
socketType- ZeroMQ socket type
-
ZSocket
Create a ZeroMQ socket- Parameters:
socketType- ZeroMQ Socket type
-
-
Method Details
-
getSocketType
Retrieve the socket type for the current 'socket'. The socket type is specified at socket creation time and cannot be modified afterwards.- Returns:
- the socket's type.
-
getType
public int getType()Retrieve the socket type for the current 'socket'. The socket type is specified at socket creation time and cannot be modified afterwards.- Returns:
- the socket's type.
- See Also:
-
bind
Creates an endpoint for accepting connections and binds to it.The endpoint argument is a string consisting of two parts as follows: transport ://address. The transport part specifies the underlying transport protocol to use. The meaning of the address part is specific to the underlying transport protocol selected.
- Parameters:
endpoint- the endpoint to bind to- Returns:
- returns true if bind to the endpoint was successful
-
unbind
Stop accepting connections on a socket.Shall unbind from the endpoint specified by the endpoint argument.
- Parameters:
endpoint- the endpoint to unbind from- Returns:
- returns true if unbind to the endpoint was successful
-
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.
- Parameters:
endpoint- the endpoint to connect to- Returns:
- returns true if connecting to the endpoint was successful
-
disconnect
Disconnecting a socket from an endpoint.- Parameters:
endpoint- the endpoint to disconnect from- Returns:
- returns true if disconnecting to endpoint was successful
-
hasReceiveMore
public final boolean hasReceiveMore()Returns a boolean value indicating if the multipart message currently being read from theSocketand has more message parts to follow. If there are no message parts to follow or if the message currently being read is not a multipart message a value of false shall be returned. Otherwise, a value of true shall be returned.- Returns:
- true if there are more messages to receive.
-
subscribe
public void subscribe(byte[] topic) -
subscribe
-
unsubscribe
public void unsubscribe(byte[] topic) -
unsubscribe
-
send
public int send(byte[] b) -
send
public int send(byte[] b, int flags) -
sendFrame
Send a frame- Parameters:
frame-flags-- Returns:
- return true if successful
-
sendMessage
-
sendStringUtf8
-
sendStringUtf8
-
receive
public byte[] receive() -
receive
public byte[] receive(int flags) -
receiveStringUtf8
-
receiveStringUtf8
-
mayRaise
private void mayRaise() -
setOption
-
getOption
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-