diff --git a/tcp-connection.go b/tcp-connection.go index dc7d962..797313d 100644 --- a/tcp-connection.go +++ b/tcp-connection.go @@ -65,11 +65,13 @@ func NewConnection(address string) *Connection { } func SendFrame(conn net.Conn, data *FrameWithPayload) error { - err := binary.Write(conn, binary.LittleEndian, data.Frame) + w := bufio.NewWriter(conn) + err := binary.Write(w, binary.LittleEndian, data.Frame) if err != nil { return err } - _, err = conn.Write(data.Payload) + _, err = w.Write(data.Payload) + w.Flush() return err } @@ -102,6 +104,7 @@ func (c *Connection) Call(msg FrameType, data []byte) (*FrameWithPayload, error) } defer conn.Close() + defer close(ch) select { case ret := <-ch: