Demo of sending raw bytes over ZMQ sockets with C++.
This assumes you are using miniconda and have installed cppzmq:
conda install -c conda-forge cppzmq
Demo of sending raw bytes over ZMQ sockets with C++.
This assumes you are using miniconda and have installed cppzmq:
conda install -c conda-forge cppzmq
| cmake_minimum_required(VERSION 3.6) | |
| project(zmqcpp) | |
| find_library(LIBZMQ libzmq.a PATHS ~/miniconda3/lib) | |
| include_directories(~/miniconda3/include) | |
| add_executable(${CMAKE_PROJECT_NAME} main.cpp) | |
| set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY CXX_STANDARD 14) | |
| target_link_libraries(${CMAKE_PROJECT_NAME} ${LIBZMQ}) |
| #include <iostream> | |
| #include <sstream> | |
| #include <thread> | |
| #include <chrono> | |
| #include <zmq.hpp> | |
| int main() { | |
| zmq::context_t ctx(1); | |
| zmq::socket_t socket(ctx, ZMQ_PUB); | |
| socket.bind("tcp://*:9090"); | |
| for (double i = 0; i < 1000; i++) { | |
| std::ostringstream stream; | |
| stream.write(reinterpret_cast<char *>(&i), sizeof(i)); | |
| std::cout << "Sending " << i << std::endl;; | |
| zmq::message_t msg(stream.str().c_str(), stream.str().length()); | |
| socket.send(msg); | |
| std::this_thread::sleep_for(std::chrono::seconds(1)); | |
| } | |
| return 0; | |
| } |