nanomsg(ZeroMQ with C)
1、应用手册
https://github.com/nanomsg/nanomsg
% mkdir build
% cd build
% cmake ..
% cmake --build .
% ctest .
% sudo cmake --build . --target install
% sudo ldconfig
(if on Linux)
2、性能测试
dong@ubuntu:~/nanomsg-1.1.4/build$ ctest .
Test project /home/dong/nanomsg-1.1.4/build
Start 1: inproc
1/43 Test #1: inproc ........................... Passed 0.51 sec
Start 2: inproc_shutdown
2/43 Test #2: inproc_shutdown .................. Passed 0.26 sec
Start 3: ipc
3/43 Test #3: ipc .............................. Passed 0.71 sec
Start 4: ipc_shutdown
4/43 Test #4: ipc_shutdown ..................... Passed 1.07 sec
Start 5: ipc_stress
5/43 Test #5: ipc_stress ....................... Passed 1.52 sec
Start 6: tcp
6/43 Test #6: tcp .............................. Passed 0.65 sec
Start 7: tcp_shutdown
7/43 Test #7: tcp_shutdown ..................... Passed 2.72 sec
Start 8: ws
8/43 Test #8: ws ............................... Passed 1.73 sec
Start 9: pair
9/43 Test #9: pair ............................. Passed 0.00 sec
Start 10: pubsub
10/43 Test #10: pubsub ........................... Passed 0.12 sec
Start 11: reqrep
11/43 Test #11: reqrep ........................... Passed 0.11 sec
Start 12: pipeline
12/43 Test #12: pipeline ......................... Passed 0.02 sec
Start 13: survey
13/43 Test #13: survey ........................... Passed 1.01 sec
Start 14: bus
14/43 Test #14: bus .............................. Passed 0.01 sec
Start 15: async_shutdown
15/43 Test #15: async_shutdown ................... Passed 2.02 sec
Start 16: block
16/43 Test #16: block ............................ Passed 0.21 sec
Start 17: term
17/43 Test #17: term ............................. Passed 0.11 sec
Start 18: timeo
18/43 Test #18: timeo ............................ Passed 0.21 sec
Start 19: iovec
19/43 Test #19: iovec ............................ Passed 0.00 sec
Start 20: msg
20/43 Test #20: msg .............................. Passed 0.03 sec
Start 21: prio
21/43 Test #21: prio ............................. Passed 0.11 sec
Start 22: poll
22/43 Test #22: poll ............................. Passed 0.15 sec
Start 23: device
23/43 Test #23: device ........................... Passed 0.21 sec
Start 24: device4
24/43 Test #24: device4 .......................... Passed 0.11 sec
Start 25: device5
25/43 Test #25: device5 .......................... Passed 0.11 sec
Start 26: device6
26/43 Test #26: device6 .......................... Passed 1.01 sec
Start 27: device7
27/43 Test #27: device7 .......................... Passed 1.01 sec
Start 28: emfile
28/43 Test #28: emfile ........................... Passed 0.05 sec
Start 29: domain
29/43 Test #29: domain ........................... Passed 0.00 sec
Start 30: trie
30/43 Test #30: trie ............................. Passed 0.00 sec
Start 31: list
31/43 Test #31: list ............................. Passed 0.00 sec
Start 32: hash
32/43 Test #32: hash ............................. Passed 0.02 sec
Start 33: stats
33/43 Test #33: stats ............................ Passed 0.51 sec
Start 34: symbol
34/43 Test #34: symbol ........................... Passed 0.00 sec
Start 35: separation
35/43 Test #35: separation ....................... Passed 0.41 sec
Start 36: zerocopy
36/43 Test #36: zerocopy ......................... Passed 0.00 sec
Start 37: shutdown
37/43 Test #37: shutdown ......................... Passed 0.01 sec
Start 38: cmsg
38/43 Test #38: cmsg ............................. Passed 0.01 sec
Start 39: bug328
39/43 Test #39: bug328 ........................... Passed 0.41 sec
Start 40: bug777
40/43 Test #40: bug777 ........................... Passed 0.00 sec
Start 41: ws_async_shutdown
41/43 Test #41: ws_async_shutdown ................ Passed 1.08 sec
Start 42: reqttl
42/43 Test #42: reqttl ........................... Passed 0.21 sec
Start 43: surveyttl
43/43 Test #43: surveyttl ........................ Passed 0.21 sec
100% tests passed, 0 tests failed out of 43
Total Test time (real) = 18.70 sec
dong@ubuntu:~/nanomsg-1.1.4/build$
3、demo
recv.c
#include <stdio.h> #include<stdlib.h> #include<string.h> #include <assert.h> #include <nanomsg/nn.h> #include <nanomsg/reqrep.h> #include <nanomsg/pubsub.h> #include <nanomsg/pipeline.h>const char *url = "ipc:///tmp/pipeline.ipc";typedef struct{int type;char text[1024]; }buf_t;int main () {buf_t *buf = NULL;buf = (buf_t *)malloc(sizeof(buf_t));int sock = nn_socket (AF_SP, NN_PULL);assert (sock >= 0);assert (nn_bind (sock, url) >= 0);while (1){int bytes = nn_recv (sock, &buf, NN_MSG, 0);assert (bytes >= 0);printf ("NODE0: RECEIVED %d \"%s\"\n", buf->type, buf->text);nn_freemsg (buf);}return 1; }
send.c
#include <stdio.h> #include<stdlib.h> #include<string.h> #include <assert.h> #include <nanomsg/nn.h> #include <nanomsg/reqrep.h> #include <nanomsg/pubsub.h> #include <nanomsg/pipeline.h>const char *url = "ipc:///tmp/pipeline.ipc";typedef struct{int type;char text[1024]; }buf_t;int main () {buf_t *buf = NULL;buf = (buf_t *)malloc(sizeof(buf_t));buf->type = 1;memset(buf->text,0,1024);memcpy(buf->text,"hello,world !",strlen("hello,world !"));int sz_msg = sizeof(buf_t);int sock = nn_socket (AF_SP, NN_PUSH);assert (sock >= 0);assert (nn_connect (sock, url) >= 0);printf ("NODE1: SENDING %d \"%s\"\n", buf->type,buf->text);int bytes = nn_send (sock, buf, sz_msg, 0);assert (bytes == sz_msg);return nn_shutdown (sock, 0); }
编译运行
dong@ubuntu:~/nanomsg_demo$ gcc -o recv recv.c -lnanomsg
dong@ubuntu:~/nanomsg_demo$ ./recv
NODE0: RECEIVED 1 "hello,world !"
NODE0: RECEIVED 1 "hello,world !"
NODE0: RECEIVED 1 "hello,world !"
dong@ubuntu:~/nanomsg_demo$ gcc -o send send.c -lnanomsg
dong@ubuntu:~/nanomsg_demo$ ./send
NODE1: SENDING 1 "hello,world !"
dong@ubuntu:~/nanomsg_demo$ ./send
NODE1: SENDING 1 "hello,world !"
dong@ubuntu:~/nanomsg_demo$ ./send
NODE1: SENDING 1 "hello,world !"
dong@ubuntu:~/nanomsg_demo$
* 进程内通信(inproc):url格式为inproc://test
* 进程间同in想(ipc):url格式为ipc:///tmp/test.ipc
* tcp通信:url格式为tcp://*:5555
参考
nanomsg通信库的pubsub及survey
https://yq.aliyun.com/ziliao/829
https://yq.aliyun.com/articles/8694
https://www.oschina.net/code/snippet_1444806_49921
https://nanomsg.org/v0.1/nn_recv.3.html
1)Getting Started with nanomsg
https://blog.csdn.net/zsy19881226/article/details/56486176
2)This is a sample for p2p network based nanomsg
https://github.com/pch957/nanomsg_p2pnode
转载于:https://www.cnblogs.com/dong1/p/9213214.html
nanomsg(ZeroMQ with C)相关推荐
- nanomsg:ZeroMQ作者用C语言新写的消息队列库
http://geek.csdn.net/news/detail/2299 http://www.freelists.org/post/nanomsg/nanomsg-01alpha-released ...
- 关于创建zeromq消息队列,设置和更改IP地址,远程可以访问,不只是本地链接。python代码。
关于zeromq的创建,绑定本地,和绑定其他客户端的方法. 网上一大堆关于zmq的通信模式的介绍,包括三种类型,具体我就不在描述. 但是他们给的demo,都是创建本地作为server服务端,也作为cl ...
- ZeroMQ实例-使用ZeroMQ进行windows与linux之间的通信
1.本文包括 1)在windows下使用ZMQ 2)在windows环境下与Linux环境下进行网络通信 2.在Linux下使用ZMQ 之前写过一篇如何在Linux环境下使用ZMQ的文章 <Ze ...
- ZeroMq实现跨线程通信
ZeroMq实现跨线程通信 之前在技术崇拜的技术经理指导下阅读了ZeroMq的基础代码,现在就将阅读的心得与成果记录一下,并重新模仿实现了一下经理的异步队列. 1.对外接口 //主要接口(1)void ...
- (转)ZeroMQ的模式-Requset-Reply
2019独角兽企业重金招聘Python工程师标准>>> 我们先来看看第一种模式:Request-Reply Pattern. 请求应答模式. Request-Reply这个名字很直白 ...
- 常见消息队列对比(ActiveMQ、ZeroMQ、kafka、RabbitMQ)?
常见消息队列对比? 消息队列是分布式应用间交换信息的重要组件,消息队列可驻留在内存或磁盘上, 队列可以存储消息直到它们被应用程序读走. 通过消息队列,应用程序可以在不知道彼此位置的情况下独立处理消息, ...
- 一个c/c++分布式框架ZMQ或者ZeroMQ, 介绍和win下安装使用方法
ZMQ(ØMQ.ZeroMQ, 0MQ)看起来像是一套嵌入式的网络链接库,但工作起来更像是一个并发式的框架.它提供的套接字可以在多种协议中传输消息,如线程间.进程间.TCP.广播等.你可以使用套接字构 ...
- 安装zeromq以及zeromq的python示例
下载ZeroMq: wget https://github.com/zeromq/zeromq4-1/releases/download/v4.1.5/zeromq-4.1.5.tar.gz 解压: ...
- ZeroMQ在windows下不同语言的编译
需要准备的工具是vs2008 C++: 用vs2008直接打开项目文件,编译即可,在lib目录下生成有libzmq.dll库. C#: 由于C#版的源码采用的是vs2010开发的,因此需要对里面的项目 ...
最新文章
- 如何确定线程池的大小?
- linux系统未来或应用广泛
- C# 学习笔记(18)操作SQL Server 中
- 基于EM参数估计的SAGE算法的MATLAB仿真
- 【WEB安全】flask不出网回显方式
- 【C++深度剖析教程34】C++中的强制类型转换dynamic_cast
- 青岛大学计算机调剂群,2019山东青岛大学硕士研究生调剂公告(4月16日更新)...
- 罗技M545鼠标是不是垃圾鼠标中的战斗机?
- 手机端搜狗输入法语音转文字的体验报告
- ConcurrentHashMap(jdk1.8)讲解及常见面试题
- iOS创建framework静态库(SDK组件化)
- 苦熬一个月,PDF超过6000页
- Salesforce Aura 组件
- 百汇BCR:什么是外汇交易风险?如何尽量减少风险影响?
- 关于CreateEvent的简单理解
- ArcGis实战:土地利用变化矩阵与土地利用变化图制作
- Google全球IP地址库
- 从阿里P1到P7,他的阿里七年总结就是两个字
- GTC 2017现场直击:以人工智能的名义搞一场黑科技的盛会!
- 精准数据采集是什么?
热门文章
- python中的中文乱码问题深入分析
- 对文本框只允许输入数字
- c#_Array.Sort()
- openwrt+linux编译,openwrt x86 编译部署
- python安装准备_Python安装准备
- python零基础入门大数据_【资源分享】零基础入门大数据(数据分析)经验分享...
- 在Oracle中exception关键字,Oracle表字段有Oracle关键字出现异常解决方案
- 论文翻译_做论文翻译需要知道哪些翻译技巧?知行翻译:这3个技巧
- java desktop类 能打开共享文件夹中的文件吗_计算机二级之JAVA篇
- java模拟器未载入,由于“活页夹线程池”,应用程序未在模拟器上运行