文字

ZMQSocket::connect

(PECL zmq >= 0.5.0)

ZMQSocket::connectConnect the socket

说明

public ZMQSocket ZMQSocket::connect ( string $dsn [, boolean $force = false ] )

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.

范例

Example #1 A ZMQContext() example

Construct a new context and allocate request socket from it

<?php

$dsn  "tcp://127.0.0.1:5555" ;


$socket  = new  ZMQSocket (new  ZMQContext (),  ZMQ :: SOCKET_REQ 'my socket' );


$endpoints  $socket -> getEndpoints ();


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


$socket -> send ( "Hello!" );
$message  $socket -> recv ();

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

返回值

Returns the current object. Throws ZMQSocketException on error.

上一篇: 下一篇: