zmq_connect_peer.txt 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. zmq_connect_peer(3)
  2. ===================
  3. NAME
  4. ----
  5. zmq_connect_peer - create outgoing connection from socket and return the connection routing id in thread-safe and atomic way.
  6. SYNOPSIS
  7. --------
  8. *uint32_t zmq_connect_peer (void '*socket', const char '*endpoint');*
  9. DESCRIPTION
  10. -----------
  11. The _zmq_connect_peer()_ function connects a 'ZMQ_PEER' socket to an 'endpoint' and then returns the endpoint 'routing_id'.
  12. The 'endpoint' is a string consisting of a 'transport'`://` followed by an
  13. 'address'. The 'transport' specifies the underlying protocol to use. The
  14. 'address' specifies the transport-specific address to connect to.
  15. The function is supported only on the 'ZMQ_PEER' socket type and would return `0` with 'errno' set to 'ENOTSUP' otherwise.
  16. The _zmq_connect_peer()_ support the following transports:
  17. 'tcp':: unicast transport using TCP, see linkzmq:zmq_tcp[7]
  18. 'ipc':: local inter-process communication transport, see linkzmq:zmq_ipc[7]
  19. 'inproc':: local in-process (inter-thread) communication transport, see linkzmq:zmq_inproc[7]
  20. 'ws':: unicast transport using WebSockets, see linkzmq:zmq_ws[7]
  21. 'wss':: unicast transport using WebSockets over TLS, see linkzmq:zmq_wss[7]
  22. RETURN VALUE
  23. ------------
  24. The _zmq_connect_peer()_ function returns the peer 'routing_id' if successful. Otherwise it returns
  25. `0` and sets 'errno' to one of the values defined below.
  26. ERRORS
  27. ------
  28. *EINVAL*::
  29. The endpoint supplied is invalid.
  30. *EPROTONOSUPPORT*::
  31. The requested 'transport' protocol is not supported with 'ZMQ_PEER'.
  32. *ENOCOMPATPROTO*::
  33. The requested 'transport' protocol is not compatible with the socket type.
  34. *ETERM*::
  35. The 0MQ 'context' associated with the specified 'socket' was terminated.
  36. *ENOTSOCK*::
  37. The provided 'socket' was invalid.
  38. *EMTHREAD*::
  39. No I/O thread is available to accomplish the task.
  40. *ENOTSUP*::
  41. The socket is not of type 'ZMQ_PEER'.
  42. *EFAULT*::
  43. The 'ZMQ_IMMEDIATE' option is set on the socket.
  44. EXAMPLE
  45. -------
  46. .Connecting a peer socket to a TCP transport and sending a message
  47. ----
  48. /* Create a ZMQ_SUB socket */
  49. void *socket = zmq_socket (context, ZMQ_PEER);
  50. assert (socket);
  51. /* Connect it to the host server001, port 5555 using a TCP transport */
  52. uint32_t routing_id = zmq_connect (socket, "tcp://server001:5555");
  53. assert (routing_id == 0);
  54. /* Sending a message to the peer */
  55. zmq_msg_t msg;
  56. int rc = zmq_msg_init_data (&msg, "HELLO", 5, NULL, NULL);
  57. assert (rc == 0);
  58. rc = zmq_msg_set_routing_id (&msg, routing_id);
  59. assert (rc == 0);
  60. rc = zmq_msg_send (&msg, socket, 0);
  61. assert (rc == 5);
  62. rc = zmq_msg_close (&msg);
  63. assert (rc == 0);
  64. ----
  65. SEE ALSO
  66. --------
  67. linkzmq:zmq_connect[3]
  68. linkzmq:zmq_bind[3]
  69. linkzmq:zmq_socket[3]
  70. linkzmq:zmq[7]
  71. AUTHORS
  72. -------
  73. This page was written by the 0MQ community. To make a change please
  74. read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.