'''
'''
'''
About pynng (python nanomsg next generation
可用的协议有以下几个:
Pair0
Pair1
Req0 / Rep0
Pub0 / Sub0
Push0 / Pull0
Surveyor0 / Respondent0
Bus0
与另外的一个socket的交流:
dial()  --send()
listen()  --recv()
#同样也可以异步 支持的库是:syncio and Trio.
asend()
arecv()
#最终执行完的时候:close()
'''
'''
实际在开始执行listen() dial() 的时候,我们应该初始化socket,通过传入一系列的关键词参数
recv_timeout(int):超过固定的时间,报出;pynng.exceptions.Timeout
send_timeout(int):
recv_max_size(int):最大massage的接收情况,默认大小是1MB,如果是0的情况,就是表示不限制接收包的大小
recv_buffer_size(int):socket能够接收的message的数量
send_buffer_size(int):socket放在buffer中的message的数量
name(str):socket 的name
raw(bool): 决定这个socket是否是raw ,当前只支持cooked,目前不支持raw A boolean, indicating whether the socket is raw or cooked. Returns True if the socket is raw, else False. This property is read-only. Corresponds to library option NNG_OPT_RAW. For more information see nng’s documentation. Note that currently, pynng does not support raw mode sockets, but we intend to in the future:
protocol (int): Read-only option which returns the 16-bit number of the socket’s protocol.
protocol_name (str): Read-only option which returns the name of the socket’s protocol.
peer (int): Returns the peer protocol id for the socket.
local_address: The SockAddr representing the local address.
reconnect_time_min(min):以ms为单位,等待最短的时间去尝试重新连接
reconnect_time_max(int):在执行连接之前等待的最大的时间的长短he maximum time to wait before attempting reconnects, in ms. Corresponds to NNG_OPT_RECONNMAXT. If this is non-zero, then the time between successive connection attempts will start at the value of reconnect_time_min, and grow exponentially, until it reaches this value. This option can be set on the socket, or on the dialers associated with the socket.
recv_fd(int): 接收文件描述,这个可以被传入到 select.poll() or select.select() ,否则没有别的用处
send_fd(int):发送的文件描述
#
# When used in select.poll() or select.select(), recv_fd and send_fd are
# both marked as readable when they can receive or send data without blocking.
# So the upshot is that for select.select()
# they should be passed in as the rlist and for select.poll.register()
# the eventmask should be POLLIN.
'''
'''
几个函数的简介:异步函数
await arecv()
await arecv_msg()
await asend(data)
dial(address, *, block=None):block:True:阻塞dial 是可以被尝试1:If True, a blocking dial is attempted. If it fails for any reason, the dial fails and an exception is raised.2:If False, a non-blocking dial is started. The dial is retried periodically in the background until it is successful.3:(Default behavior): If None, a blocking dial is first attempted. If it fails an exception is logged (using the Python logging module), then a non-blocking dial is done.
listen(address,flags=0):listen at specified address
new_context(): 返回一个新的context给 socket
recv(block=True):在socket上面接收数据,这实际上是一个同步的函数,block默认情况下是True,这个时候会指导接收到数据,否则一直处在阻塞状态。如果block=False 的情况下, 他会立即返回当前的结果。如果没有数据就返回pynng.TryAgain
recv_msg(block=True):Receive a Message on the socket.
send(data):Sends data (either bytes or bytearray) on socket.'''
'''
可支持的协议:
1、class pynng.Pair0(**kwargs):::::::::有同步的,有异步的,API,这种情况适用于双向一对一通讯得情况
2、class pynng.Pair1(*, polyamorous=None, **kwargs):::::::::::这是socket,用于有很多partners得双向交流得情况
3、:问答:class pynng.Req0(*, resend_time=None, **kwargs)class pynng.Rep0(**kwargs)
4、Pub and Subclass pynng.Pub0(**kwargs)class pynng.Sub0(**kwargs)pub:不能使用recv 否则会提示 pynng.NotSupported exceptionsub:接收同样的socket的参数,但是还有一个额外的参数就是topics,这个topics 是str bytes类型,这个实际上是一个对应,用来看pub发送的是不是匹配到我当前想要的东西如果这个参数设定为b''空,这个时候,我们就能接收所有的数据了# pub/sub is a “best effort” transport;#  if you have a very high volume of messages be prepared for some messages to be silently dropped.5、Push and Pullclass pynng.Push0(**kwargs)class pynng.Pull0(**kwargs)Push: Push0套接字是数据管道的推入端,数据被推送到唯一的一个pull端,这个对于将工作分配给很多节点很好这也就说明了在push端执行recv()是会报错的Pull:A Pull0 is the receiving end of a data pipeline. It needs to be paired with a Push0 socket. Attempting to send() with a Pull0 socket will raise a pynng.NotSupported exception.
6、 Surveyor0 / Respondent0  class pynng.Surveyor0(**kwargs)class pynng.Respondent0(**kwargs)Surveyor0:  发布一个调查,给这些所有的respodents 一个机会能够发言Respondent0: 接收到一个消息之后可以发言了,但是你是不能够提前发言的7、Bus0class pynng.Bus0(**kwargs)Bus0:发送一个msg 给所有直接相联的peers,这个也就允许我们设计一个网格网络,这个msg也就仅仅发送给直接相联的peersYou must explicitly connect all nodes with the listen() and corresponding listen() calls.''''''
一些基本的概念:
1、pipe:    There is no public constructor for a Pipe; they are automatically added to the underlying socket whenever the pipe is created.class pynng.Pipe(...)await asend(data)Asynchronously send bytes from this Pipe.send(data):Synchronously send bytes from this Pipe. This method automatically creates a Message,associates with this pipe, and sends it with this pipe’s associated Socket.
2、Contextclass pynng.Context(.....)说明:这个是上下文环境nng_context ,可以通过Socket.new_context() 去创建一个上下文这个context实际上支队Req0 和 Rep0 才有用,其他的协议是不支持的说明2:如果我们有了上下文环境,我们可以直接使用send() recv() or async equivalent 说明3:这个上下文环境,跟踪一个协议的状态,这个上下文环境允许相同的socket用于多种不同的操作---多线程,多协程说明4:上下文环境允许多路复用同一个socket , 它删除了需要使用原始套接字的最大用例之一。说明5:上下文环境不能直接实例化,我们需要创建一个socket 然后 调用new_context()await arecv()Asynchronously receive data using this context.await arecv_msg()Asynchronously receive a Message on the context.await asend(data)Asynchronously send data using this context.close()Close this context.recv()Synchronously receive data on this context.recv_msg()Synchronously receive a Message using this context.send(data)Synchronously send data on the context.
3、Messageclass pynng.Message(data)说明:使用消息接口可以更好地控制发送消息的各个方面。特别是,您可以判断消息来自on receive的哪个管道,并且可以指示消息将从on send发送到哪个管道说明1:通常情况,不需要创建Message,只需要通过Socket.recv_msg() 这个时候就实例化了一个message这个我们也就可以通过Pipe.send()来发送数据了说明2:由于我们使用message的情况下,就是为了更加方便使用一个特定pipe所以我们需要能够更加方便: pipe.send() or pipe.asend()说明3:Messages in pynng are immutable; this is to prevent data corruption.警告:可以使用_buffer属性访问消息的底层数据缓冲区。但是,必须注意不要在对缓冲区的引用仍然存在时发送消息;如果在消息发送后使用缓冲区,可能会导致分段错误或数据损坏(读:will)。
4、Dialer      class pynng.Dialer(...)说明:  A Dialer is associated with a single Socket. The associated socket can be accessed via the socket attribute. There is no public constructor for creating a Dialerclose() 关闭当前dialer
5、Listenerclass pynng.Listener(...)The Python version of nng_listener. A Listener is returned whenever Socket.listen() is called.A list of active listeners can be accessed via Socket.listenersclose()Close the listener.
'''

