예제 #1
0
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            Console.WriteLine("POST request: {0}", p.http_url);
            string data = inputData.ReadToEnd();

            p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("<a href=/test>return</a><p>");
            p.outputStream.WriteLine("postbody: <pre>{0}</pre>", data);
        }
예제 #2
0
        public override void handleGETRequest(HttpProcessor p)
        {
            Console.WriteLine("request: {0}", p.http_url);
            p.writeSuccess();
            p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
            p.outputStream.WriteLine("url : {0}", p.http_url + "</br>");

            //p.outputStream.WriteLine("<form method=post action=/form>");
            //p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
            //p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
            //p.outputStream.WriteLine("</form>");

            string[] pathArr = p.http_url.Split('/');
            string reqMethod = pathArr[1];

            string root = Path.Combine(Environment.GetEnvironmentVariable("RoleRoot") + @"\", @"approot\");
            //string root = Path.Combine(Environment.GetEnvironmentVariable("RoleRoot") );

            Microsoft.WindowsAzure.ServiceRuntime.LocalResource locRes;
            locRes = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetLocalResource("localStorage");
            string localStoragePath = string.Format(locRes.RootPath);

            if (reqMethod == "list")
            {

                p.outputStream.WriteLine("root is :" + root + "</br>");//msgln = "root is :" + root;
                var files = Directory.GetFiles(root);
                var dirs = Directory.GetDirectories(root);

                foreach (string v in dirs)
                {
                    var d = v;
                    p.outputStream.WriteLine(string.Format("<a  href=\"/{0}\">{0}</a> (dir) ", d) + "</br>");//msgln = string.Format("<a  href=\"/{0}\">{0}</a> (dir) ", d);
                }

                foreach (string v in files)
                {
                    FileInfo fin = new FileInfo(v);

                    var f = fin.Name;
                    p.outputStream.WriteLine(string.Format("<a href=\"/{0}\">{0}</a> (file) {1}", f, fin.Length) + "</br>");//msgln = string.Format("<a href=\"/{0}\">{0}</a> (file) {1}", f, fin.Length);
                }

                p.outputStream.WriteLine("list dir :" + localStoragePath + "</br>");//msgln = "list dir :" + localStoragePath;

                files = Directory.GetFiles(localStoragePath);
                dirs = Directory.GetDirectories(localStoragePath);

                foreach (string v in dirs)
                {
                    var d = v;
                    p.outputStream.WriteLine(string.Format("<a  href=\"/{0}\">{0}</a> (dir) ", d) + "</br>");//msgln = string.Format("<a  href=\"/{0}\">{0}</a> (dir) ", d);
                }

                foreach (string v in files)
                {

                    FileInfo fin = new FileInfo(v);

                    var f = fin.Name;
                    p.outputStream.WriteLine(string.Format("<a href=\"" + localStoragePath + "{0}\">{0}</a> (file) {1}", f, fin.Length) + "</br>");//msgln = string.Format("<a href=\"/{0}\">{0}</a> (file) {1}", f, fin.Length);
                }

            }
            else if (reqMethod == "recVid")
            {
                p.outputStream.WriteLine("start record to " + localStoragePath + "</br>");
                Class1.vlcSave(localStoragePath, root);
            }
            else if (reqMethod == "loadFile")
            {
                //socket.Client.Send(File.ReadAllBytes(
            }
        }
예제 #3
0
 public abstract void handlePOSTRequest(HttpProcessor p, StreamReader inputData);
예제 #4
0
 public void listen()
 {
     listener = new TcpListener(IPAddress.Any, port);
     listener.Start();
     while (is_active)
     {
         TcpClient s = listener.AcceptTcpClient();
         HttpProcessor processor = new HttpProcessor(s, this);
         Thread thread = new Thread(new ThreadStart(processor.process));
         thread.Start();
         Thread.Sleep(1);
     }
 }
예제 #5
0
 public abstract void handleGETRequest(HttpProcessor p);