Skip to content

Commit 6b6d92c

Browse files
committed
bonjour: fix no messages received on Linux
UDP multicast on Linux is quite different from Windows. We have to allow all addresses for each network interface, otherwise we don't receive any data.
1 parent a1fcdc8 commit 6b6d92c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
66
## Unreleased
77
### Fixed
88
- Fix "Timed out while waiting for handshake" error
9+
- Fix not working on Linux without Avahi installed
910

1011
## 1.0.3 - 2019-03-25
1112
### Changed

src/dnssd/bonjour.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,17 @@ class BonjourClient extends events.EventEmitter implements dnssd.Client {
7979
* @param ifaceAddress the IP address
8080
*/
8181
private createClient(ifaceIndex: number, ifaceAddress: string): void {
82+
// On Windows, we need the full IP address as part of the multicast socket
83+
// interface or things don't work right. On Linux, we have to strip the
84+
// IP address or things don't work right.
85+
const iface = (os.platform() === 'win32') ? ifaceAddress : ifaceAddress.replace(/.*%/,'::%');
86+
8287
// work around bonjour issue where error is not handled
8388
new Promise<bonjour.Bonjour>((resolve, reject) => {
8489
const bClient = bonjour(<any> {
8590
type: 'udp6',
8691
ip: 'ff02::fb',
87-
interface: ifaceAddress
92+
interface: iface,
8893
});
8994
(<any>bClient)['iface'] = ifaceIndex;
9095
(<any> bClient)._server.mdns.on('ready', () => resolve(bClient));

0 commit comments

Comments
 (0)