예제 #1
0
        static void Main(string[] args)
        {
            try
            {
                WeatherStation root = new WeatherStation();
                bool           done = false;
                using (WoopsaServer woopsaServer = new WoopsaServer(root, 80))
                {
                    Console.WriteLine("Woopsa server listening on http://localhost:{0}{1}", woopsaServer.WebServer.Port, woopsaServer.RoutePrefix);
                    Console.WriteLine("Some examples of what you can do directly from your browser:");
                    Console.WriteLine(" * View the object hierarchy of the root object:");
                    Console.WriteLine("   http://localhost:{0}{1}meta/", woopsaServer.WebServer.Port, woopsaServer.RoutePrefix);
                    Console.WriteLine(" * Read the value of a property:");
                    Console.WriteLine("   http://localhost:{0}{1}read/Temperature", woopsaServer.WebServer.Port, woopsaServer.RoutePrefix);


                    Console.WriteLine();
                    Console.WriteLine("Commands : QUIT, AUTH, NOAUTH");
                    do
                    {
                        Console.Write(">");
                        switch (Console.ReadLine().ToUpper())
                        {
                        case "QUIT":
                            done = true;
                            break;

                        case "AUTH":
                            woopsaServer.Authenticator = new SimpleAuthenticator(
                                "WoopsaDemoServer",
                                (sender, e) => { e.IsAuthenticated = e.Username == "woopsa"; });
                            break;

                        case "NOAUTH":
                            woopsaServer.Authenticator = null;
                            break;

                        default:
                            Console.WriteLine("Invalid command");
                            break;
                        }
                    }while (!done);
                }
            }
            catch (SocketException e)
            {
                // A SocketException is caused by an application already listening on a port in most cases
                // Applications known to use port 80:
                //  - On Windows 10, IIS is on by default on some configurations. Disable it here:
                //    http://stackoverflow.com/questions/30758894/apache-server-xampp-doesnt-run-on-windows-10-port-80
                //  - IIS
                //  - Apache
                //  - Nginx
                //  - Skype
                Console.WriteLine("Error: Could not start Woopsa Server. Most likely because an application is already listening on port 80.");
                Console.WriteLine("Known culprits:");
                Console.WriteLine(" - On Windows 10, IIS is on by default on some configurations.");
                Console.WriteLine(" - Skype");
                Console.WriteLine(" - Apache, nginx, etc.");
                Console.WriteLine("SocketException: {0}", e.Message);
                Console.ReadLine();
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            try
            {
                WeatherStation root = new WeatherStation();
                bool done = false;
                using (WoopsaServer woopsaServer = new WoopsaServer(root, 80))
                {

                    Console.WriteLine("Woopsa server listening on http://localhost:{0}{1}", woopsaServer.WebServer.Port, woopsaServer.RoutePrefix);
                    Console.WriteLine("Some examples of what you can do directly from your browser:");
                    Console.WriteLine(" * View the object hierarchy of the root object:");
                    Console.WriteLine("   http://localhost:{0}{1}meta/", woopsaServer.WebServer.Port, woopsaServer.RoutePrefix);
                    Console.WriteLine(" * Read the value of a property:");
                    Console.WriteLine("   http://localhost:{0}{1}read/Temperature", woopsaServer.WebServer.Port, woopsaServer.RoutePrefix);

                    Console.WriteLine();
                    Console.WriteLine("Commands : QUIT, AUTH, NOAUTH");
                    do
                    {
                        Console.Write(">");
                        switch (Console.ReadLine().ToUpper())
                        {
                            case "QUIT":
                                done = true;
                                break;
                            case "AUTH":
                                woopsaServer.Authenticator = new SimpleAuthenticator(
                                    "WoopsaDemoServer",
                                    (sender, e) => { e.IsAuthenticated = e.Username == "woopsa"; });
                                break;
                            case "NOAUTH":
                                woopsaServer.Authenticator = null;
                                break;
                            default:
                                Console.WriteLine("Invalid command");
                                break;
                        }
                    }
                    while (!done);
                }
            }
            catch (SocketException e)
            {
                // A SocketException is caused by an application already listening on a port in most cases
                // Applications known to use port 80:
                //  - On Windows 10, IIS is on by default on some configurations. Disable it here:
                //    http://stackoverflow.com/questions/30758894/apache-server-xampp-doesnt-run-on-windows-10-port-80
                //  - IIS
                //  - Apache
                //  - Nginx
                //  - Skype
                Console.WriteLine("Error: Could not start Woopsa Server. Most likely because an application is already listening on port 80.");
                Console.WriteLine("Known culprits:");
                Console.WriteLine(" - On Windows 10, IIS is on by default on some configurations.");
                Console.WriteLine(" - Skype");
                Console.WriteLine(" - Apache, nginx, etc.");
                Console.WriteLine("SocketException: {0}", e.Message);
                Console.ReadLine();
            }
        }