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

View File

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