ZeroMQ There is mainly a namespace zmq. There are many classes under it .zmq.hpp The main classes in are :

*
context_t

*
message_t

*
socket_t

*
monitor_t

*
error_t

     among context_t,message_t All have a friend element socket_t.

socket_t There is a friend element monitor_t.

     Start with code examples :

REQ-REP Model :

client.cpp
// Hello World client #include <zmq.h> #include <string.h> #include <stdio.h>
#include <unistd.h> int main (void) { printf ("Connecting to hello world
server…\n"); void *context = zmq_ctx_new (); void *requester = zmq_socket
(context, ZMQ_REQ); zmq_connect (requester, "tcp://localhost:5555"); int
request_nbr; for (request_nbr = 0; request_nbr != 10; request_nbr++) { char
buffer [10]; printf ("Sending Hello %d…\n", request_nbr); zmq_send (requester,
"Hello", 5, 0); zmq_recv (requester, buffer, 10, 0); printf ("Received World
%d\n", request_nbr); } zmq_close (requester); zmq_ctx_destroy (context); return
0; } // Hello World server in C++ // Binds REP socket to tcp://*:5555 //
Expects "Hello" from client, replies with "World" // #include <zmq.hpp>
#include <string> #include <iostream> #ifndef _WIN32 #include <unistd.h> #else
#include <windows.h> #define sleep(n) Sleep(n) #endif int main () { // Prepare
our context and socket zmq::context_t context (1); zmq::socket_t socket
(context, ZMQ_REP); socket.bind ("tcp://*:5555"); while (true) { zmq::message_t
request; // Wait for next request from client socket.recv (&request); std::cout
<< "Received Hello" << std::endl; // Do some 'work' sleep(1); // Send reply
back to client zmq::message_t reply (5); memcpy (reply.data (), "World", 5);
socket.send (reply); } return 0; }
    zmq::context_t context (1); Create a context_t class .

use zmq::context_t context Yes .

     There are 3 Constructors , One of them is mobile semantics . Essentially for use zmq_ctx_new() To create a pointer . Only constructors with parameters will use zmq_ctx_set() function .
// Constructor without parameters context_t ();// afferent io_threads_(IO Threaded ID) and max_sockets_( maximum connection )context_t
(int io_threads_, int max_sockets_ = ZMQ_MAX_SOCKETS_DFLT);// Mobile semantics
context_t (context_t &&rhs) ZMQ_NOTHROW : ptr (rhs.ptr);
zmq::socket_t socket:

     Create a socket_t class . There are 3 Constructors , One of them is mobile semantics . Essentially for use zmq_ctx_new() To create a pointer . Only constructors with parameters will use zmq_ctx_set() function .

     ZMQ_REQ,ZMQ_REP Corresponding to the 0 and 1.

*  
*  
*   socket_t(context_t& context_, int type_);
socket_t(context_t& context_, socket_type type_);socket_t(socket_t&& rhs)
ZMQ_NOTHROW : ptr(rhs.ptr);
     Constructors are all passed in context Then call init() Function to initialize pointer *ptr and *ctxptr.

 

zmq::message_t request:

     Create a message_t class . There are 6 Constructors and a mobile semantic constructor . Too many constructors . Please check for yourself . Mainly for storing information .

    socket.bind ("tcp://*:5555"); Call socket.bind() Function in TCP/IP Binding port on Protocol 5555.

    socket.send() send message .

    socket.recv() Receiving information .

Technology
©2019-2020 Toolsou All rights reserved,
el-select At the same time label and value value airflow Question series 2 —— task keep running Suspended animation Golang Array bisection , Array split , Array grouping ( Essence )2020 year 8 month 2 day TypeScript The use of generics Map judge key Corresponding value Does the value exist -containsKey()( Essence )2020 year 7 month 30 day Wechat applet Use of modules ( Essence )2020 year 6 month 29 day C# Class library Interface signature verification java Compile time and runtime exceptions in common 5 species JAVA Runtime exception Linux File name validity detection