Centreon_EventLog_2_Syslog.SyslogServer.SendThread C# (CSharp) Method

SendThread() private method

Thread to send syslog event to TCP syslog server
private SendThread ( ) : void
return void
        private void SendThread()
        {
            do
            {
                // Send the object
                try
                {
                    String message = (String)SendQueue.Peek();
                    byte[] rawMsg = Encoding.Default.GetBytes(message);

                    IPAddress[] ServersAddress = Dns.GetHostAddresses(this._ServerAddress);

                    //String temp = ServersAddress.GetValue(0).ToString();

                    for (int i = 0; i < ServersAddress.Length; i++)
                    {
                        //Try to send message by TCP
                        TcpClient tcp;
                        NetworkStream flux;

                        tcp = new TcpClient(ServersAddress.GetValue(i).ToString(), this._ServerPort);
                        flux = tcp.GetStream();
                        flux.Write(rawMsg, 0, rawMsg.Length);
                        flux.Close();
                        tcp.Close();
                        tcp = null;
                        this._Debug.Write("Syslog Server", "Event send to: " + this._ServerAddress + " with message: " + message, DateTime.Now, 2);
                        SendQueue.Dequeue();

                    }
                }
                catch (Exception e)
                {
                }

                if (SendQueue.Count == 0) Thread.Sleep(100);

            } while (SendQueue.Count != 0);

            sending = false;
        }