« ZMQSocket::bind
ZMQSocket::__construct »

ZMQSocket::connect

(PECL zmq >= 0.5.0)

ZMQSocket::connect — Connect the socket

説明

public function 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>";
?>

関連キーワード:
socket   ZMQSocket   connect   Connect   connected   endpoint   transport   endpoints   force   address   example   ZMQContext   Server   message   bind   construct   remote   defined   format   following   inproc   epgm   Tries   even   already
関連する関数・ページ:
zmqsocket.bind   zmqsocket.disconnect   class.zmqsocket   zmqsocket.unbind   zmqsocket.getendpoints   zmqsocket.getsockettype