Socket.receive

Receives a message frame.

_receive blocks until the request can be satisfied, and returns the number of bytes in the frame. tryReceive performs the operation in non-blocking mode, and returns a $(STDREF typecons,Tuple) which contains the size of the frame along with a bool value that signifies whether a frame was received. (If the latter is false, the former is always set to zero.)

  1. size_t receive(ubyte[] data)
    struct Socket
    @safe
    size_t
    receive
    (
    scope ubyte[] data
    )
  2. size_t receive(Frame msg)
  3. this(SocketType type)
  4. this(Context context, SocketType type)

Throws

ZmqException if $(ZMQ) reports an error.

Corresponds to

$(ZMQREF zmq_recv()) (with the ZMQ_DONTWAIT flag, in the case of tryReceive).

Examples

// Sender
auto snd = Socket(SocketType.req);
snd.connect("inproc://zmqd_receive_example");
snd.send("Hello World!");

// Receiver
import std.string: representation;
auto rcv = Socket(SocketType.rep);
rcv.bind("inproc://zmqd_receive_example");
char[256] buf;
immutable len  = rcv.receive(buf.representation);
assert (buf[0 .. len] == "Hello World!");

Meta