Hi,
I have a project where I want to send and receive information to an Api server in my own network.
This is the code on my meadow:
class TPProductieService
{
public TPProductieService()
{
PingHttpClientAsync().Wait();
}
private static async Task PingHttpClientAsync()
{
const string serverUri = "Https://192.168.182.3/";
var counter = 0;
int breedte = 220;
while (true)
{
counter++;
using (HttpClient client = new HttpClient())
{
client.Timeout = new TimeSpan(0, 1, 0);
//HttpRequestCachePolicy noCachePolicy =
//new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri(serverUri + "Productie/GetMeters/"+breedte),
Headers =
{
Connection = { "keep-alive"}
}
};
var response = await client.SendAsync(request);
Console.WriteLine("Response : " + await response.Content.ReadAsStringAsync() + " " + counter + " times");
response.Dispose();
request.Dispose();
}
Thread.Sleep(2000);
}
}
}
And this is the Api:
[System.Web.Http.Route("Productie/GetMeters/{breedte}")]
public async Task<IHttpActionResult> GetMeters(int breedte)
{
return Ok(breedte);
}
After repeating about 193 times, depending on the Tread.sleep time, the meadow just stops responding.
Does anyone know what I am doing wrong here?
Thanks in Advance,
Martijn.