public void TestStartStop()
        {
            HttpListener listener = HttpListener.Create(IPAddress.Any, 8321);

            listener.LogWriter        = NullLogWriter.Instance;
            listener.RequestReceived += OnIncomingRequest;
            listener.Start(5);

            LaunchThreads(10, OnTestStartStop);
            Thread.Sleep(50);
            for (int i = 0; i < 50; ++i)
            {
                listener.Stop();
                listener.Start(1);
            }
            listener.Stop();

            foreach (WebClient client in _webClients)
            {
                client.Dispose();
            }

            // the aborting hangs, and I do not know why :/
            //foreach (Thread thread in _threads)
            //    thread.Abort();
        }
Exemple #2
0
 public HttpView(Field field)
 {
     _field    = field;
     _listener = HttpListener.Create(System.Net.IPAddress.Any, 8080);
     _listener.RequestReceived += OnRequest;
     _listener.Start(5);
 }
Exemple #3
0
        static void Main(string[] args)
        {
            HttpListener listener = HttpListener.Create(System.Net.IPAddress.Loopback, 9981);

            listener.RequestReceived += new EventHandler <RequestEventArgs>(listener_RequestReceived);
            listener.Start(5);

            bus.OnIncomingSerialLine += new IncomingSerialLineHandler(bus_OnIncomingSerialLine);

            Console.WriteLine("SerialServe is running, press Ctrl+C or close this window to stop the server.");
            Console.WriteLine();
            Console.WriteLine();
            var previousColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!      Warning     !!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            Console.WriteLine("!!!                                                                     !!!");
            Console.WriteLine("!!!    Browsing untrusted websites with the server running is unsafe!   !!!");
            Console.WriteLine("!!!                                                                     !!!");
            Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            Console.ForegroundColor = previousColor;

            while (true)
            {
                Thread.Sleep(9000000);
            }
        }
Exemple #4
0
        void init(int port)
        {
            if (mInitialed)
            {
                return;
            }

            Loom.Current.Initial();
            UtilsHelper.Init();

            UTNT.HttpServer.Utils.Instance.InternetCacheDir = UtilsHelper.TemporaryCachePath;
            //HttpServer.Utils.Instance.ApplicationDataDir = UtilsHelper.TemporaryCachePath;
            //HttpServer.Utils.Instance.LocalApplicationDataDir = UtilsHelper.TemporaryCachePath;

            AddEditableFileExtion(".txt");
            AddEditableFileExtion(".lua");
            AddEditableFileExtion(".xml");

            //HttpServer.Logging.LogFactory.Assign(new LogFactory());

            mServer.MaxContentSize     = 1024 * 1024 * 1024;
            mServer.ContentLengthLimit = 1024 * 1024 * 1024;

            var module = new FileModule();

            module.ContentTypes.Add("svg", new ContentTypeHeader("image/svg+xml"));
            //复杂的url必须先注册
            var loader = new UintyStreamAssetsLoader();

            loader.Add("/" + WWWCache.Instance.CustomPath, "/" + WWWCache.Instance.CustomPath, true);
            loader.Add("/", "/www/");

            module.Resources.Add(loader);

            mServer.Add(module);
            mServer.Add(new MultiPartDecoder());

            // use one http listener.
            mServer.Add(HttpListener.Create(System.Net.IPAddress.Any, port));
            mServer.Add(new SimpleRouter("/", "/index.html"));

            mServer.Add(new HandleRouter("/api/getrootdir", getRootDirHandler));
            mServer.Add(new HandleRouter("/api/getdir", getDirHandler));
            mServer.Add(new HandleRouter("/api/rename", renameHandler));
            mServer.Add(new HandleRouter("/api/addfold", addFoldHandler));
            mServer.Add(new HandleRouter("/api/addfile", addFileHandler));
            mServer.Add(new HandleRouter("/api/delete", deleteHandler));
            mServer.Add(new HandleRouter("/api/replacefile", repaceFileHandler));
            mServer.Add(new HandleRouter("/api/setcontent", setContentHandler));
            mServer.Add(new HandleRouter("/api/unzip", unzipHandler));
            mServer.Add(new HandleRouter("/api/getfile", getFileHandler));

            mServer.Add(new HandleRouter("/api/terminalinfo", getTerminalInfoHandler));

            mInitialed = true;
        }
        public void TestMultiThreaded()
        {
            HttpListener listener = HttpListener.Create(IPAddress.Any, 8321);

            listener.RequestReceived += OnIncomingRequest;
            listener.Start(20);
            LaunchThreads(50, OnTestMultiThreaded);

            // check if all was invoked and got result
            WaitOnThreadsToComplete();
            listener.Stop();
            Assert.Equal(_threadCount, _currentThreadCount);
        }
        public void TestSequential()
        {
            WebClient _client = new WebClient();

            for (int i = 0; i < 100; ++i)
            {
                _testEvent.Reset();
                HttpListener listener = HttpListener.Create(IPAddress.Any, 4324);
                listener.RequestReceived += OnIncomingRequest;
                listener.Start(5);
                _client.DownloadString("http://localhost:4324/welcome/to/tomorrow/");
                listener.Stop();
                Console.WriteLine("Round: " + i);
                Assert.True(_testEvent.WaitOne(5000, false));
            }
        }
