public void MulticastGroupTest() { using (SyslogMulticastReceiver target = new SyslogMulticastReceiver()) { target.MulticastGroup = new IPAddress(new byte[] { 236, 2, 6, 86 }); try { //Error expected target.MulticastGroup = new IPAddress(new byte[] { 192, 168, 1, 1 }); } catch { } } }
public void TestMulticast() { AutoResetEvent complete = new AutoResetEvent(false); using (SyslogMulticastReceiver target = new SyslogMulticastReceiver()) { target.Log = new SimpleLogImpl(new NullCollector()); target.MulticastGroup = new IPAddress(new byte[] { 236, 13, 2, 86 }); target.Start(); target.MessageReceived += delegate(object sender, SyslogMessageEventArgs e) { if (e.Message.MessageId == "UNIT_TEST") { complete.Set(); } }; target.ParseError += delegate { Assert.Fail("Error decoding Syslog message"); }; target.Error += delegate { Assert.Fail("Error in test object"); }; SyslogMessage msg = new SyslogMessage("localhost", SyslogFacility.Local0, SyslogSeverity.Notice, "Hello") { MessageId = "UNIT_TEST" }; byte[] payload = Encoding.UTF8.GetBytes(msg.ToRfc5424String()); using (UdpClient client = new UdpClient { MulticastLoopback = false }) { client.Connect(target.MulticastGroup, target.Port); client.Send(payload, payload.Length); } if (!complete.WaitOne(3000)) { Assert.Fail("Multicast listener didn't receive the Syslog datagram"); } } }