You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,47 @@ $loop->run();
32
32
33
33
See also the [examples](examples).
34
34
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
+
35
76
## Install
36
77
37
78
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