private static string PrepareResponse(string message)
        {
            // Check the received message
            if (message == COMMAND_COUNT)
            {
                // Get the count from shared memory counter as the response
                long count = SharedMemoryCounter.Capture();

                // Return the count as string
                return(count.ToString());
            }

            // Return the received message if the command is not recognized
            return(string.Format("{0}{1}{2}", BOT, message, EOT));
        }
Exemple #2
0
        private void RunListener()
        {
            // Instantiate the Cassandra Counter class
            CassandraCounter cassandraCounter =
                new CassandraCounter("127.0.0.1", 9042, "url_shortcut", "urluser", "urluser");

            // Get the most recent count number from database
            long count = cassandraCounter.GetCounter();

            // Initialize the shared memory counter class with the count number
            SharedMemoryCounter.Initialize(count);

            // The port to which the server listens
            int port = 7079;

            // The maximum number of pending client connections
            int backlog = int.MaxValue;

            // Launch the server
            AsyncServerSocket.LaunchServer(port, backlog, ref this.running);
        }