The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

ZMQ::Socket - ZMQ Socket object

SYNOPSIS

    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();

DESCRIPTION

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.

METHODS

bind

The bind($endpoint) method function creates an endpoint for accepting connections and binds it to the socket.

inproc

Local in-process (inter-thread) communication transport.

ipc

Local inter-process communication transport.

tcp

Unicast transport using TCP.

pgm, epgm

Reliable multicast transport using PGM.

connect

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.

close

Closes and terminates the socket.

send

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] );

sendmsg ( $msg [, $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 is only available if you are using ZMQ::LibZMQ3 as the underlying library.

recv

The semantics of this function varies greatly depending on the underlying version of libzmq.

For ZMQ::LibZMQ2:

    $msg = $sock->recv();

For ZMQ::LibZMQ3:

    $sock->recv( $msg, $len [, $flags] );

recvmsg

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.

recvmsg is only available if you are using ZMQ::LibZMQ3 as the underlying library.

send_multipart( \@frames [, $flags] )

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.

This method will use the right method for sending independent of the backend that is used.

recv_multipart( [$flags] )

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.

This method will use the right method for receiving independent of the backend that is used.

getsockopt

The my $optval = $sock->getsockopt(ZMQ_SOME_OPTION) method call retrieves the value for the given socket 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.

setsockopt

The $sock->setsockopt(ZMQ_SOME_OPTION, $value) method call sets the specified option to the given value.

The list of option names (constants) varies depending on the underlying libzmq version. Please refer to the manual for libzmq for the correct list.

CAVEATS

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

SEE ALSO

ZMQ, ZMQ::Socket

http://zeromq.org

AUTHOR

Daisuke Maki <daisuke@endeworks.jp>

COPYRIGHT AND LICENSE

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.