Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,21 @@ as defined in [RFC 6763](https://tools.ietf.org/html/rfc6763).
Once [installed](#install), you can use the following code to look up the address of a local domain name:

```php
$factory = new Factory();
<?php

require __DIR__ . '/vendor/autoload.php';

$factory = new Clue\React\Mdns\Factory();
$resolver = $factory->createResolver();

$resolver->lookup('hostname.local')->then(function ($ip) {
echo 'Found: ' . $ip . PHP_EOL;
$resolver->resolve('hostname.local')->then(function ($ip) {
echo 'Found: ' . $ip . PHP_EOL;
}, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
```

See also the [examples](examples).
See also the [examples](examples/).

## Usage

Expand Down Expand Up @@ -83,7 +89,7 @@ Sending queries uses a [Promise](https://github.com/reactphp/promise)-based inte
(i.e. either successfully resolved or rejected with an error):

```php
$resolver->lookup($hostname)->then(
$resolver->resolve($hostname)->then(
function ($ip) {
// IP successfully resolved
},
Expand All @@ -105,12 +111,16 @@ you should look into also using [clue/reactphp-block](https://github.com/clue/re
The resulting blocking code could look something like this:

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Clue\React\Block;

$factory = new Factory();
$factory = new Clue\React\Mdns\Factory();
$resolver = $factory->createResolver();

$promise = $resolver->lookup('me.local');
$promise = $resolver->resolve('me.local');

try {
$ip = Block\await($promise, $loop);
Expand All @@ -124,8 +134,8 @@ Similarly, you can also process multiple lookups concurrently and await an array

```php
$promises = array(
$resolver->lookup('first.local'),
$resolver->lookup('second.local'),
$resolver->resolve('first.local'),
$resolver->resolve('second.local'),
);

$ips = Block\awaitAll($promises, $loop);
Expand Down
10 changes: 5 additions & 5 deletions examples/lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
$factory = new Clue\React\Mdns\Factory();
$mdns = $factory->createResolver();

$mdns->resolve($name)->then('e', 'e');

function e($v) {
echo $v . PHP_EOL;
}
$mdns->resolve($name)->then(function ($ip) {
echo 'Found: ' . $ip . PHP_EOL;
}, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});