diff --git a/ws/message.go b/ws/message.go index 8ca95ea..e577eb7 100644 --- a/ws/message.go +++ b/ws/message.go @@ -153,6 +153,11 @@ func (m Message) Send(socket net.Conn) error { header := make([]byte, 0, maximumHeaderSize) + // fix size + if uint(len(m.Data)) <= m.Size { + m.Size = uint( len(m.Data) ) + } + /* (1) Byte 0 : FIN + opcode */ header = append(header, 0x80 | byte(TEXT) ) @@ -182,7 +187,7 @@ func (m Message) Send(socket net.Conn) error { /* (3) Build write buffer */ writeBuf := make([]byte, 0, len(header) + int(m.Size)) writeBuf = append(writeBuf, header...) - writeBuf = append(writeBuf, m.Data...) + writeBuf = append(writeBuf, m.Data[0:m.Size]...) /* (4) Send over socket */ _, err := socket.Write(writeBuf)