From 2900409465d29bfb287a367fbc23dcf8e8f11b82 Mon Sep 17 00:00:00 2001 From: w1ndyb0y Date: Wed, 23 Dec 2020 14:39:57 +0800 Subject: [PATCH] client close --- utils/socket.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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()