上面是我过python的脚本写的,下面是实际的文字:

'''
'''
'''
About pynng (python nanomsg next generation
可用的协议有以下几个:
Pair0
Pair1
Req0 / Rep0
Pub0 / Sub0
Push0 / Pull0
Surveyor0 / Respondent0
Bus0
与另外的一个socket的交流:
dial()  --send()
listen()  --recv()
#同样也可以异步 支持的库是:syncio and Trio.
asend()
arecv()
#最终执行完的时候:close()
'''
'''
实际在开始执行listen() dial() 的时候,我们应该初始化socket,通过传入一系列的关键词参数
recv_timeout(int):超过固定的时间,报出;pynng.exceptions.Timeout
send_timeout(int):
recv_max_size(int):最大massage的接收情况,默认大小是1MB,如果是0的情况,就是表示不限制接收包的大小
recv_buffer_size(int):socket能够接收的message的数量
send_buffer_size(int):socket放在buffer中的message的数量
name(str):socket 的name
raw(bool): 决定这个socket是否是raw ,当前只支持cooked,目前不支持raw A boolean, indicating whether the socket is raw or cooked. Returns True if the socket is raw, else False. This property is read-only. Corresponds to library option NNG_OPT_RAW. For more information see nng’s documentation. Note that currently, pynng does not support raw mode sockets, but we intend to in the future:
protocol (int): Read-only option which returns the 16-bit number of the socket’s protocol.
protocol_name (str): Read-only option which returns the name of the socket’s protocol.
peer (int): Returns the peer protocol id for the socket.
local_address: The SockAddr representing the local address.
reconnect_time_min(min):以ms为单位,等待最短的时间去尝试重新连接
reconnect_time_max(int):在执行连接之前等待的最大的时间的长短he maximum time to wait before attempting reconnects, in ms. Corresponds to NNG_OPT_RECONNMAXT. If this is non-zero, then the time between successive connection attempts will start at the value of reconnect_time_min, and grow exponentially, until it reaches this value. This option can be set on the socket, or on the dialers associated with the socket.
recv_fd(int): 接收文件描述,这个可以被传入到 select.poll() or select.select() ,否则没有别的用处
send_fd(int):发送的文件描述
#
# When used in select.poll() or select.select(), recv_fd and send_fd are
# both marked as readable when they can receive or send data without blocking.
# So the upshot is that for select.select()
# they should be passed in as the rlist and for select.poll.register()
# the eventmask should be POLLIN.
'''
'''
几个函数的简介:异步函数
await arecv()
await arecv_msg()
await asend(data)
dial(address, *, block=None):block:True:阻塞dial 是可以被尝试1:If True, a blocking dial is attempted. If it fails for any reason, the dial fails and an exception is raised.2:If False, a non-blocking dial is started. The dial is retried periodically in the background until it is successful.3:(Default behavior): If None, a blocking dial is first attempted. If it fails an exception is logged (using the Python logging module), then a non-blocking dial is done.
listen(address,flags=0):listen at specified address
new_context(): 返回一个新的context给 socket
recv(block=True):在socket上面接收数据,这实际上是一个同步的函数,block默认情况下是True,这个时候会指导接收到数据,否则一直处在阻塞状态。如果block=False 的情况下, 他会立即返回当前的结果。如果没有数据就返回pynng.TryAgain
recv_msg(block=True):Receive a Message on the socket.
send(data):Sends data (either bytes or bytearray) on socket.'''
'''
可支持的协议:
1、class pynng.Pair0(**kwargs):::::::::有同步的,有异步的,API,这种情况适用于双向一对一通讯得情况
2、class pynng.Pair1(*, polyamorous=None, **kwargs):::::::::::这是socket,用于有很多partners得双向交流得情况
3、:问答:class pynng.Req0(*, resend_time=None, **kwargs)class pynng.Rep0(**kwargs)
4、Pub and Subclass pynng.Pub0(**kwargs)class pynng.Sub0(**kwargs)pub:不能使用recv 否则会提示 pynng.NotSupported exceptionsub:接收同样的socket的参数,但是还有一个额外的参数就是topics,这个topics 是str bytes类型,这个实际上是一个对应,用来看pub发送的是不是匹配到我当前想要的东西如果这个参数设定为b''空,这个时候,我们就能接收所有的数据了# pub/sub is a “best effort” transport;#  if you have a very high volume of messages be prepared for some messages to be silently dropped.5、Push and Pullclass pynng.Push0(**kwargs)class pynng.Pull0(**kwargs)Push: Push0套接字是数据管道的推入端,数据被推送到唯一的一个pull端,这个对于将工作分配给很多节点很好这也就说明了在push端执行recv()是会报错的Pull:A Pull0 is the receiving end of a data pipeline. It needs to be paired with a Push0 socket. Attempting to send() with a Pull0 socket will raise a pynng.NotSupported exception.
6、 Surveyor0 / Respondent0  class pynng.Surveyor0(**kwargs)class pynng.Respondent0(**kwargs)Surveyor0:  发布一个调查,给这些所有的respodents 一个机会能够发言Respondent0: 接收到一个消息之后可以发言了,但是你是不能够提前发言的7、Bus0class pynng.Bus0(**kwargs)Bus0:发送一个msg 给所有直接相联的peers,这个也就允许我们设计一个网格网络,这个msg也就仅仅发送给直接相联的peersYou must explicitly connect all nodes with the listen() and corresponding listen() calls.''''''
一些基本的概念:
1、pipe:    There is no public constructor for a Pipe; they are automatically added to the underlying socket whenever the pipe is created.class pynng.Pipe(...)await asend(data)Asynchronously send bytes from this Pipe.send(data):Synchronously send bytes from this Pipe. This method automatically creates a Message,associates with this pipe, and sends it with this pipe’s associated Socket.
2、Contextclass pynng.Context(.....)说明:这个是上下文环境nng_context ,可以通过Socket.new_context() 去创建一个上下文这个context实际上支队Req0 和 Rep0 才有用,其他的协议是不支持的说明2:如果我们有了上下文环境,我们可以直接使用send() recv() or async equivalent 说明3:这个上下文环境,跟踪一个协议的状态,这个上下文环境允许相同的socket用于多种不同的操作---多线程,多协程说明4:上下文环境允许多路复用同一个socket , 它删除了需要使用原始套接字的最大用例之一。说明5:上下文环境不能直接实例化,我们需要创建一个socket 然后 调用new_context()await arecv()Asynchronously receive data using this context.await arecv_msg()Asynchronously receive a Message on the context.await asend(data)Asynchronously send data using this context.close()Close this context.recv()Synchronously receive data on this context.recv_msg()Synchronously receive a Message using this context.send(data)Synchronously send data on the context.
3、Messageclass pynng.Message(data)说明:使用消息接口可以更好地控制发送消息的各个方面。特别是,您可以判断消息来自on receive的哪个管道,并且可以指示消息将从on send发送到哪个管道说明1:通常情况,不需要创建Message,只需要通过Socket.recv_msg() 这个时候就实例化了一个message这个我们也就可以通过Pipe.send()来发送数据了说明2:由于我们使用message的情况下,就是为了更加方便使用一个特定pipe所以我们需要能够更加方便: pipe.send() or pipe.asend()说明3:Messages in pynng are immutable; this is to prevent data corruption.警告:可以使用_buffer属性访问消息的底层数据缓冲区。但是,必须注意不要在对缓冲区的引用仍然存在时发送消息;如果在消息发送后使用缓冲区,可能会导致分段错误或数据损坏(读:will)。
4、Dialer      class pynng.Dialer(...)说明:  A Dialer is associated with a single Socket. The associated socket can be accessed via the socket attribute. There is no public constructor for creating a Dialerclose() 关闭当前dialer
5、Listenerclass pynng.Listener(...)The Python version of nng_listener. A Listener is returned whenever Socket.listen() is called.A list of active listeners can be accessed via Socket.listenersclose()Close the listener.
'''

