Вот какой-то код: < /p>
Код: Выделить всё
return Task.Factory.StartNew(async () => {
if(first_ping_attempt) {
Serilog.Log.Information("First ping attempt...");
}
HttpClient http = new HttpClient();
var cancellation = new CancellationTokenSource(10000);
HttpStringContent content = new HttpStringContent(FormPingPacket(device_ID, deviceName));
content.Headers.ContentType = JSONMediaType;
try {
var response = await http.PostAsync(PingPostURI, content).AsTask(cancellation.Token).ConfigureAwait(false);
if(!response.IsSuccessStatusCode) {
Serilog.Log.Error(String.Format("Ping POST response status code {0}\n URL: {1}\n Data:\n{2}", response.StatusCode, PingPostURI, content.ToString()));
}
if(first_ping_attempt) {
Serilog.Log.Information($"POST status: {response.StatusCode}");
}
} catch(TaskCanceledException) {
Serilog.Log.Error("Ping POST Timeout");
} catch(Exception e) {
Serilog.Log.Logger.Error(e, $"SendPing: Exception from http.PostAsync: {e.GetType()}: {e.Message}\n URL: {PingPostURI}");
}
content = new HttpStringContent(FormVersionPutPacket());
content.Headers.ContentType = JSONMediaType;
cancellation = new CancellationTokenSource(10000);
try {
var response = await http.PutAsync(DevicePutURI(device_ID), content).AsTask(cancellation.Token).ConfigureAwait(false);
// We don't actually care about the response code other than for debugging
if(!response.IsSuccessStatusCode) {
Serilog.Log.Error(String.Format("Ping PUT response status code {0}\n URL: {1}", response.StatusCode, DevicePutURI(device_ID)));
}
if(first_ping_attempt) {
Serilog.Log.Information($"POST status: {response.StatusCode}");
}
} catch(TaskCanceledException) {
Serilog.Log.Error("Ping PUT Timeout");
} catch(Exception e) {
Serilog.Log.Logger.Error(e, $"SendPing: Exception from http.PutAsync: {e.GetType()}: {e.Message}\n URL: {DevicePutURI(device_ID)}");
}
if(first_ping_attempt) {
Serilog.Log.Information("First manager ping complete.");
first_ping_attempt = false;
}
});
}
Код: Выделить всё
172.18.0.141 6/12/2025 3:16:07 PM First ping attempt...
172.18.0.141 6/12/2025 3:17:07 PM First ping attempt...
172.18.0.141 6/12/2025 3:18:07 PM First ping attempt...
172.18.0.141 6/12/2025 3:19:07 PM First ping attempt...
172.18.0.141 6/12/2025 3:20:07 PM First ping attempt...
172.18.0.141 6/12/2025 3:21:07 PM First ping attempt...
172.18.0.141 6/12/2025 3:22:07 PM First ping attempt...
172.18.0.141 6/12/2025 3:23:07 PM First ping attempt...
172.18.0.141 6/12/2025 3:24:07 PM First ping attempt...
172.18.0.141 6/12/2025 3:25:07 PM First ping attempt...
172.18.0.141 6/12/2025 3:26:07 PM First ping attempt...
172.18.0.141 6/12/2025 3:27:07 PM First ping attempt...
Подробнее здесь: https://stackoverflow.com/questions/796 ... n-computer