ZMQSocket::connect

(PECL zmq >= 0.5.0)

ZMQSocket::connectConnect the socket

Description

public 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.

Parameters

dsn

The connect dsn, for example transport://address.

force

Tries to connect even if the socket has already been connected to given endpoint.

Return Values

Returns the current object.

Errors/Exceptions

Throws ZMQSocketException on error.

Examples

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

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial