| OLD | NEW |
| 1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 library mdns.src.native_protocol_client; | 5 library mdns.src.native_protocol_client; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // Find all network interfaces with an IPv4 address. | 94 // Find all network interfaces with an IPv4 address. |
| 95 var interfaces = | 95 var interfaces = |
| 96 await NetworkInterface.list(type: InternetAddressType.IP_V4); | 96 await NetworkInterface.list(type: InternetAddressType.IP_V4); |
| 97 for (NetworkInterface interface in interfaces) { | 97 for (NetworkInterface interface in interfaces) { |
| 98 // Create a socket for sending on each adapter. | 98 // Create a socket for sending on each adapter. |
| 99 var socket = await RawDatagramSocket.bind( | 99 var socket = await RawDatagramSocket.bind( |
| 100 interface.addresses[0], mDnsPort, reuseAddress: true); | 100 interface.addresses[0], mDnsPort, reuseAddress: true); |
| 101 _sockets.add(socket); | 101 _sockets.add(socket); |
| 102 | 102 |
| 103 // Join multicast on this interface. | 103 // Join multicast on this interface. |
| 104 _incoming.joinMulticast(mDnsAddress, interface); | 104 (_incoming as dynamic).joinMulticast(mDnsAddress, interface); |
| 105 } | 105 } |
| 106 _incoming.listen(_handleIncoming); | 106 _incoming.listen(_handleIncoming); |
| 107 | 107 |
| 108 _starting = false; | 108 _starting = false; |
| 109 _started = true; | 109 _started = true; |
| 110 } | 110 } |
| 111 | 111 |
| 112 void stop() { | 112 void stop() { |
| 113 if (!_started) return; | 113 if (!_started) return; |
| 114 if (_starting) { | 114 if (_starting) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 if (event == RawSocketEvent.READ) { | 158 if (event == RawSocketEvent.READ) { |
| 159 Datagram datagram = _incoming.receive(); | 159 Datagram datagram = _incoming.receive(); |
| 160 List<ResourceRecord> response = decodeMDnsResponse(datagram.data); | 160 List<ResourceRecord> response = decodeMDnsResponse(datagram.data); |
| 161 if (response != null) { | 161 if (response != null) { |
| 162 cache.updateRecords(response); | 162 cache.updateRecords(response); |
| 163 _resolver.handleResponse(response); | 163 _resolver.handleResponse(response); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 } | 167 } |
| OLD | NEW |