0MQ messaging ZMQSocket::connect

(PECL zmq >= 0.5.0)

ZMQSocket::connect — 소켓 연결


설명

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

소켓을 원격 끝점에 연결합니다. 끝점은 transport://address 형식으로 정의되며 여기서 전송은 inproc, ipc, tcp, pgm 또는 epgm 중 하나입니다.


매개변수

dsn
바인드 dsn(예: transport://address).
force
소켓이 이미 지정된 끝점에 연결되어 있는 경우에도 연결을 시도합니다.

반환 값

현재 개체를 반환합니다.


오류/예외

오류가 발생하면 ZMQSocketException을 던집니다.


Examples

예제 #1 ZMQContext() 예제

새 컨텍스트를 구성하고 요청 소켓을 할당합니다.

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