private bool canSendAsCloseFrame(PayloadData data) { if (data.Length >= 2) { var code = Ext.To <ushort>(Ext.SubArray(data.ToBytes(), 0, 2), ByteOrder.BIG); if (code == (ushort)CloseStatusCode.NO_STATUS_CODE || code == (ushort)CloseStatusCode.ABNORMAL || code == (ushort)CloseStatusCode.HANDSHAKE_FAILURE) { return(false); } } return(true); }
public CloseEventArgs(PayloadData data) : base(Opcode.CLOSE, data) { _code = (ushort)CloseStatusCode.NO_STATUS_CODE; _reason = string.Empty; _wasClean = false; if (data.Length >= 2) { _code = Ext.To <ushort>(Ext.SubArray(data.ToBytes(), 0, 2), ByteOrder.BIG); } if (data.Length > 2) { var buffer = Ext.SubArray(data.ToBytes(), 2, (int)(data.Length - 2)); _reason = Encoding.UTF8.GetString(buffer); } }