Skip to content

Commit ae4253a

Browse files
committed
Update README.md
1 parent 72682e3 commit ae4253a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,47 @@ $loop->run();
3232

3333
See also the [examples](examples).
3434

35+
## Usage
36+
37+
### Factory
38+
39+
The `Factory` is responsible for creating your [`Resolver`](#resolver) instance.
40+
It also registers everything with the main [`EventLoop`](https://github.com/reactphp/event-loop#usage).
41+
42+
```php
43+
$loop = React\EventLoop\Factory::create();
44+
$factory = new Factory($loop);
45+
```
46+
47+
#### createResolver()
48+
49+
The `createResolver()` method can be used to create a mDNS resolver instance that sends multicast DNS queries and waits for incoming unicast DNS responses. It returns a [`Resolver`](#resolver) instance.
50+
51+
### Resolver
52+
53+
The [`Factory`](#factory) creates instances of the `React\Dns\Resolver\Resolver` class from the [react/dns](https://github.com/reactphp/dns) package.
54+
55+
While React's *normal* DNS resolver uses unicast UDP messages (and TCP streams) to query a given nameserver,
56+
this resolver instance uses multicast UDP messages to query all reachable hosts in your network.
57+
58+
Sending queries is async (non-blocking), so you can actually send multiple DNS queries in parallel.
59+
The mDNS hosts will respond to each DNS query message with a DNS response message. The order is not guaranteed.
60+
Sending queries uses a [Promise](https://github.com/reactphp/promise)-based interface that makes it easy to react to when a query is *fulfilled*
61+
(i.e. either successfully resolved or rejected with an error):
62+
63+
```php
64+
$resolver->lookup($hostname)->then(
65+
function ($ip) {
66+
// IP successfully resolved
67+
},
68+
function (Exception $e) {
69+
// an error occured while looking up the given hostname
70+
}
71+
});
72+
```
73+
74+
Please refer to the [DNS documentation](https://github.com/reactphp/dns#readme) for more details.
75+
3576
## Install
3677

3778
The recommended way to install this library is [through composer](http://getcomposer.org). [New to composer?](http://getcomposer.org/doc/00-intro.md)

0 commit comments

Comments
 (0)