ZMQ::Socket - ZMQ Socket object
use ZMQ; use ZMQ::Constants qw(ZMQ_PUSH); my $cxt = ZMQ::Context->new(); my $sock = $cxt->socket( ZMQ_PUSH ); # zmq 2.1.x $sock->send( $msg ); my $msg = $sock->recv(); # zmq 3.1.x $sock->send( $data, $len, $flags ); $sock->recv( $msg, $len, $flags ); $sock->sendmsg( $msg ); my $msg = $sock->recvmsg();
A ZMQ::Socket object represents a 0MQ socket.
ZMQ::Socket object can only be created via ZMQ::Context objects, so there are no public constructors.
The types of sockets that you can create, and the semantics of the socket object varies greatly on the underlying version of libzmq, so please read the documents for libzmq for details.
The bind($endpoint) method function creates an endpoint for accepting connections and binds it to the socket.
bind($endpoint)
Local in-process (inter-thread) communication transport.
Local inter-process communication transport.
Unicast transport using TCP.
Reliable multicast transport using PGM.
Connect to an existing endpoint. Takes an enpoint string as argument, see the documentation for bind($endpoint) above.
If an error occurs ( zmq_connect() returns a non-zero status ), then an exception is throw.
zmq_connect()
Closes and terminates the socket.
The semantics of this function varies greatly depending on the underlying version of libzmq.
For ZMQ::LibZMQ2:
$sock->send( $msg [, $flags] ); $sock->send( $raw_string [, $flags] );
For ZMQ::LibZMQ3:
$sock->send( $msg, $len [, $flags] );
The sendmsg($msg, $flags) method queues the given message to be sent to the socket. The flags argument is a combination of the flags defined below.
sendmsg($msg, $flags)
sendmsg is only available if you are using ZMQ::LibZMQ3 as the underlying library.
sendmsg
ZMQ::LibZMQ3
$msg = $sock->recv();
$sock->recv( $msg, $len [, $flags] );
The my $msg = $sock->recvmsg($flags) method receives a message from the socket and returns it as a new ZMQ::Message object. If there are no messages available on the specified socket the recvmsg() method blocks until the request can be satisfied. The flags argument is a combination of the flags defined below.
my $msg = $sock->recvmsg($flags)
ZMQ::Message
recvmsg()
recvmsg is only available if you are using ZMQ::LibZMQ3 as the underlying library.
recvmsg
The send_multipart(\@frames, $flags) method sends a multipart message to the socket. The method will send the frames with the ZMQ_SNDMORE flag, except for the last. The flags argument is a combination of the flags defined below. There is no return value.
send_multipart(\@frames, $flags)
ZMQ_SNDMORE
This method will use the right method for sending independent of the backend that is used.
The recv_multipart($flags) method receives a multipart message from the socket and returns an array of ZMQ::Message objects. The method will receive frames as long as the ZMQ_RCVMORE flag is set on the socket. The flags argument is a combination of the flags defined below.
recv_multipart($flags)
ZMQ_RCVMORE
This method will use the right method for receiving independent of the backend that is used.
The my $optval = $sock->getsockopt(ZMQ_SOME_OPTION) method call retrieves the value for the given socket option.
my $optval = $sock->getsockopt(ZMQ_SOME_OPTION)
The list of option names (constants) varies depending on the underlying libzmq version. Please refer to the manual for libzmq for the correct list.
The $sock->setsockopt(ZMQ_SOME_OPTION, $value) method call sets the specified option to the given value.
$sock->setsockopt(ZMQ_SOME_OPTION, $value)
ZMQ::Socket objects aren't thread safe due to the underlying library. Therefore, they are currently not cloned when a new Perl ithread is spawned. The variables in the new thread that contained the socket in the parent thread will be a scalar reference to undef in the new thread. This makes the Perl wrapper thread safe (i.e. no segmentation faults).
ZMQ::Socket
undef
ZMQ, ZMQ::Socket
http://zeromq.org
Daisuke Maki <daisuke@endeworks.jp>
The ZMQ module is
Copyright (C) 2010 by Daisuke Maki
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.0 or, at your option, any later version of Perl 5 you may have available.
To install ZMQ, copy and paste the appropriate command in to your terminal.
cpanm
cpanm ZMQ
CPAN shell
perl -MCPAN -e shell install ZMQ
For more information on module installation, please visit the detailed CPAN module installation guide.