Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public MainWindow()
- {
- _listener = new HttpListener();
- _listener.Prefixes.Add("http://127.0.0.1:60024/");
- _listener.Start();
- _listener.BeginGetContext(new AsyncCallback(ProcessRequest), null);
- }
- private void ProcessRequest(IAsyncResult result)
- {
- HttpListenerContext context = _listener.EndGetContext(result);
- HttpListenerRequest request = context.Request;
- var sr = new StreamReader(request.InputStream);
- var command = sr.ReadToEnd();
- string responseString;
- if (command != "action=getCommand")
- {
- command = command.Split(new string[] { "data=" }, StringSplitOptions.None)[1];
- System.Diagnostics.Debug.WriteLine(command);
- responseString = "null";
- }
- else
- responseString = "API.getVolume()";
- HttpListenerResponse response = context.Response;
- response.ContentType = "text/html";
- response.Headers.Add("Access-Control-Allow-Origin", "*");
- byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
- response.ContentLength64 = buffer.Length;
- Stream output = response.OutputStream;
- output.Write(buffer, 0, buffer.Length);
- output.Close();
- _listener.BeginGetContext(new AsyncCallback(ProcessRequest), null);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement