Refactored IEventListener and IEventSink to handle garbage data according to configur...
[lwes-dotnet/github-mirror.git] / Org.Lwes / Listener / MulticastEventListener.cs
blob21e8a24e03b75484fc56aa83070384b21f16a653
1 namespace Org.Lwes.Listener
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Net;
7 using System.Net.Sockets;
8 using System.Text;
10 using Org.Lwes.DB;
11 using Org.Lwes.Properties;
13 /// <summary>
14 /// Implementation of the IEventListener for listening to multicast events.
15 /// </summary>
16 public sealed class MulticastEventListener : EventListenerBase
18 #region Methods
20 /// <summary>
21 /// Initializes the instance.
22 /// </summary>
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
30 , int multicastPort
31 , bool parallel
32 , ListenerGarbageHandling garbageHandling)
34 if (IsInitialized) throw new InvalidOperationException(Resources.Error_AlreadyInitialized);
36 base.Initialize(db, new IPEndPoint(multicastAddress, multicastPort), parallel, garbageHandling,
37 (s, e) =>
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));
47 else
49 s.Bind(new IPEndPoint(IPAddress.Any, e.Port));
50 s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership,
51 new MulticastOption(e.Address));
53 });
56 #endregion Methods