nanomsg-pynng库的简单学习笔记相关推荐

  1. 特征提取算法简单学习笔记

    update 2021.04.22 这几年的经验下来,以前以为特征提取的方法时共通的,注意力都在后续算法部分,现在的感受是,不同领域算法反而很多时候时共通的,特征提取差异很大,不能简单的一言以蔽之,这 ...

  2. 日志库 winston 的学习笔记 - logger.info 的实现原理单步调试

    按照这篇文章日志库 winston 的学习笔记 - 创建一个使用 winston 的 Node.js 应用里的代码,对下列方法进行单步调试: 因为我们调用的是 info 方法,所以生成的日志,leve ...

  3. marshmallow库的简单学习

    marshmallow库的简单学习 一.简单说明 二.创建Schema类 三.序列化和反序列化 1.定义 2.序列化 3.反序列化 4.部分序列化 5.部分反序列化(这部分应放在特殊用法) 四.数据校 ...

  4. python re库函数_python re库的正则表达式学习笔记

    1. 安装 默认已经安装好了python环境了 re库是python3的核心库,不需要pip install,直接import就行 2. 最简单的模式 字符本身就是最简单的模式 比如:'A', 'I ...

  5. 配置库用户_GEE学习笔记 六十八:【GEE之Python版教程二】配置Python开发环境

    这一篇内容主要讲解两部分内容,第一部分是本地python开发环境的配置,第二部分是GEE的python开发环境配置.我这里做的所有的操作都是在我的Mac电脑上做的,Windows上操作类似,如果有不清 ...

  6. 开源机器人库orocos KDL 学习笔记(四):Forward Kinematric

    上一篇主要讲述了KDL中运动链的建立方式,以及与其相关的段(Segment)和关节(Joint)的概念,这些是串联机械臂运动学的基础.本篇主要讲述KDL中正运动学解的实现方式及其使用. 1. puma ...

  7. 网易蜂巢简单学习笔记

    这个笔记是在学习网易云课堂Java Web微专业的入门课程中单个章节时记下的. 主要是一些命令以及网易蜂巢的简单使用. 简单笔记

  8. 图解远程版本库开发周期 —— Git 学习笔记 22

    图解远程版本库开发周期 文章目录 图解远程版本库开发周期 克隆版本库 快进推送 非快进推送 fetch 命令 merge 命令 push 命令 参考资料 克隆版本库 假设服务器上有一个简单的版本库: ...

  9. 日志库 winston 的学习笔记 - 创建一个使用 winston 的 Node.js 应用

    winston 被设计为一个简单且通用的日志库,支持多种传输. 传输本质上是日志的存储设备. 每个 winston 记录器都可以在不同级别配置多个存储渠道.例如,人们可能希望将错误日志存储在持久的远程 ...

