GoLang ZMQContext::getSocket

request it (179)
GoLang replacement for PHP's ZMQContext::getSocket [edit | history]

Do you know a GoLang replacement for PHP's ZMQContext::getSocket? Write it!

PHP ZMQContext::getSocket

PHP original manual for ZMQContext::getSocket [ show | php.net ]


(PECL zmq >= 0.5.0)

ZMQContext::getSocketCreate a new socket


public ZMQSocket ZMQContext::getSocket ( int $type [, string $persistent_id = NULL [, callback $on_new_socket = NULL ]] )

Shortcut for creating new sockets from the context. If the context is not persistent the persistent_id parameter is ignored and the socket falls back to being non-persistent. The on_new_socket is called only when a new underlying socket structure is created.



ZMQ::SOCKET_* constant to specify socket type.


If persistent_id is specified the socket will be persisted over multiple requests.


Callback function, which is executed when a new socket structure is created. This function does not get invoked if the underlying persistent connection is re-used. The callback takes ZMQSocket and persistent_id as two arguments.


Example #1 A ZMQContext() example

Basic usage

/* Allocate a new context */
$context = new ZMQContext();

/* Create a new socket */
$socket $context->getSocket(ZMQ::SOCKET_REQ'my sock');

/* Connect the socket */

/* Send a request */
$socket->send("Hello there");

/* Receive back the response */
$message $socket->recv();
"Received message: {$message}\n";

Return Values

Returns a ZMQSocket object on success. Throws ZMQSocketException on error.