Exemplo n.º 1
0
        public async void serve(string ip = "0.0.0.0", int port = 3000, int threads = 3)
        {
            IPAddress   address  = IPAddress.Parse(ip);
            TcpListener listener = new TcpListener(address, port);

            listener.Start();

            Console.WriteLine("server started on: " + ip + " and port " + port);
            Console.WriteLine(Environment.ProcessorCount + " is processsors count");

            ThreadPool.SetMinThreads(2, 2);
            ThreadPool.SetMaxThreads(threads, threads);

            KWorker resper = new KWorker();

            while (true)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(resper.Resp2), listener.AcceptTcpClient());
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var tst = new KWorker();

            tst.jfn();
            //return;



            Controller controller = new Controller();

            action dl = delegate(KClient client)
            {
                client.HTML("<h3>works!</h3><h1>Yra!!!</h1>");
            };

            controller.Get("/tost", dl);

            action dl2 = delegate(KClient client)
            {
                Console.WriteLine(client.RawText);
                client.HTML("<h5>some txt</h5>" +
                            "<div> werui</div>" +
                            "<button>click</button>");
                Console.WriteLine("ended test response create");
            };

            controller.Get("/test2", dl2);


            action dl3 = delegate(KClient client)
            {
                client.Json(new MyStruct("mnogo texta", 5));
            };

            controller.Get("/json", dl3);



            action dlwait = delegate(KClient client)
            {
                client.HTML("waited some time");
                Thread.Sleep(3000);
                Console.WriteLine("has waited");
            };

            controller.Get("/wait", dlwait);

            action postdel = delegate(KClient client)
            {
                Console.WriteLine("wertyu");
                Console.WriteLine(client.GetHeader("Content-Type"));
                JObject jobj = JObject.Parse(client.RawBody);
                client.PlainText(jobj["tkey"].ToString());
            };

            controller.Post("/tpost", postdel);


            controller.Get("/act", (action) delegate(KClient client)
            {
                Dictionary <string, string> dict = new Dictionary <string, string>();
                dict["name"]  = "poki";
                dict["birth"] = "12.03.2002";
                Console.WriteLine(client.RequestRoad());
                client.Json(dict);
            });


            Thread th = new Thread(test);

            th.Start();

            controller.serve();
        }