private void InitWebServer(List<SerialPortTuple> serialPorts) { httpServer = new HttpServer(HTTP_SERVER_PORT); IAsyncAction asyncAction = Windows.System.Threading.ThreadPool.RunAsync( async (workItem) => { httpServer.StartServer(this, this, serialPorts); // test loop: while(true) { await Task.Delay(5000); // see https://blogs.windows.com/buildingapps/2015/11/23/demystifying-httpclient-apis-in-the-universal-windows-platform/ // cache is controlled by HTTP header, but we can also set it here: //var myFilter = new HttpBaseProtocolFilter(); //myFilter.CacheControl.ReadBehavior = HttpCacheReadBehavior.MostRecent; //using (HttpClient client = new HttpClient(myFilter)) // keep-alive by default using (HttpClient client = new HttpClient()) // keep-alive by default { try { // inside the same process isolation does not block access. Other processes on the same computer are blocked. // use another computer to hit this URL in the browser. while (true) // using keep-alive { await Task.Delay(5000); // alternative way: //Send the GET request //HttpResponseMessage httpResponse = await client.GetAsync(new Uri("http://localhost:" + HTTP_SERVER_PORT + "/DateTime")); //httpResponse.EnsureSuccessStatusCode(); //string response = await httpResponse.Content.ReadAsStringAsync(); string response = await client.GetStringAsync(new Uri("http://localhost:" + HTTP_SERVER_PORT + "/DateTime")); //string response = await client.GetStringAsync(new Uri("http://172.16.1.201:" + HTTP_SERVER_PORT + "/DateTime")); Debug.WriteLine("HttpClient: got response: " + response); } } catch (Exception exc) { // possibly a 404 Debug.WriteLine("Error: HttpClient: got " + exc); } } } }); }
public ASP(HttpServer s) { server = s; }
private void InitWebServer(List<SerialPortTuple> serialPorts) { httpServer = new HttpServer(HTTP_SERVER_PORT); IAsyncAction asyncAction = Windows.System.Threading.ThreadPool.RunAsync( async (workItem) => { httpServer.StartServer(this, this, serialPorts); // test loop: while (true) { await Task.Delay(5000); using (HttpClient client = new HttpClient()) { try { // inside the same process isolation does not block access. Other processes on the same computer are blocked. // use another computer to hit this URL in the browser: string response = await client.GetStringAsync(new Uri("http://localhost:" + HTTP_SERVER_PORT + "/robotUI.html")); //string response = await client.GetStringAsync(new Uri("http://172.16.1.201:" + HTTP_SERVER_PORT + "/robotUI.html")); Debug.WriteLine("HttpClient: got response: " + response); } catch (Exception exc) { // possibly a 404 Debug.WriteLine("Error: HttpClient: got " + exc); } } } }); }