Пример #1
0
        public void SecondBufferShouldNotFlushBeforeItemSize()  //first buffer failure test
        {
            var conobjBufferA = LineProtocolConfiguration.InitConfiguration();

            conobjBufferA.FlushBufferItemsSize       = 1;
            conobjBufferA.FlushBufferSeconds         = 300;
            conobjBufferA.FlushSecondBufferSeconds   = 50;
            conobjBufferA.FlushSecondBufferItemsSize = 42;
            InfluxCon(conobjBufferA, "DROP MEASUREMENT \"datameasurementE\"");
            InfluxCon(conobjBufferA, "DROP DATABASE " + conobjBufferA.DBName);  // dropping db so first buffer fail

            List <string> data = new List <string>();

            data.Add("datameasurementE,location=us-midwest temperature=32 1465839830100400200");

            var influxLib = new InfluxClient(conobjBufferA);

            influxLib.Enqueue(data, true);
            Thread.Sleep(1000); //wait before flush call and db creation so flush dnt pass to influx but to 2nd buffer
            InfluxCon(conobjBufferA, "CREATE DATABASE \"" + conobjBufferA.DBName + "\"");
            Thread.Sleep(2000); //wait for NW latency to Influx

            influxLib.Enqueue("datameasurementE,location=us-east temperature=15 1465839830100400203", false);


            Thread.Sleep(3000); //wait for 2nd buffer to flush

            JObject pobj    = JObject.Parse(InfluxCon(conobjBufferA, "SELECT * FROM \"datameasurementE\""));
            var     rows    = pobj.SelectTokens("['results'][0].['series'][0].['values']");
            var     inCount = rows.Children().Count();

            Assert.Equal(0, inCount);//Check if row count is now 4
        }
Пример #2
0
        public void FirstBufferShouldFlushAfterTimeInterval()
        {
            var conobj = LineProtocolConfiguration.InitConfiguration();

            conobj.FlushBufferItemsSize = 100;
            conobj.FlushBufferSeconds   = 1;
            //InfluxCon(conobj, "DELETE FROM \"datameasurementB\"");
            InfluxCon(conobj, "DROP MEASUREMENT \"datameasurementB\"");

            List <string> data = new List <string>();

            data.Add("datameasurementB,location=us-midwest temperature=82 1465839830100400200");

            var influxLib = new InfluxClient(conobj);

            influxLib.Enqueue(data, true);
            Thread.Sleep(2000); //wait for TIME flush & NW latency to Influx


            JObject pobj    = JObject.Parse(InfluxCon(conobj, "SELECT * FROM \"datameasurementB\""));
            var     rows    = pobj.SelectTokens("['results'][0].['series'][0].['values']");
            var     inCount = rows.Children().Count();

            Assert.Equal(1, inCount);//Check if row count is now 1
        }
Пример #3
0
        public void FirstBufferShouldNotFlushBeforeItemSize(bool useListEnqueue)
        {
            var conobj = LineProtocolConfiguration.InitConfiguration();

            conobj.FlushBufferItemsSize = 2;
            conobj.FlushBufferSeconds   = 300;
            //InfluxCon(conobj, "DELETE FROM \"datameasurementA\"");
            InfluxCon(conobj, "DROP MEASUREMENT \"datameasurementA\"");

            List <string> data = new List <string>();

            data.Add("datameasurementA,location=us-midwest temperature=82 1465839830100400200");

            var influxLib = new InfluxClient(conobj);

            if (useListEnqueue)
            {
                influxLib.Enqueue(data, true);
            }
            else
            {
                influxLib.Enqueue(data[0], true);
            }


            JObject pobj    = JObject.Parse(InfluxCon(conobj, "SELECT * FROM \"datameasurementA\""));
            var     rows    = pobj.SelectTokens("['results'][0].['series'][0].['values']");
            var     inCount = rows.Children().Count();

            Assert.Equal(0, inCount);//Check if row count is now 0
        }
