zmq-windows使用

编译

查看 install 文件, 使用 cmake 导出 vs2015 工程,然后编译

下载例子项目

1
git clone --depth=1 https://github.com/imatix/zguide.git

pub-sub example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
auto pzmq_ctx_new = g_dllzmq.getDllFunc<void*()>("zmq_ctx_new");
auto pzmq_socket = g_dllzmq.getDllFunc<void*(void *context, int type)>("zmq_socket");
auto pzmq_bind = g_dllzmq.getDllFunc<int(void *socket, const char *endpoint)>("zmq_bind");
auto pzmq_recv = g_dllzmq.getDllFunc<int(void *socket, void *buf, size_t len, int flags)>("zmq_recv");
auto pzmq_send = g_dllzmq.getDllFunc<int(void *socket, void *buf, size_t len, int flags)>("zmq_send");
auto pzmq_close = g_dllzmq.getDllFunc<int(void *socket)>("zmq_close");
auto pzmq_ctx_destroy = g_dllzmq.getDllFunc<int(void *context)>("zmq_ctx_destroy");
auto pzmq_setsockopt = g_dllzmq.getDllFunc<int(void *socket, int option_name, const void *option_value, size_t option_len)>("zmq_setsockopt");


// Prepare our context and publisher
void* pCtx = pzmq_ctx_new();
// Socket to talk to clients
void *publisher = pzmq_socket(pCtx, ZMQ_PUB);
int rc = pzmq_bind(publisher, "tcp://*:5563");
assert(rc == 0);

while (FLAG_EXIT_WORKTHREAD != (pwnd->m_iFlag&FLAG_EXIT_WORKTHREAD))
{
// broadcast information.
pzmq_send(publisher, "A", 1, ZMQ_SNDMORE);
pzmq_send(publisher, "Hi World", strlen("Hi World"), 0);

pzmq_send(publisher, "B", 1, ZMQ_SNDMORE);
pzmq_send(publisher, "Hello World", strlen("Hello World"), 0);

Sleep(3000);
}
pzmq_close(publisher);
pzmq_ctx_destroy(pCtx);
坚持原创技术分享,您的支持将鼓励我继续创作!