[Test] public void SendMessage()
		{
			SyslogMessage msg = new SyslogMessage("localhost", "testing");
			SyslogUdpClient cl = new SyslogUdpClient();
            cl.Connect(IPAddress.Loopback);
			cl.Send(msg);
			cl.Close();
		}
        [Test] public void SendMessage()
        {
            SyslogMessage   msg = new SyslogMessage("localhost", "testing");
            SyslogUdpClient cl  = new SyslogUdpClient();

            cl.Connect(IPAddress.Loopback);
            cl.Send(msg);
            cl.Close();
        }
 public void SendMessageUsing()
 {
     SyslogMessage msg = new SyslogMessage("localhost", "testing");
     using (SyslogUdpClient cl = new SyslogUdpClient())
     {
         cl.Connect(IPAddress.Loopback);
         cl.Send(msg);
     }
 }
Beispiel #4
0
        private void btnSend_Click(object sender, System.EventArgs e)
        {
            if (ValidInput())
            {
                // Wait cursor
                using (new WaitCursor())

                    try
                    {
                        // Lookup server IP Address
                        IPHostEntry IPList = Dns.GetHostEntry(txtServer.Text);
                        if ((IPList == null) || (IPList.AddressList.Length == 0))
                        {
                            throw new Exception("Unable to resolve address for host " +
                                                txtServer.Text);
                        }

                        IPAddress destAddress = IPList.AddressList[0];

                        // Get our host name
                        string hostName = Dns.GetHostName();

                        // Create message
                        SyslogMessage msg = new SyslogMessage(hostName,
                                                              txtMessage.Text,
                                                              (SyslogMessage.FacilityCode)comFacility.SelectedItem,
                                                              (SyslogMessage.SeverityCode)comSeverity.SelectedItem,
                                                              DateTime.Now);

                        // Send message
                        using (SyslogClient client = new SyslogUdpClient())
                        {
                            client.Connect(destAddress, Convert.ToInt32(txtPort.Text));
                            client.Send(msg);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, "Unable to send message:\n" + ex.Message);
                    }
            }
        }
Beispiel #5
0
        [Test] public void TransferTest()
        {
            using (SyslogServer srv = new SyslogServer())
            {
                srv.SyslogMessageReceived += new SyslogServer.SyslogMessageDelegate
                                                 (OnSyslogMessageReceived);

                srv.Connect();

                _messageCount = 0;
                SyslogMessage msg = new SyslogMessage("localhost", MessageText);

                using (SyslogUdpClient cl = new SyslogUdpClient())
                {
                    cl.Connect(IPAddress.Loopback);

                    for (int i = 0; i < MessagesToSend; i++)
                    {
                        cl.Send(msg);
                        // Allow a small delay so not to overload
                        Thread.Sleep(10);
                    }
                }

                // Sleep until message counts are settled
                int prevCount = -1;
                int newCount  = 0;
                while (prevCount != newCount)
                {
                    Thread.Sleep(100);
                    lock (this)
                    {
                        prevCount = newCount;
                        newCount  = _messageCount;
                    }
                }

                Assert.AreEqual(MessagesToSend, _messageCount, "Messages received");
            }
        }
		[Test] public void TransferTest()
		{
			using (SyslogServer srv = new SyslogServer())
			{
				srv.SyslogMessageReceived += new SyslogServer.SyslogMessageDelegate
					(OnSyslogMessageReceived);

				srv.Connect();

				_messageCount = 0;
				SyslogMessage msg = new SyslogMessage("localhost", MessageText);

				using (SyslogUdpClient cl = new SyslogUdpClient())
				{
                    cl.Connect(IPAddress.Loopback);

					for (int i=0; i<MessagesToSend; i++)
					{
						cl.Send(msg);
						// Allow a small delay so not to overload
						Thread.Sleep(10);
					}
				}

				// Sleep until message counts are settled
				int prevCount = -1;
				int newCount = 0;
				while (prevCount != newCount)
				{
					Thread.Sleep(100);
					lock (this)
					{
						prevCount = newCount;
						newCount = _messageCount;
					}
				}

				Assert.AreEqual(MessagesToSend, _messageCount, "Messages received");
			}
		}