I'm attempting to use the ZMQ draft specs ZMQ_RADIO
and ZMQ_DISH
. I built libzmq and cppzmq with CMake ExternalProject
and and the flag ENABLE_DRAFTS=ON
and verified it was built with drafts using the zmq_has()
function. I modified the standard hello world example to use radio and dish and cannot get them to talk. I also get compilation errors that ZMQ_RADIO
and ZMQ_DISH
are undefined. I defined them manually and it compiles but I never get an actual connection so it seems like something else is wrong.
Here's my code:
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.11)
project(zmq_udp)
include(ExternalProject)
ExternalProject_Add(libzmq
GIT_REPOSITORY https://github.com/zeromq/libzmq
GIT_TAG master
CMAKE_ARGS
-DENABLE_DRAFTS=ON
-DWITH_PERF_TOOL=OFF
-DZMQ_BUILD_TESTS=OFF
-DENABLE_CPACK=OFF
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/zmq
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_BINARY_DIR}/zmq/lib
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_SHARED_LINKER_FLAGS=${CMAKE_SHARED_LINKER_FLAGS}
)
ExternalProject_Add(cppzmq
GIT_REPOSITORY https://github.com/zeromq/cppzmq
GIT_TAG master
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/zmq.hpp ${CMAKE_BINARY_DIR}/zmq/include/zmq.hpp
TEST_COMMAND ""
)
add_dependencies(cppzmq libzmq)
set(ZEROMQ_LIBNAME "libzmq.so")
set(ZEROMQ_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/zmq/include)
set(ZEROMQ_LIBRARIES ${CMAKE_BINARY_DIR}/zmq/lib/${ZEROMQ_LIBNAME})
include_directories(${ZEROMQ_INCLUDE_DIRS})
add_executable(server server.cpp)
add_executable(client client.cpp)
add_dependencies(server cppzmq)
add_dependencies(client cppzmq)
target_link_libraries(server ${ZEROMQ_LIBRARIES})
target_link_libraries(client ${ZEROMQ_LIBRARIES})
server.cpp
#include <zmq.hpp>
#include <string>
#include <iostream>
#define ZMQ_DISH 15
int main ()
{
std::cout << zmq_has("draft") << std::endl;
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_DISH);
socket.bind ("udp://127.0.0.1:5555");
while (true)
{
zmq::message_t request;
socket.recv (&request);
std::cout << "Received Hello" << std::endl;
}
return 0;
}
client.cpp
#include <zmq.hpp>
#include <string>
#include <iostream>
#include <unistd.h>
#define ZMQ_RADIO 14
int main ()
{
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_RADIO);
std::cout << "Connecting to hello world server…" << std::endl;
socket.connect ("udp://127.0.0.1:5555");
for (int request_nbr = 0; request_nbr != 10; request_nbr++)
{
zmq::message_t request (5);
memcpy (request.data (), "Hello", 5);
std::cout << "Sending Hello " << request_nbr << "…" << std::endl;
socket.send (request);
sleep(1);
}
return 0;
}
The server outputs a 1 as expected for the zmq_has()
function, which should verify libzmq was built with the draft API mode on.
What do I need to do to get RADIO/DISH
to work properly?
I'd like to use ZMQ on a project as a UDP receiver to receive some UDP packets from a non-ZMQ application.