diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2021-08-07 16:49:12 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2021-08-07 16:49:12 -0700 |
| commit | 9d41bcdf29778eab3253f8e31670baf64ad389bf (patch) | |
| tree | 9f123786b69bb3ee91326ec15f37bad40e71aa1c /hotline/client.go | |
| parent | eabc4b6cacc4749db226af272e71fcff1556f433 (diff) | |
Add keepalive to Client
Diffstat (limited to 'hotline/client.go')
| -rw-r--r-- | hotline/client.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/hotline/client.go b/hotline/client.go index 6aad5a1..493d59e 100644 --- a/hotline/client.go +++ b/hotline/client.go @@ -199,6 +199,12 @@ var clientHandlers = map[uint16]clientTHandler{ Name: "tranServerMsg", Handler: handleTranServerMsg, }, + tranKeepAlive: clientTransaction{ + Name: "tranKeepAlive", + Handler: func(client *Client, transaction *Transaction) (t []Transaction, err error) { + return t, err + }, + }, } func handleTranServerMsg(c *Client, t *Transaction) (res []Transaction, err error) { @@ -562,9 +568,20 @@ func (c *Client) JoinServer(address, login, passwd string) error { return err } + // start keepalive go routine + go func() { _ = c.keepalive() }() + return nil } +func (c *Client) keepalive() error { + for { + time.Sleep(300 * time.Second) + _ = c.Send(*NewTransaction(tranKeepAlive, nil)) + c.Logger.Infow("Sent keepalive ping") + } +} + // connect establishes a connection with a Server by sending handshake sequence func (c *Client) connect(address string) error { var err error |