zmq_socket()

Name

zmq_socket : 创建0MQ socket

Synopsis

void *zmq_socket(void *context, int type)

描述

zmq_socket(): 在一个特定的context中创建一个0MQ socket,返回一个不透明的句柄到新创建的socket中。

type: 指定socket类型。

新创建的socket初试时时未绑定的,不和任何相关联。为了建立一个信息流,socket必须首先zmq_connect()其中一个终端,或是zmq_bind();


与传统socket的不同:

传统socket提供的同步接口,要么是面向连接的可靠的字节流(SOCK_STREAM),要么是无连接不可靠的数据包(SOCK_DGRAM).

0MQ socket 是异步的,物理连接的安装和卸载,重连和有效地转发等对用户来说都是透明的,时间由0MQ自己控制。 消息会排队,当一个peer不能有效接收时。


传统socket :严格的1-1(2个peer)、N-1(多个client,一个server)、1-N(多播)。

0MQ: ZMQ_PAIR是个特例。0MQ socket 可以连接到多个终端,使用zmq_connect();同时,可以结果多个终端的信息,使用zmq_bind().  N-N的模式


线程安全:

0MQ socket不是线程安全的。 Applications MUST NOT use a socket from multiple threads except after migrating a socket from one thread to another with a "full fence" memory barrier.

Socket类型

  1. Request-reply pattern:
    Summary of ZMQ_REQ characteristics
    Compatible peer sockets ZMQ_REPZMQ_ROUTER
    Direction Bidirectional
    Send/receive pattern Send, Receive, Send, Receive, …
    Outgoing routing strategy Round-robin
    Incoming routing strategy Last peer
    Action in mute state Block
    Summary of ZMQ_REP characteristics
    Compatible peer sockets ZMQ_REQZMQ_DEALER
    Direction Bidirectional
    Send/receive pattern Receive, Send, Receive, Send, …
    Incoming routing strategy Fair-queued
    Outgoing routing strategy Last peer
    Action in mute state Drop
    Summary of ZMQ_DEALER characteristics
    Compatible peer sockets ZMQ_ROUTERZMQ_REPZMQ_DEALER
    Direction Bidirectional
    Send/receive pattern Unrestricted
    Outgoing routing strategy Round-robin
    Incoming routing strategy Fair-queued
    Action in mute state Block


    Summary of ZMQ_ROUTER characteristics
    Compatible peer sockets ZMQ_DEALERZMQ_REQZMQ_ROUTER
    Direction Bidirectional
    Send/receive pattern Unrestricted
    Outgoing routing strategy See text
    Incoming routing strategy Fair-queued
    Action in mute state Drop
    Summary of ZMQ_DEALER characteristics
    Compatible peer sockets ZMQ_ROUTERZMQ_REPZMQ_DEALER
    Direction Bidirectional
    Send/receive pattern Unrestricted
    Outgoing routing strategy Round-robin
    Incoming routing strategy Fair-queued
    Action in mute state Block

  2. Publish-subscribe pattern : 1-N (1 publisher,multiple subscribers
  1. Summary of ZMQ_XSUB characteristics
    Compatible peer sockets ZMQ_PUBZMQ_XPUB
    Direction Unidirectional
    Send/receive pattern Receive messages, send subscriptions
    Incoming routing strategy Fair-queued
    Outgoing routing strategy N/A
    Action in mute state Drop
    Summary of ZMQ_SUB characteristics
    Compatible peer sockets ZMQ_PUBZMQ_XPUB
    Direction Unidirectional
    Send/receive pattern Receive only
    Incoming routing strategy Fair-queued
    Outgoing routing strategy N/A
    Action in mute state Drop
    Summary of ZMQ_PUB characteristics
    Compatible peer sockets ZMQ_SUBZMQ_XSUB
    Direction Unidirectional
    Send/receive pattern Send only
    Incoming routing strategy N/A
    Outgoing routing strategy Fan out
    Action in mute state Drop
    Summary of ZMQ_XPUB characteristics
    Compatible peer sockets ZMQ_SUBZMQ_XSUB
    Direction Unidirectional
    Send/receive pattern Send messages, receive subscriptions
    Incoming routing strategy N/A
    Outgoing routing strategy Fan out
    Action in mute state Drop
  2. pipeline pattern:ZMQ_PUSH、ZMQ_PULL
    Summary of ZMQ_PUSH characteristics
    Compatible peer sockets ZMQ_PULL
    Direction Unidirectional
    Send/receive pattern Send only
    Incoming routing strategy N/A
    Outgoing routing strategy Round-robin
    Action in mute state Block

Summary of ZMQ_PULL characteristics
Compatible peer sockets ZMQ_PUSH
Direction Unidirectional
Send/receive pattern Receive only
Incoming routing strategy Fair-queued
Outgoing routing strategy N/A
Action in mute state Block

你可能感兴趣的:(zeromq)