array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'uk', ), 'this' => array ( 0 => 'zmqsocket.connect.php', 1 => 'ZMQSocket::connect', 2 => 'Connect the socket', ), 'up' => array ( 0 => 'class.zmqsocket.php', 1 => 'ZMQSocket', ), 'prev' => array ( 0 => 'zmqsocket.bind.php', 1 => 'ZMQSocket::bind', ), 'next' => array ( 0 => 'zmqsocket.construct.php', 1 => 'ZMQSocket::__construct', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/zmq/zmqsocket/connect.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

ZMQSocket::connect

(PECL zmq >= 0.5.0)

ZMQSocket::connectConnect the socket

Опис

public ZMQSocket::connect(string $dsn, bool $force = false): ZMQSocket

Connect the socket to a remote endpoint. The endpoint is defined in format transport://address where transport is one of the following: inproc, ipc, tcp, pgm or epgm.

Параметри

dsn

The connect dsn, for example transport://address.

force

Tries to connect even if the socket has already been connected to given endpoint.

Значення, що повертаються

Returns the current object.

Помилки/виключення

Throws ZMQSocketException on error.

Приклади

Приклад #1 A ZMQContext() example

Construct a new context and allocate request socket from it

<?php
/* Server hostname */
$dsn = "tcp://127.0.0.1:5555";

/* Create a socket */
$socket = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_REQ, 'my socket');

/* Get list of connected endpoints */
$endpoints = $socket->getEndpoints();

/* Check if the socket is connected */
if (!in_array($dsn, $endpoints['connect'])) {
echo
"<p>Connecting to $dsn</p>";
$socket->connect($dsn);
} else {
echo
"<p>Already connected to $dsn</p>";
}

/* Send and receive */
$socket->send("Hello!");
$message = $socket->recv();

echo
"<p>Server said: {$message}</p>";
?>