(addr string)
| 37 | } |
| 38 | |
| 39 | func (t *TCPClient) Connect(addr string) error { |
| 40 | t.Close() |
| 41 | conn, err := net.Dial("tcp", addr) |
| 42 | if err != nil { |
| 43 | return errors.Wrap(err, "dial tcp error") |
| 44 | } |
| 45 | t.lock.Lock() |
| 46 | defer t.lock.Unlock() |
| 47 | t.conn = conn |
| 48 | t.connected = true |
| 49 | return nil |
| 50 | } |
| 51 | |
| 52 | func (t *TCPClient) Write(buf []byte) error { |
| 53 | if conn := t.getConn(); conn != nil { |