1
namespace Org
.Lwes
.Listener
4 using System
.Collections
.Generic
;
7 using System
.Net
.Sockets
;
11 using Org
.Lwes
.Properties
;
14 /// Implementation of the IEventListener for listening to multicast events.
16 public sealed class MulticastEventListener
: EventListenerBase
21 /// Initializes the instance.
23 /// <param name="db"></param>
24 /// <param name="multicastAddress"></param>
25 /// <param name="multicastPort"></param>
26 /// <param name="parallel"></param>
27 /// <param name="garbageHandling"></param>
28 public void Initialize(IEventTemplateDB db
29 , IPAddress multicastAddress
32 , ListenerGarbageHandling garbageHandling
)
34 if (IsInitialized
) throw new InvalidOperationException(Resources
.Error_AlreadyInitialized
);
36 base.Initialize(db
, new IPEndPoint(multicastAddress
, multicastPort
), parallel
, garbageHandling
,
39 s
.SetSocketOption(SocketOptionLevel
.Udp
, SocketOptionName
.NoDelay
, 1);
40 s
.SetSocketOption(SocketOptionLevel
.Socket
, SocketOptionName
.ReuseAddress
, 1);
41 if (e
.AddressFamily
== AddressFamily
.InterNetworkV6
)
43 s
.Bind(new IPEndPoint(IPAddress
.IPv6Any
, e
.Port
));
44 s
.SetSocketOption(SocketOptionLevel
.IPv6
, SocketOptionName
.AddMembership
,
45 new IPv6MulticastOption(e
.Address
));
49 s
.Bind(new IPEndPoint(IPAddress
.Any
, e
.Port
));
50 s
.SetSocketOption(SocketOptionLevel
.IP
, SocketOptionName
.AddMembership
,
51 new MulticastOption(e
.Address
));