zstr(7) - Linux man page

Name

zstr - sending and receiving strings

Synopsis

//  Receive a string off a socket, caller must free it
CZMQ_EXPORT char *
    zstr_recv (void *socket);

//  Receive a string off a socket if socket had input waiting
CZMQ_EXPORT char *
    zstr_recv_nowait (void *socket);

//  Send a string to a socket in 0MQ string format
CZMQ_EXPORT int
    zstr_send (void *socket, const char *string);

//  Send a string to a socket in 0MQ string format, with MORE flag
CZMQ_EXPORT int
    zstr_sendm (void *socket, const char *string);

//  Send a formatted string to a socket
CZMQ_EXPORT int
    zstr_sendf (void *socket, const char *format, ...);

//  Send formatted C string to socket with MORE flag
CZMQ_EXPORT int
    zstr_sendfm (void *socket, const char *format, ...);

//  Self test of this class
int
    zstr_test (bool verbose);

Description

The zstr class provides utility functions for sending and receiving C strings across 0MQ sockets. It sends strings without a terminating null, and appends a null byte on received strings. This class is for simple message sending.

Example

From zstr_test method.

 zctx_t *ctx = zctx_new ();
 assert (ctx);

void *output = zsocket_new (ctx, ZMQ_PAIR);
 assert (output);
 zsocket_bind (output, "inproc://zstr.test");
 void *input = zsocket_new (ctx, ZMQ_PAIR);
 assert (input);
 zsocket_connect (input, "inproc://zstr.test");

//  Send ten strings, five strings with MORE flag and then END
 int string_nbr;
 for (string_nbr = 0; string_nbr < 10; string_nbr++)
     zstr_sendf (output, "this is string %d", string_nbr);
 for (string_nbr = 0; string_nbr < 5; string_nbr++)
     zstr_sendfm (output, "this is string %d", string_nbr);
 zstr_send (output, "END");

//  Read and count until we receive END
 string_nbr = 0;
 for (string_nbr = 0;; string_nbr++) {
     char *string = zstr_recv (input);
     if (streq (string, "END")) {
         free (string);
         break;
     }
     free (string);
 }
 assert (string_nbr == 15);

zctx_destroy (&ctx);

See Also

czmq(7)

Authors

The CZMQ manual was written by Pieter Hintjens<ph@imatix.com [1] >.

Resources

Main web site: http://czmq.zeromq.org/

Report bugs to the 0MQ development mailing list: <zeromq-dev@lists.zeromq.org [2] >

Copyright

Copyright © 1991-2010 iMatix Corporation and contributors. License LGPLv3+: GNU LGPL 3 or later <http://gnu.org/licenses/lgpl.html>. This is free software: you are free to change it and redistribute it. There is NO WARRANTY, to the extent permitted by law. For details see the files COPYING and COPYING.LESSER included with the CZMQ distribution.

Notes

1.

ph@imatix.com

mailto:ph@imatix.com
2.

zeromq-dev@lists.zeromq.org

mailto:zeromq-dev@lists.zeromq.org