Пример #1
0
        //internal WebSocketFrame(string textMessage)
        //    :this()
        public WebSocketFrame(Fin fin, Opcode opcode, PayLoadData payLoadData, bool mask = false)
        {
            Fin    = fin;
            Rsv2   = Rsv.Off;
            Rsv3   = Rsv.Off;
            Rsv4   = Rsv.Off;
            Opcode = opcode;

            var len = payLoadData.Length;

            if (len < 126)
            {
                PayloadLength         = (byte)len;
                ExtendedPayloadLength = new byte[0];
            }
            else if (len < 65536)
            {
                PayloadLength         = 126;
                ExtendedPayloadLength = ((ushort)len).InternalToByteArray(ByteOrder.Big);
            }
            else
            {
                PayloadLength         = 127;
                ExtendedPayloadLength = len.InternalToByteArray(ByteOrder.Big);
            }

            if (mask)
            {
                Mask = Mask.On;
            }
            else
            {
                Mask       = Mask.Off;
                MaskingKey = new byte[0];
            }

            PayloadData = payLoadData;
        }
Пример #2
0
 static PayLoadData()
 {
     Empty     = new PayLoadData();
     MaxLength = Int64.MaxValue;
 }
Пример #3
0
 internal static WebSocketFrame CreateCloseFrame(PayLoadData payLoadData, bool mask)
 {
     return(new WebSocketFrame(Fin.Final, Opcode.Close, payLoadData, false));
 }