func (cli *socketClient) OnStop() {
	if cli.conn != nil {
		cli.conn.Close()
	}
	cli.flushQueue()
	cli.flushTimer.Stop()
}
OnStop implements Service by closing connection and flushing all queues.
package abcicli
import (
	"bufio"
	"container/list"
	"errors"
	"fmt"
	"io"
	"net"
	"reflect"
	"time"
	"github.com/line/ostracon/abci/types"
	tmnet "github.com/line/ostracon/libs/net"
	"github.com/line/ostracon/libs/service"
	tmsync "github.com/line/ostracon/libs/sync"
	"github.com/line/ostracon/libs/timer"
)
const (
	reqQueueSize    = 256  
	flushThrottleMS = 20   
)
type socketClient struct {
	service.BaseService
	addr        string
	mustConnect bool
	conn        net.Conn
	reqQueue   chan *ReqRes
	flushTimer *timer.ThrottleTimer
	mtx     tmsync.Mutex
	err     error
	reqSent *list.List  
	globalCbMtx tmsync.Mutex
	globalCb    GlobalCallback
}
var _ Client = (*socketClient)(nil)
func NewSocketClient(addr string, mustConnect bool) Client {
	cli := &socketClient{
		reqQueue:    make(chan *ReqRes, reqQueueSize),
		flushTimer:  timer.NewThrottleTimer("socketClient", flushThrottleMS),
		mustConnect: mustConnect,
		addr:     addr,
		reqSent:  list.New(),
		globalCb: nil,
	}
	cli.BaseService = *service.NewBaseService(nil, "socketClient", cli)
	return cli
}
func (cli *socketClient) OnStart() error {
	var (
		err  error
		conn net.Conn
	)
	for {
		conn, err = tmnet.Connect(cli.addr)
		if err != nil {
			if cli.mustConnect {
				return err
			}
			cli.Logger.Error(fmt.Sprintf("abci.socketClient failed to connect to %v.  Retrying after %vs...",
				cli.addr, dialRetryIntervalSeconds), "err", err)
			time.Sleep(time.Second * dialRetryIntervalSeconds)
			continue
		}
		cli.conn = conn
		go cli.sendRequestsRoutine(conn)
		go cli.recvResponseRoutine(conn)
		return nil
	}
}