1. 程式人生 > >ZeroMQ介面函式之 :zmq_tcp – 使用TCP協議的ØMQ網路單播協議

ZeroMQ介面函式之 :zmq_tcp – 使用TCP協議的ØMQ網路單播協議

zmq_tcp(7)          ØMQ Manual - ØMQ/4.1.0

Name

zmq_tcp – 使用TCP協議的ØMQ網路單播協議

Synopsis

TCP是一個應用廣泛、可靠、單播的傳輸協議。當在一個網路中使用ZMQ進行分散式的應用連線時,應該優先使用TCP傳輸協議。

Addressing

一個ØMQ網路節點是一個字串,格式為transport://然後緊跟著一個address。transport指明底層使用的協議。address引數指定了傳輸協議要連線到的地址。

對於TCP傳輸協議來說,transport引數就是tcp,下面解釋了address部分的含義。

給一個socket設定一個本地地址

當使用zmq_bind()函式給一個socket分配一個TCP本地地址的時候,網路節點應解釋為一個介面後面加上冒號和要使用的TCP埠號。

一個地址介面的可能會以下面的形式被指定:

  ● 萬用字元*,表示所有可以使用的介面地址

  ● 用數字形式表示的分配給介面的IPV4或IPV6地址

  ● 被作業系統定義的可移植的介面名稱

TCP埠號可以被如下方式指定:

  ● 在POSIX系統中,通常是1024以上的數字

  ● 萬用字元*,表示系統分配的臨時埠

當使用臨時埠時,呼叫者需要使用ZMQ_LAST_ENDPOINT屬性返回實際被分配的埠號。參見zmq_getsockopt(3)

函式獲取更多細節。

Connecting a socket

當使用zmq_connect()函式以TCP方式連線一個對等的地址時,節點應當被視為對等地址後面加上冒號和TCP埠號。

一個對等資質可以被下面任何一種方式指定。

  ● 對等的DNS名稱

  ● 以數字形式表示的IPV4或者IPV6形式的地址

注意:ZeroMQ Message Transport Protocol (ZMTP)使用的TCP描述文件是http://rfc.zeromq.org/spec:15

Examples

  給socket分配一個本地地址

//  TCP port 5555 on all available interfaces
rc = zmq_bind(socket, "tcp:/// :5555"); assert (rc == 0); // TCP port 5555 on the local loop-back interface on all platforms rc = zmq_bind(socket, "tcp://127.0.0.1:5555"); assert (rc == 0); // TCP port 5555 on the first Ethernet network interface on Linux rc = zmq_bind(socket, "tcp://eth0:5555"); assert (rc == 0);

  連線一個socket

//  Connecting using an IP address
rc = zmq_connect(socket, "tcp://192.168.1.1:5555");
assert (rc == 0);
//  Connecting using a DNS name
rc = zmq_connect(socket, "tcp://server1:5555"); assert (rc == 0);

See also

zmq_bind(3)  zmq_connect(3)  zmq_pgm(7)  zmq_ipc(7)  zmq_inproc(7)  zmq(7)

Authors

This page was written by the ØMQ community. To make a change please read the ØMQ Contribution Policy at http://www.zeromq.org/docs:contributing.

Web site design and content is copyright (c) 2007-2012 iMatix Corporation. Contact us for professional support. Site content licensed under the Creative Commons Attribution-Share Alike 3.0 License. ØMQ is copyright (c) Copyright (c) 2007-2012 iMatix Corporation and Contributors. ØMQ is free software licensed under the LGPL. ØMQ, ZeroMQ, and 0MQ are trademarks of iMatix Corporation. Terms of Use — Privacy

Policy

翻譯:風波

mail : [email protected]