Zeromq advanced stage (1)

Source: Internet
Author: User

The lifecycle of the socket of zeromq is as follows:

Create and destroy sockets: zmq_socket (), zmq_close ()

Configure and read socket options: zmq_setsockopt (), zmq_getsockopt ()

Establish a connection for the socket: zmq_bind (), zmq_connect ()

Send and receive messages: zmq_send (), zmq_recv ()

 

The socket of zeromq is always a null pointer type, and the message is a struct type.

Zmq is asynchronous and highly scalable.

 

Zmq connections are different from traditional TCP connections, mainly including:

Multiple protocols are used: inproc (in-process), IPC (in-process), TCP, PGM (broadcast), and epgm;
When the client uses zmq_connect (), the connection has been established, and a service of this endpoint is not required to be bound using zmq_bind;
The connection is asynchronous and buffered by a group of message queues;
The connection will display a certain message mode, which is determined by the socket type of the connection to be created;
A socket can have multiple input and output connections;
Zmq does not provide functions similar to zmq_accept (), because it automatically starts to accept connections when the socket is bound to an endpoint;
ApplicationProgramYou cannot directly deal with these connections because they are encapsulated at the bottom layer of zmq.

 

 

The difference between TCP socket and zmq socket in data transmission:

Zmq socket transmits messages instead of bytes (TCP) or frames (UDP ). A message refers to a piece of binary data block with a specified length. We will talk about the message below. This design is designed for performance optimization, so it may be hard to understand.

Zmq socket performs I/O operations in the background, that is to say, whether it is receiving or sending messages, it will first be transmitted to a local buffer queue, the size of this memory queue can be configured.

Zmq sockets can be connected to multiple Sockets (if the socket type is allowed ). The TCP protocol can only perform point-to-point connections, while zmq can perform one-to-many (similar to wireless broadcast), many-to-many (similar to post office), and many-to-one (similar to mailbox ), of course, this includes one-to-one scenarios.

Zmq socket can send messages to multiple endpoints (fan-out model) or receive messages from multiple endpoints (fan-in Model)

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.