Пример #4
0
        public void SecondBufferFlushTimeInterval(bool notFlushBeforeTimeInterval)  //first buffer failure test
        {
            var conobjBufferA = LineProtocolConfiguration.InitConfiguration();

            conobjBufferA.FlushBufferItemsSize       = 2;
            conobjBufferA.FlushBufferSeconds         = 300;
            conobjBufferA.FlushSecondBufferSeconds   = 5;
            conobjBufferA.FlushSecondBufferItemsSize = 5;
            //InfluxCon(conobjBufferA, "DELETE FROM \"datameasurementD\"");
            InfluxCon(conobjBufferA, "DROP MEASUREMENT \"datameasurementD\"");
            InfluxCon(conobjBufferA, "DROP DATABASE \"" + conobjBufferA.DBName + "\""); // dropping db so first buffer fail

            List <string> data = new List <string>();

            data.Add("datameasurementD,location=us-midwest temperature=82 1465839830100400200");
            data.Add("datameasurementD,location=us-east temperature=75 1465839830100400200");

            var influxLib = new InfluxClient(conobjBufferA);

            influxLib.Enqueue(data, true);
            Thread.Sleep(2000);
            InfluxCon(conobjBufferA, "CREATE DATABASE \"" + conobjBufferA.DBName + "\"");

            if (!notFlushBeforeTimeInterval)
            {
                Thread.Sleep((conobjBufferA.FlushSecondBufferSeconds + 1) * 1000); //wait for 2nd buffer to flush
            }

            JObject pobj    = JObject.Parse(InfluxCon(conobjBufferA, "SELECT * FROM \"datameasurementD\""));
            var     rows    = pobj.SelectTokens("['results'][0].['series'][0].['values']");
            var     inCount = rows.Children().Count();

            Assert.Equal((notFlushBeforeTimeInterval ? 0 : 2), inCount);//Check if row count is now 2
        }
Пример #5
0
        static async Task MainAsync(string[] args)
        {
            InfluxClassMap.Register <ComputerInfo>(cm =>
            {
                cm.SetMeasurementName(__measurementName);
                cm.MapTimestamp(x => x.Timestamp);
                cm.MapTag(x => x.Host, "host");
                cm.MapTag(x => x.Region, "region");
                cm.MapField(x => x.CPU, "cpu");
                cm.MapField(x => x.RAM, "ram");
            });
            const string influxHost   = "http://localhost:8086"; //"http://ipv4.fiddler:8086";
            const string databaseName = "mydb";

            var client = new InfluxClient(new Uri(influxHost));
            await client.CreateDatabaseAsync(databaseName);

            await Should_Write_Typed_Rows_To_Database(databaseName, client);
            await Should_Query_And_Display_Typed_Data(databaseName, client);
            await Should_Query_With_Parameters_And_Display_Typed_Data(databaseName, client);

            await client.DropDatabaseAsync(databaseName);

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Пример #6
0
        public void InfluxClientDisposeTestShouldPass()  //first buffer failure test
        {
            //for coverage
            InfluxClient ic = new InfluxClient(LineProtocolConfiguration.InitConfiguration());

            ic.Dispose();
        }
Пример #7
0
 public InfluxClientFixture()
 {
     Client = new InfluxClient(new Uri(InfluxHost), "root", "root");
     //Client.DefaultQueryOptions.UsePost = true;
     //Client.DefaultQueryOptions.Precision = TimestampPrecision.Microsecond;
     Client.CreateDatabaseAsync(DatabaseName).Wait();
 }
Пример #8
0
        /// <summary>
        /// Requests data each time the period specified by Interval has elapsed.
        /// </summary>
        public async override Task RequestData()
        {
            try {
                Google.Apis.Analytics.v3.Data.RealtimeData rt   = GetRequest.Execute();
                List <Dictionary <string, string> >        data = RealtimeData.GetData(rt);

                // Gets the date of the latest dataset in order to only add newer data.
                List <IInfluxSeries> last = await InfluxClient.QueryMultiSeriesAsync(DatabaseName, "SELECT last(*) FROM " + MeasurementName);

                DateTime now    = DateTime.UtcNow;
                DateTime New    = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0);
                DateTime?latest = last.FirstOrDefault()?.Entries[0].Time;

                List <InfluxDatapoint <InfluxValueField> > list = new List <InfluxDatapoint <InfluxValueField> >();
                foreach (Dictionary <string, string> dict in data)
                {
                    if (latest == null)
                    {
                        list.Add((InfluxDatapoint <InfluxValueField>) typeof(T).GetMethod("CreateInfluxDatapoint").Invoke(null, new object[] { MeasurementName, dict }));
                    }
                    else
                    {
                        // Necessary since nanoseconds cannot be set and will cause one date to be greater than the other although all (visible) parameters are equal.
                        if (New.Subtract(new TimeSpan(0, Convert.ToInt32(dict["rt:minutesAgo"]), 0)) > latest)
                        {
                            list.Add((InfluxDatapoint <InfluxValueField>) typeof(T).GetMethod("CreateInfluxDatapoint").Invoke(null, new object[] { MeasurementName, dict }));
                        }
                    }
                    await WriteToDatabase(list);
                }
            }
            catch (Exception ex) {
                Console.WriteLine("Error trying to request Google Analytics data: " + ex.Message);
            }
        }
        // Returns informationa about a toilet for the day
        public async Task <dynamic> GetSensorDailyStats(string toiletid, string datefrom, string dateto)
        {
            var client = new InfluxClient(new Uri("[REDACTED]"), "[REDACTED]", "[REDACTED]");

            // Get average users using a toilet
            var mean_users_result = await client.ReadAsync <SensorInfo>("SensorValues", String.Format("SELECT mean(CurrentUsers) AS \"result\" FROM \"{0}\" WHERE time > '{1}' AND time < '{2}'", toiletid, datefrom, dateto));

            // Get average gas
            var mean_gas_result = await client.ReadAsync <SensorInfo>("SensorValues", String.Format("SELECT mean(GasValue) AS \"result\" FROM \"{0}\" WHERE time > '{1}' AND time < '{2}'", toiletid, datefrom, dateto));

            // Get max gas
            var max_gas_result = await client.ReadAsync <SensorInfo>("SensorValues", String.Format("SELECT max(GasValue) AS \"result\" FROM \"{0}\" WHERE time > '{1}' AND time < '{2}'", toiletid, datefrom, dateto));

            // Get total requests
            var mean_request_result = await client.ReadAsync <SensorInfo>("SensorValues", String.Format("SELECT mean(Requests) AS \"result\" FROM \"{0}\" WHERE time > '{1}' AND time < '{2}'", toiletid, datefrom, dateto));

            var data = new
            {
                max_gas       = max_gas_result.Results[0].Series[0].Rows[0].result,
                mean_gas      = mean_gas_result.Results[0].Series[0].Rows[0].result,
                mean_requests = mean_request_result.Results[0].Series[0].Rows[0].result,
                mean_users    = mean_users_result.Results[0].Series[0].Rows[0].result
            };

            return(Newtonsoft.Json.JsonConvert.SerializeObject(data));
        }
