(PECL zmq >= 0.5.0)
Connect 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.
Parameters:
dsn
The connect dsn, for example transport://address.
force
Tries to connect even if the socket has already been connected to given endpoint.
Returns:
Returns the current object. Throws ZMQSocketException on error.
Examples:
A ZMQContext() example
Construct a new context and allocate request socket from it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php /* Server hostname */ /* 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>" ; ?> |
Please login to continue.