最新文章

  1. 如何设置不一样的奇偶页页眉?
  2. Linux 将文件夹下的所有文件复制到另一个文件里
  3. 21个营销机构网站设计案例
  4. 核心动画05-CAAnimationGroup
  5. python购物车模块
  6. 怎么用c语言写一个贪吃蛇,刚学C语言,想写一个贪吃蛇的代码
  7. 附录-实模式下1M内存
  8. 条款2. 最好使用C++转型操作符
  9. 分享一次学习中遇到的问题
  10. IDEA JetBrains Mono 字体安装
  11. 真正会沟通的项目经理,不会告诉你的4件事
  12. 计算机科学与技术的学士服是什么颜色的,学士服颜色分类 各色学士服都有什么讲究...
  13. 面试总结:给应届生一些找工作的基本建议,毕竟我踩坑多
  14. 思科无线服务器,Cisco统一无线网络TACACS+配置
  15. 如何免费将一个PDF拆分成多个文件?
  16. 用VB评估数学表达式
  17. 微信小程序wx:key使用
  18. MySQL分区(Partition)功能
  19. crontab环境变量问题
  20. Android初学------系统设置之设置输入法

热门文章

  1. LLMs之InstructGPT:《Training language models to follow instructions with human feedback》翻译与解读
  2. 图像颜色处理(一)----由LCD屏幕显示像素格式引出的思考(调色板,CLUT)
  3. 通过Wireshark抓包疯狂聊天程序聊天记录
  4. cocoscreator固定旋转_cocoscreator全平台横竖屏切换
  5. IBM即将倒闭,微软离倒闭还有18个月
  6. STM32-F407入门学习专题(二) STM32复位和中断
  7. 微信支持聊天图片搜索;任天堂社长称暂不入局元宇宙,因为没弄懂;英特尔开放x86内核授权 | EA周报...
  8. USB3.0移动硬盘启动Win7的方法(AHCI/AMD USB3.0/Win7)
  9. 素数(质数)判断的五种方法
  10. avada打开速度慢怎么办?