Skip to content

Commit

Permalink
Changed beacon receiving to work in unix
Browse files Browse the repository at this point in the history
Because windows and unix differ in how they handle broadcast addressing
this needs to be platform specific.  On windows any interface can
recieve broadcast by requesting to enable broadcast on the socket. On
linux to recieve broadcast you must bind to the broadcast address
specifically. Verfied using Ubuntu-16.04 mono-5.02.
  • Loading branch information
Wraith2 committed Aug 13, 2017
1 parent 9e1a9af commit 17194bc
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/NetMQ/NetMQBeacon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using JetBrains.Annotations;
using NetMQ.Sockets;
using System.Runtime.InteropServices;

namespace NetMQ
{
Expand Down Expand Up @@ -105,8 +106,25 @@ private void Configure([NotNull] string interfaceName, int port)
{
if (interfaceAddress == null || @interface.Address.Equals(interfaceAddress))
{
sendTo = @interface.BroadcastAddress;
bindTo = @interface.Address;
// because windows and unix differ in how they handle broadcast addressing this needs to be platform specific
// on windows any interface can recieve broadcast by requesting to enable broadcast on the socket
// on linux to recieve broadcast you must bind to the broadcast address specifically
//bindTo = @interface.Address;
sendTo = @interface.BroadcastAddress;
#if NET35 || NET40
if (Environment.OSVersion.Platform==PlatformID.Unix)
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
#endif
{
bindTo = @interface.BroadcastAddress;
}
else
{
bindTo = @interface.Address;
}
sendTo = @interface.BroadcastAddress;

break;
}
}
Expand Down Expand Up @@ -239,7 +257,7 @@ private NetMQFrame ReceiveUdpFrame(out string peerName)
}
}

#endregion
#endregion

private readonly NetMQActor m_actor;

Expand Down

0 comments on commit 17194bc

Please sign in to comment.