コード例 #1
0
        public void run()
        {
            // configure http server but do not start running yet
            Servers.MinimalHTTPServer.ServerConfiguration config = new Servers.MinimalHTTPServer.ServerConfiguration();
            Servers.MinimalHTTPServer.Server server = new Servers.MinimalHTTPServer.Server(config);
            server.ServerNotify += server_ServerNotify;
            server.addHTTPResponsibility(new ElseResponsibility());
            server.addHTTPResponsibility(new RunningResponsibility());

            // configure web socket server but do not start running
            Servers.MinimalWebSocketServer.ServerConfiguration webSocketconfig = new Servers.MinimalWebSocketServer.ServerConfiguration();
            webSocketconfig.bufferSize = 100;
            Servers.MinimalWebSocketServer.Server webSocketServer = new Servers.MinimalWebSocketServer.Server(webSocketconfig);
            webSocketServer.ServerNotify += server_ServerNotify;

            DataSources dataSources = new DataSources();
            VesselChangeDetector vesselChangeDetector = new VesselChangeDetector(false);
            IKSPAPI kspAPI = new DummyKSPAPI(JSONFormatterProvider.Instance, vesselChangeDetector, config);

            //webSocketServer.addWebSocketService("/server", new KSPWebSocketService(kspAPI,));
            //webSocketServer.subscribeToHTTPForStealing(server);

            // start the HTTP server
            //server.startServing();
            //Console.Read();
            //server.stopServing();
        }
コード例 #2
0
        public void run()
        {
            // configure http server but do not start running yet
            Servers.MinimalHTTPServer.ServerConfiguration config = new Servers.MinimalHTTPServer.ServerConfiguration();
            Servers.MinimalHTTPServer.Server server = new Servers.MinimalHTTPServer.Server(config);
            server.ServerNotify += server_ServerNotify;
            server.addHTTPResponsibility(new ElseResponsibility());
            server.addHTTPResponsibility(new RunningResponsibility());

            // configure web socket server but do not start running
            Servers.MinimalWebSocketServer.ServerConfiguration webSocketconfig = new Servers.MinimalWebSocketServer.ServerConfiguration();
            webSocketconfig.bufferSize = 100;
            Servers.MinimalWebSocketServer.Server webSocketServer = new Servers.MinimalWebSocketServer.Server(webSocketconfig);
            webSocketServer.ServerNotify += server_ServerNotify;
            webSocketServer.addWebSocketService("/server", new WebSocketEchoService());
            webSocketServer.subscribeToHTTPForStealing(server);

            // start the HTTP server
            server.startServing();
            Console.Read();
            server.stopServing();
        }
コード例 #3
0
 private static void stopDataLink()
 {
     if (server != null)
     {
         PluginLogger.print("Telemachus data link shutting down.");
         server.stopServing();
         server = null;
         webSocketServer.stopServing();
         webSocketServer = null;
     }
 }
コード例 #4
0
        private static void startDataLink()
        {
            if (server == null)
            {
                try
                {
                    PluginLogger.print("Telemachus data link starting");

                    readConfiguration();

                    server = new Server(serverConfig);
                    server.ServerNotify += HTTPServerNotify;
                    server.addHTTPResponsibility(new ElseResponsibility());
                    ioPageResponsibility = new IOPageResponsibility();
                    server.addHTTPResponsibility(ioPageResponsibility);

                    vesselChangeDetector = new VesselChangeDetector();

                    dataLinkResponsibility = new DataLinkResponsibility(serverConfig, new KSPAPI(JSONFormatterProvider.Instance, vesselChangeDetector, serverConfig));
                    server.addHTTPResponsibility(dataLinkResponsibility);

                    Servers.MinimalWebSocketServer.ServerConfiguration webSocketconfig = new Servers.MinimalWebSocketServer.ServerConfiguration();
                    webSocketconfig.bufferSize = 300;
                    webSocketServer = new Servers.MinimalWebSocketServer.Server(webSocketconfig);
                    webSocketServer.ServerNotify += WebSocketServerNotify;
                    kspWebSocketService = new KSPWebSocketService(new KSPAPI(JSONFormatterProvider.Instance, vesselChangeDetector, serverConfig));
                    webSocketServer.addWebSocketService("/datalink", kspWebSocketService);
                    webSocketServer.subscribeToHTTPForStealing(server);

                    server.startServing();

                    PluginLogger.print("Telemachus data link listening for requests on the following addresses: ("
                        + server.getIPsAsString() +
                        "). Try putting them into your web browser, some of them might not work.");
                }
                catch (Exception e)
                {
                    PluginLogger.print(e.Message);
                    PluginLogger.print(e.StackTrace);
                }
            }
        }