示例#1
0
 /// <summary>
 /// Call to open the server and start listening for communication from IFTTT.
 /// </summary>
 public void OpenServer()
 {
     try
     {
         server      = new Crestron.SimplSharp.Net.Http.HttpServer(EthernetAdapterType.EthernetUnknownAdapter);
         server.Port = Port;
         CrestronConsole.PrintLine("IFTTT: Port #: " + Port);
         server.ServerName     = "IFTTT Server";
         server.OnHttpRequest += OnServerRequest;
         server.Open();
         CrestronConsole.PrintLine("IFTTT: Server started on port " + Port);
     }
     catch (Exception ex)
     {
         CrestronConsole.PrintLine("IFTTT: Error occurred while starting server.");
         CrestronConsole.PrintLine("IFTTT: " + ex.Message);
     }
     try
     {
         client = new HttpsClient();
         client.HostVerification = false;
         client.PeerVerification = false;
         client.KeepAlive        = false;
     }
     catch (Exception ex)
     {
         CrestronConsole.PrintLine("IFTTT: Error occurred while creating client.");
         CrestronConsole.PrintLine("IFTTT: " + ex.Message);
     }
 }
示例#2
0
 /// <summary>
 /// Call to close the server and stop listening for communication from IFTTT.
 /// </summary>
 public void CloseServer()
 {
     if (server != null)
     {
         server.Close();
         server.OnHttpRequest -= OnServerRequest;
         server.Dispose();
         server = null;
         CrestronConsole.PrintLine("IFTTT: Disposed of the server.");
     }
     if (client != null)
     {
         client.Dispose();
         client = null;
     }
 }
示例#3
0
        public void Start(int port)
        {
            // TEMP - this should be inserted by configuring class

            HttpServer                = new Crestron.SimplSharp.Net.Http.HttpServer();
            HttpServer.ServerName     = "Cisco API Server";
            HttpServer.KeepAlive      = true;
            HttpServer.Port           = port;
            HttpServer.OnHttpRequest += Server_Request;
            HttpServer.Open();

            CrestronEnvironment.ProgramStatusEventHandler += (a) =>
            {
                if (a == eProgramStatusEventType.Stopping)
                {
                    HttpServer.Close();
                    Debug.Console(1, "Shutting down HTTP Server on port {0}", HttpServer.Port);
                }
            };
        }