typed message type + added CONTINUATION

This commit is contained in:
xdrm-brackets 2018-05-03 14:54:02 +02:00
parent 378534153c
commit 2d51ba1863
2 changed files with 11 additions and 8 deletions

View File

@ -23,7 +23,7 @@ func Read(socket net.Conn) (*T, error){
m.Final = bool( buffer[0] & 0x80 == 0x80 )
m.Type = byte( buffer[0] & 0x0f )
m.Type = Type( buffer[0] & 0x0f )
/* (3) Byte 2: Mask and Length[0] */
buffer = make([]byte, 1)
@ -103,7 +103,7 @@ func (m T) Send(socket net.Conn) error {
buffer := make([]byte, 0)
/* (1) Byte 0 : FIN + opcode */
buffer = append(buffer, 0x80 | TEXT )
buffer = append(buffer, 0x80 | byte(TEXT) )
/* (2) Get payload length */
if m.Size < 126 { // simple

View File

@ -2,18 +2,21 @@ package message
// Lists websocket message types
type Type byte
const (
TEXT = 0x1
BINARY = 0x2
CLOSE = 0x8
PING = 0x9
PONG = 0xa
CONTINUATION Type = 0x0
TEXT Type = 0x1
BINARY Type = 0x2
CLOSE Type = 0x8
PING Type = 0x9
PONG Type = 0xa
);
// Represents a websocket message
type T struct {
Type byte
Type Type
Data []byte
Size uint
Final bool