Exemple #7
0
        private static void StartHTTP()
        {
            try
            {
                HttpServer.Logging.LogFactory.Assign(new HttpServer.Logging.ConsoleLogFactory(new HttpServer.Logging.LogFilter()));
                HTTP = new Server();
                HTTP.Add(HttpListener.Create(System.Net.IPAddress.Any, Settings.Get("HttpPort", 7780)));
                HTTP.Add(new HttpMod());
                HTTP.Start(32);

                LocalFileStorage = Settings.Get("LocalFiles", new Dictionary <string, string>());
            }
            catch (Exception ex)
            {
                Trace.WriteLine("HTTP Startup Error: " + ex.Message);
            }
        }
Exemple #8
0
        public WordLaunch(ServerInfo targetserver)
        {
            InitializeComponent();
            this.targetserver = targetserver;
            plugin            = new PluginRpc(targetserver.conn.URL);
            medsize           = plugin.GetMediumSize();

            txt_Content.NativeInterface.SetCodePage((int)Constants.SC_CP_UTF8);

            CategoryFullInfo[] cfi = targetserver.conn.GetCategories(0, targetserver.username, targetserver.password);
            foreach (CategoryFullInfo cf in cfi)
            {
                CheckBox cb = new CheckBox();
                cb.Name = "cb_" + cf.categoryName;
                cb.Text = cf.categoryName;
                cb.Tag  = cf;
                flow_Categories.Controls.Add(cb);
            }

            postResources = GetNextAvailableDir();
            Directory.CreateDirectory(postResources);

            var module = new FileModule();

            webserv = new Server();
            module.Resources.Add(new FileResources("/", postResources));
            webserv.Add(module);
            webserv.Add(new MultiPartDecoder());
            webserv.RequestReceived += new EventHandler <RequestEventArgs>(webserv_RequestReceived);

            // use one http listener.
            webserv.Add(HttpListener.Create(System.Net.IPAddress.Any, webservport));
            webserv.Start(5);

            // Find a valid post to use
            url = targetserver.conn.URL.Replace("xmlrpc.php", "?p=2147483646");
        }
Exemple #9
0
        public Striker2API.Usb usbToys;         // Striker II object

        private void run()
        {
            // create a new instance
            usbToys = new Striker2API.Usb();

            // init the Striker II, pass it the windows handle
            usbToys.Init(Process.GetCurrentProcess().MainWindowHandle);

            bool connected = usbToys.isUSBConnected();

            if (!connected)
            {
                Console.WriteLine("No device connected.");
            }


            HttpListener listener = HttpListener.Create(System.Net.IPAddress.Any, 8089);

            listener.RequestReceived += OnRequest;
            listener.Start(5);
            Console.WriteLine("Active on port 8089");

            Thread.Sleep(9000000);
        }
Exemple #10
0
 public void StartTutorial()
 {
     _listener = HttpListener.Create(IPAddress.Any, 8081);
     _listener.RequestReceived += OnRequest;
     _listener.Start(5);
 }