diff --git a/utils/socket.go b/utils/socket.go index 2d01956..f9d6a9a 100644 --- a/utils/socket.go +++ b/utils/socket.go @@ -50,8 +50,7 @@ func WriteToClient(data string) error { _, err := client.Write([]byte(data + "\r\n")) if err != nil { log.Println("error in write data to client socket ", err) - client.Close() - client = nil + closeClient() } return err } @@ -71,6 +70,13 @@ func IsClientConnected() bool { return client != nil } +func closeClient() { + if client != nil { + client.Close() + client = nil + } +} + func StopSocketServer() { if IsClientConnected() { client.Close()