diff --git a/README.md b/README.md index 7f68ddd..e869000 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ import ( func main() { client := palworldrcon.NewClient("127.0.0.1:25575", "password") + defer client.Close() info, err := client.Info() if err != nil { diff --git a/rcon.go b/rcon.go index 01b7e70..39556d5 100644 --- a/rcon.go +++ b/rcon.go @@ -31,6 +31,17 @@ func NewClient(address string, password string) *Client { return client } +// Close closes the connection to the RCON server. Calling any other method after closing will reopen the connection. +func (r *Client) Close() error { + if r.conn == nil { + return nil + } else { + err := r.conn.Close() + r.conn = nil + return err + } +} + func (r *Client) connect() error { if r.conn != nil { r.conn.Close()