Пример #10
0
        public static void Main(string[] args)
        {
            var client = new InfluxClient(new Uri("http://52.174.149.189:8086"), "root", "root");

            var from = new DateTime(2010, 1, 1, 1, 1, 1, DateTimeKind.Utc);
            var to   = new DateTime(2010, 1, 1, 1, 11, 1, DateTimeKind.Utc);
        }
Пример #11
0
        static void Main(string[] args)
        {
            try
            {
                var client = new InfluxClient(new Uri("http://localhost:8086"), "root", "root");

                //var from = DateTime.Parse( "21-12-2015 20:39:44" );
                //var to = DateTime.Parse( "23-12-2015 20:28:29" );

                var resultSet = client.ReadAsync <ComputerInfo>("mydb", $"SELECT * FROM computerInfo").Result;

                //var resultSet = client.ShowGrantsAsync( "root" ).Result;

                // resultSet will contain 1 result in the Results collection (or multiple if you execute multiple queries at once)
                var result = resultSet.Results[0];

                // result will contain 1 series in the Series collection (or potentially multiple if you specify a GROUP BY clause)
                var series = result.Series[0];

                foreach (var row in series.Rows)
                {
                    Console.WriteLine("CPU: " + row.CPU);
                    Console.WriteLine("RAM: " + row.RAM);
                    // ...
                }

                Console.WriteLine(resultSet);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #12
0
        public void test_pir_voltage_write()
        {
            SetupMocks();

            var influxClient = new InfluxClient(_mockConfig.Object, _mockLogger.Object);

            influxClient.WritePirVoltage("test1", "5677", 4.543f, DateTime.Now);
        }
Пример #13
0
        public void test_that_writes_work()
        {
            SetupMocks();

            var influxClient = new InfluxClient(_mockConfig.Object, _mockLogger.Object);

            influxClient.WritePirDetectEvent("test1", "5677", "front garden", DateTime.Now);
        }
Пример #14
0
        public MachineStatusRepositoryWithCache(InfluxClient client, string databaseName, TimeSpan cacheWriteInterval, ILogger logger = null) : base(logger)
        {
            repository = new MachineStatusRepository(client, databaseName);

            cacheWriteTimer          = new NonReentrantTimer(cacheWriteInterval.TotalMilliseconds);
            cacheWriteTimer.Elapsed += CacheWriteTimer_Elapsed;
            cacheWriteTimer.Start();
        }
Пример #15
0
 internal QueryResultIterator(HttpResponseMessage responseMessage, JsonStreamObjectIterator objectIterator, InfluxClient client, InfluxQueryOptions options, string db)
 {
     _responseMessage = responseMessage;
     _objectIterator  = objectIterator;
     _client          = client;
     _options         = options;
     _db = db;
 }
Пример #16
0
        public async void Save(string value, string measurementName)
        {
            string db   = AppSettings.InfluxDatabase;
            string host = AppSettings.InfluxHostName;

            var client = new InfluxClient(new Uri(host));

            await ShouldWriteTypedRowsToDatabase(db, client, measurementName, DataDeserialize(value));
        }
Пример #17
0
        /// <summary>
        /// Query the database and return the dataset async
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task <InfluxResultSet <DynamicInfluxRow> > SimpleQuery(string query)
        {
            InfluxClient client = new InfluxClient(new Uri(_InfluxHost), _Username, _Password);
            //Debug.Log("Querying Database with: " + query);
            InfluxResultSet <DynamicInfluxRow> resultSet = await client.ReadAsync <DynamicInfluxRow>(_Database, query);

            client.Dispose();
            return(resultSet);
        }
        public InfluxClientTest()
        {
            var executedPath      = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
            var executedDirectory = Path.GetDirectoryName(executedPath);
            var directoryInfo     = new DirectoryInfo(executedDirectory);
            var rootPath          = directoryInfo.Parent.Parent.Parent.FullName;

            client = new InfluxClient(Path.Combine(rootPath, "config.yml"));
        }
Пример #19
0
        private static async Task <InfluxResultSet <TInfluxRow> > CreateBasedOnInterfaceAsync <TInfluxRow, TTimestamp>(
            InfluxClient client,
            IEnumerable <QueryResult> queryResults,
            string db,
            bool allowMetadataQuerying,
            InfluxRowTypeInfo <TInfluxRow> propertyMap,
            InfluxQueryOptions options,
            CancellationToken cancellationToken = default)
            where TInfluxRow : IInfluxRow <TTimestamp>, new()
        {
            var timestampParser = client.TimestampParserRegistry.FindTimestampParserOrNull <TTimestamp>();

            // In this case, we will contruct objects based on the IInfluxRow interface
            Dictionary <int, InfluxResult <TInfluxRow> > results = new Dictionary <int, InfluxResult <TInfluxRow> >();

            foreach (var queryResult in queryResults)
            {
                foreach (var result in queryResult.Results)
                {
                    InfluxResult <TInfluxRow> existingResult;
                    if (!results.TryGetValue(result.StatementId, out existingResult))
                    {
                        existingResult = new InfluxResult <TInfluxRow>(result.StatementId, result.Error ?? (result.Series == null ? Errors.UnexpectedQueryResult : null));
                        results.Add(result.StatementId, existingResult);
                    }
                    else
                    {
                        existingResult.AppendErrorMessage(result.Error);
                    }

                    if (existingResult.Succeeded)
                    {
                        foreach (var series in result.Series)
                        {
                            var name = series.Name;

                            // create influx series
                            var tags = series.Tags?.ToDictionary(x => x.Key, x => x.Value == string.Empty ? null : (object)x.Value) ?? new Dictionary <string, object>();

                            // find or create influx serie
                            var influxSerie = existingResult.FindGroupInternal(name, tags, true);
                            if (influxSerie == null)
                            {
                                influxSerie = new InfluxSeries <TInfluxRow>(name, tags);
                                existingResult.Series.Add(influxSerie);
                            }

                            // add data to found series
                            await AddValuesToInfluxSeriesByInterfaceAsync <TInfluxRow, TTimestamp>(
                                influxSerie, series, client, db, allowMetadataQuerying, propertyMap, options, timestampParser, cancellationToken);
                        }
                    }
                }
            }

            return(new InfluxResultSet <TInfluxRow>(results.Values.ToList()));
        }
Пример #20
0
        protected MachineRepositoryBase(string ipaddress, string username, string password, string databaseName, TimeSpan timeOut, int port = 8086)
        {
            _ipaddress = ipaddress;
            _port      = port;
            var uri = new Uri($"http://{ipaddress}:{port}");

            _client         = new InfluxClient(uri, username, password);
            _client.Timeout = timeOut;
        }
        internal InfluxRowContent(InfluxClient client, bool isBasedOnInterface, IEnumerable dataPoints, Func <TInfluxRow, string> getMeasurementName, InfluxWriteOptions options)
        {
            _isBasedOnInterface = isBasedOnInterface;
            _dataPoints         = dataPoints;
            _getMeasurementName = getMeasurementName;
            _options            = options;
            _timestampParser    = client.TimestampParserRegistry.FindTimestampParserOrNull <TTimestamp>();

            Headers.ContentType = TextMediaType;
        }
    public async Task InfluxClient_Should_Get_All_Users()
    {
        //Arrange
        var client = new InfluxClient(new Uri("http://localhost:8086"));
        //Act
        var users = await client.ShowUsersAsync();

        //Assert
        //...verify expected results.
    }
        // Returns mean sensor values based on <datefrom>, <dateto> and <interval> inputs
        // <datefrom>, <dateto> : RFC3339 Date Format
        // <interval> : 15m - 15 minutes, 1d - 1 day etc.
        public async Task <dynamic> GetSensorHistory(string tablename, string datefrom, string dateto, string interval)
        {
            var client    = new InfluxClient(new Uri("[REDACTED]"), "[REDACTED]", "[REDACTED]");
            var resultSet = await client.ReadAsync <SensorInfo>("SensorValues", String.Format("SELECT mean(*) FROM \"{0}\" WHERE time > '{1}' AND time < '{2}' GROUP BY time({3})", tablename, datefrom, dateto, interval));

            if (resultSet.Results[0].Series.Count == 0)
            {
                return("{}");
            }
            return(Newtonsoft.Json.JsonConvert.SerializeObject(resultSet.Results[0].Series[0]));
        }
Пример #24
0
        public async Task Should_Login_As_User_And_Set_Password()
        {
            await _client.CreateUserAsync("at5User", "somePassword");

            await _client.SetPasswordAsync("at5User", "otherPassword");

            var at5UserClient = new InfluxClient(new Uri("http://localhost:8083"), "at5User", "otherPassword");

            // TODO: Some operations

            await _client.DropUserAsync("at5User");
        }
Пример #25
0
        private static InfluxResultSet <TInfluxRow> CreateBasedOnAttributes <TInfluxRow, TTimestamp>(
            InfluxClient client,
            IEnumerable <QueryResult> queryResults,
            InfluxQueryOptions options,
            InfluxRowTypeInfo <TInfluxRow> propertyMap)
            where TInfluxRow : new()
        {
            // Create type based on attributes
            Dictionary <int, InfluxResult <TInfluxRow> > results = new Dictionary <int, InfluxResult <TInfluxRow> >();
            var timestampParser = client.TimestampParserRegistry.FindTimestampParserOrNull <TTimestamp>();

            foreach (var queryResult in queryResults)
            {
                foreach (var result in queryResult.Results)
                {
                    InfluxResult <TInfluxRow> existingResult;
                    if (!results.TryGetValue(result.StatementId, out existingResult))
                    {
                        existingResult = new InfluxResult <TInfluxRow>(result.StatementId, result.Error ?? (result.Series == null ? Errors.UnexpectedQueryResult : null));
                        results.Add(result.StatementId, existingResult);
                    }
                    else
                    {
                        existingResult.AppendErrorMessage(result.Error);
                    }

                    // TODO: What if error message is given in following query?
                    if (existingResult.Succeeded)
                    {
                        foreach (var series in result.Series)
                        {
                            var name = series.Name;

                            // create new dictionary, with correct typing (we must potentially convert strings to enums, if the column being used in the GROUP BY is an enum)
                            var tags = CreateTagDictionaryFromSerieBasedOnAttributes(series, propertyMap.All);

                            // find or create influx serie
                            var influxSerie = existingResult.FindGroupInternal(name, tags, true);
                            if (influxSerie == null)
                            {
                                influxSerie = new InfluxSeries <TInfluxRow>(name, tags);
                                existingResult.Series.Add(influxSerie);
                            }

                            // add data to found serie
                            AddValuesToInfluxSeriesByAttributes <TInfluxRow, TTimestamp>(influxSerie, series, propertyMap, options, timestampParser);
                        }
                    }
                }
            }

            return(new InfluxResultSet <TInfluxRow>(results.Values.ToList()));
        }
Пример #26
0
        protected TestBase()
        {
            this.Client = new InfluxClient(new InfluxClientOptions(new []
            {
                new InfluxHost("SERVER_IP", 8086)
            })
            {
                UserName = "******",
                Password = "******"
            });

            this.Client.DeleteDatabaseAsync("test").Wait();
        }
Пример #27
0
        public InfluxStorage(Uri endpoint, string database, string username, string password, IConcurrencyControl concurrency, IKeyConverter <TKey> keyConverter)
        {
            _client   = new InfluxClient(endpoint, username, password);
            _database = database;

            _client.DefaultQueryOptions.Precision = TimestampPrecision.Nanosecond;
            _client.DefaultWriteOptions.Precision = TimestampPrecision.Nanosecond;

            _keyConverter = keyConverter;
            _cc           = concurrency;

            _defaultSelection = new[] { new StorageSelection <TKey, TEntry, IStorage <TKey, TEntry> >(this) };
        }
Пример #28
0
        private async Task <List <WaterInfo> > ShouldQueryTypedData(string db, InfluxClient client,
                                                                    string measurementName)
        {
            var resultSet = await client.ReadAsync <WaterInfo>(db, "SELECT * FROM " + measurementName);

            // resultSet will contain 1 result in the Results collection (or multiple if you execute multiple queries at once)
            var result = resultSet.Results[0];

            // result will contain 1 series in the Series collection (or potentially multiple if you specify a GROUP BY clause)
            var series = result.Series[0].Rows;

            return(series);
        }
Пример #29
0
 public void WriteMetrics/*<TInfluxRow>*/ (string measurement, DynamicInfluxRow props) //, IEnumerable<TInfluxRow> rows)
                                                                                       //where TInfluxRow : new()
 {
     lock (_syncObject)
     {
         using (var client = new InfluxClient(new Uri(Settings.DbAddress)))
         {
             var infos = new [] { props };
             client.WriteAsync(Settings.DbName, measurement, infos)
             .GetAwaiter()
             .GetResult();
         }
     }
 }
Пример #30
0
        static async Task <int> MainAsync(string[] args)
        {
            try
            {
                #region Test

                /*
                 * // WARNING: Remove or comment out this part for production.
                 * var testArgs = AppSettings.SensorListener.ExecutionParamsStringExample.Split(' ');
                 * args = testArgs;
                 */
                #endregion Test

                _parsedInputParams = CommandLineArgsParser.CommandLineArgsParser.ParseInputParams(args);
            }
            catch (Exception ex)
            {
                var errorMessage = "ERROR: execution params parsing failed.\r\n" + ex.Message;
                Console.WriteLine(errorMessage);

                return(1);
            }

            _measurementName = AppSettings.MeasurementNameBase + _parsedInputParams.TestId;

            _influxClient = new InfluxClient(new Uri(AppSettings.InfluxHost));

            // var databases = await _client.ShowDatabasesAsync();

            await _influxClient.CreateDatabaseAsync(AppSettings.InfluxDatabaseName); // Creates Influx database if not exist

            InitTimer(_parsedInputParams.ProgramExecutionTime);

            try
            {
                Console.WriteLine("Listening to port: {0}...", AppSettings.SensorListener.ListenPort);

                Thread receiveThread = new Thread(new ThreadStart(ReceiveMessage));
                receiveThread.Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                return(2);
            }

            return(0);
        }