Zeromq install

Installl

sudo aptitude install libtool autoconf automake
wget http://download.zeromq.org/zeromq-3.2.2.tar.gz
./configure
make
make install

install binding cpp

git clone https://github.com/zeromq/cppzmq
sudo cp cppzmq /usr/include

server.cpp

//
//  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>
#include <unistd.h>

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 ((void *) reply.data (), "World", 5);
        socket.send (reply);
    }
    return 0;
}

client.cpp

//
//  Hello World client in C++
//  Connects REQ socket to tcp://localhost:5555
//  Sends "Hello" to server, expects "World" back
//
#include <zmq.hpp>
#include <string>
#include <iostream>

int main ()
{
    //  Prepare our context and socket
    zmq::context_t context (1);
    zmq::socket_t socket (context, ZMQ_REQ);

    std::cout << "Connecting to hello world server…" << std::endl;
    socket.connect ("tcp://localhost:5555");

    //  Do 10 requests, waiting each time for a response
    for (int request_nbr = 0; request_nbr != 10; request_nbr++) {
        zmq::message_t request (6);
        memcpy ((void *) request.data (), "Hello", 5);
        std::cout << "Sending Hello " << request_nbr << "…" << std::endl;
        socket.send (request);

        //  Get the reply.
        zmq::message_t reply;
        socket.recv (&reply);
        std::cout << "Received World " << request_nbr << std::endl;
    }
    return 0;
}

compile

g++ client.cpp -lzmq

Error

        linux-vdso.so.1 =>  (0x00007fff2a0ee000)
	libzmq.so.3 => not found
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f0a58b65000)
	libm.so.6 => /lib/libm.so.6 (0x00007f0a588e2000)
	libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f0a586cc000)
	libc.so.6 => /lib/libc.so.6 (0x00007f0a5836a000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f0a58e8e000)

umm

ldconfig
Remove all ads