diff --git a/Example1/AudioStreamer.cs b/Example1/AudioStreamer.cs index d9994cfd..ead59406 100644 --- a/Example1/AudioStreamer.cs +++ b/Example1/AudioStreamer.cs @@ -85,11 +85,11 @@ namespace Example1 { switch (e.Type) { - case Opcode.TEXT: + case Opcode.Text: var msg = parseTextMessage(e.Data); _msgQ.Enqueue(msg); break; - case Opcode.BINARY: + case Opcode.Binary: var audioMsg = parseAudioMessage(e.RawData); if (audioMsg.user_id == _user_id) goto default; if (_audioBox.ContainsKey(audioMsg.user_id)) diff --git a/README.md b/README.md index 53bdf84d..0f21a886 100644 --- a/README.md +++ b/README.md @@ -126,19 +126,19 @@ ws.OnMessage += (sender, e) => { `e` has passed as a `WebSocketSharp.MessageEventArgs`. -`e.Type` property returns either `WebSocketSharp.Opcode.TEXT` or `WebSocketSharp.Opcode.BINARY` that represents the type of the received message. So by checking it, you determine which item you should use. +`e.Type` property returns either `WebSocketSharp.Opcode.Text` or `WebSocketSharp.Opcode.Binary` that represents the type of the received message. So by checking it, you determine which item you should use. -If `e.Type` is `Opcode.TEXT`, you should use `e.Data` property (returns a `string`) that represents the received **Text** message. +If `e.Type` is `Opcode.Text`, you should use `e.Data` property (returns a `string`) that represents the received **Text** message. -Or if `e.Type` is `Opcode.BINARY`, you should use `e.RawData` property (returns a `byte []`) that represents the received **Binary** message. +Or if `e.Type` is `Opcode.Binary`, you should use `e.RawData` property (returns a `byte []`) that represents the received **Binary** message. ```cs -if (e.Type == Opcode.TEXT) { +if (e.Type == Opcode.Text) { // Do something with e.Data return; } -if (e.Type == Opcode.BINARY) { +if (e.Type == Opcode.Binary) { // Do something with e.RawData return; } diff --git a/websocket-sharp/MessageEventArgs.cs b/websocket-sharp/MessageEventArgs.cs index 404378d5..f61f8a2e 100644 --- a/websocket-sharp/MessageEventArgs.cs +++ b/websocket-sharp/MessageEventArgs.cs @@ -117,7 +117,7 @@ namespace WebSocketSharp { return data.LongLength == 0 ? String.Empty - : opcode == Opcode.TEXT + : opcode == Opcode.Text ? Encoding.UTF8.GetString (data) : opcode.ToString (); } diff --git a/websocket-sharp/Opcode.cs b/websocket-sharp/Opcode.cs index b3ca4fc9..157395d8 100644 --- a/websocket-sharp/Opcode.cs +++ b/websocket-sharp/Opcode.cs @@ -4,8 +4,8 @@ * * The MIT License * - * Copyright (c) 2012-2013 sta.blockhead - * + * Copyright (c) 2012-2014 sta.blockhead + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights @@ -15,7 +15,7 @@ * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -28,40 +28,46 @@ using System; -namespace WebSocketSharp { - +namespace WebSocketSharp +{ /// - /// Contains the values of the opcodes that denotes the frame type of the WebSocket frame. + /// Contains the values of the opcode that indicates the type of a WebSocket frame. /// /// - /// The Opcode enumeration contains the values of the opcodes defined in - /// RFC 6455 for the WebSocket protocol. + /// The values of the opcode are defined in + /// Section 5.2 of RFC 6455. /// public enum Opcode : byte { /// - /// Equivalent to numeric value 0. Indicates a continuation frame. + /// Equivalent to numeric value 0. + /// Indicates a continuation frame. /// - CONT = 0x0, + Cont = 0x0, /// - /// Equivalent to numeric value 1. Indicates a text frame. + /// Equivalent to numeric value 1. + /// Indicates a text frame. /// - TEXT = 0x1, + Text = 0x1, /// - /// Equivalent to numeric value 2. Indicates a binary frame. + /// Equivalent to numeric value 2. + /// Indicates a binary frame. /// - BINARY = 0x2, + Binary = 0x2, /// - /// Equivalent to numeric value 8. Indicates a connection close frame. + /// Equivalent to numeric value 8. + /// Indicates a connection close frame. /// - CLOSE = 0x8, + Close = 0x8, /// - /// Equivalent to numeric value 9. Indicates a ping frame. + /// Equivalent to numeric value 9. + /// Indicates a ping frame. /// - PING = 0x9, + Ping = 0x9, /// - /// Equivalent to numeric value 10. Indicates a pong frame. + /// Equivalent to numeric value 10. + /// Indicates a pong frame. /// - PONG = 0xa + Pong = 0xa } } diff --git a/websocket-sharp/Server/WebSocketServiceManager.cs b/websocket-sharp/Server/WebSocketServiceManager.cs index 65c50c36..61fb2eed 100644 --- a/websocket-sharp/Server/WebSocketServiceManager.cs +++ b/websocket-sharp/Server/WebSocketServiceManager.cs @@ -364,9 +364,9 @@ namespace WebSocketSharp.Server } if (data.LongLength <= WebSocket.FragmentLength) - broadcast (Opcode.BINARY, data, null); + broadcast (Opcode.Binary, data, null); else - broadcast (Opcode.BINARY, new MemoryStream (data), null); + broadcast (Opcode.Binary, new MemoryStream (data), null); } /// @@ -386,9 +386,9 @@ namespace WebSocketSharp.Server var rawData = Encoding.UTF8.GetBytes (data); if (rawData.LongLength <= WebSocket.FragmentLength) - broadcast (Opcode.TEXT, rawData, null); + broadcast (Opcode.Text, rawData, null); else - broadcast (Opcode.TEXT, new MemoryStream (rawData), null); + broadcast (Opcode.Text, new MemoryStream (rawData), null); } /// @@ -414,9 +414,9 @@ namespace WebSocketSharp.Server } if (data.LongLength <= WebSocket.FragmentLength) - broadcastAsync (Opcode.BINARY, data, completed); + broadcastAsync (Opcode.Binary, data, completed); else - broadcastAsync (Opcode.BINARY, new MemoryStream (data), completed); + broadcastAsync (Opcode.Binary, new MemoryStream (data), completed); } /// @@ -443,9 +443,9 @@ namespace WebSocketSharp.Server var rawData = Encoding.UTF8.GetBytes (data); if (rawData.LongLength <= WebSocket.FragmentLength) - broadcastAsync (Opcode.TEXT, rawData, completed); + broadcastAsync (Opcode.Text, rawData, completed); else - broadcastAsync (Opcode.TEXT, new MemoryStream (rawData), completed); + broadcastAsync (Opcode.Text, new MemoryStream (rawData), completed); } /// @@ -493,9 +493,9 @@ namespace WebSocketSharp.Server len)); if (len <= WebSocket.FragmentLength) - broadcast (Opcode.BINARY, data, completed); + broadcast (Opcode.Binary, data, completed); else - broadcast (Opcode.BINARY, new MemoryStream (data), completed); + broadcast (Opcode.Binary, new MemoryStream (data), completed); }, ex => _logger.Fatal (ex.ToString ())); } diff --git a/websocket-sharp/Server/WebSocketSessionManager.cs b/websocket-sharp/Server/WebSocketSessionManager.cs index bb4bb3b6..c61a48fe 100644 --- a/websocket-sharp/Server/WebSocketSessionManager.cs +++ b/websocket-sharp/Server/WebSocketSessionManager.cs @@ -406,9 +406,9 @@ namespace WebSocketSharp.Server } if (data.LongLength <= WebSocket.FragmentLength) - broadcast (Opcode.BINARY, data, null); + broadcast (Opcode.Binary, data, null); else - broadcast (Opcode.BINARY, new MemoryStream (data), null); + broadcast (Opcode.Binary, new MemoryStream (data), null); } /// @@ -427,9 +427,9 @@ namespace WebSocketSharp.Server var rawData = Encoding.UTF8.GetBytes (data); if (rawData.LongLength <= WebSocket.FragmentLength) - broadcast (Opcode.TEXT, rawData, null); + broadcast (Opcode.Text, rawData, null); else - broadcast (Opcode.TEXT, new MemoryStream (rawData), null); + broadcast (Opcode.Text, new MemoryStream (rawData), null); } /// @@ -455,9 +455,9 @@ namespace WebSocketSharp.Server } if (data.LongLength <= WebSocket.FragmentLength) - broadcastAsync (Opcode.BINARY, data, completed); + broadcastAsync (Opcode.Binary, data, completed); else - broadcastAsync (Opcode.BINARY, new MemoryStream (data), completed); + broadcastAsync (Opcode.Binary, new MemoryStream (data), completed); } /// @@ -484,9 +484,9 @@ namespace WebSocketSharp.Server var rawData = Encoding.UTF8.GetBytes (data); if (rawData.LongLength <= WebSocket.FragmentLength) - broadcastAsync (Opcode.TEXT, rawData, completed); + broadcastAsync (Opcode.Text, rawData, completed); else - broadcastAsync (Opcode.TEXT, new MemoryStream (rawData), completed); + broadcastAsync (Opcode.Text, new MemoryStream (rawData), completed); } /// @@ -534,9 +534,9 @@ namespace WebSocketSharp.Server len)); if (len <= WebSocket.FragmentLength) - broadcast (Opcode.BINARY, data, completed); + broadcast (Opcode.Binary, data, completed); else - broadcast (Opcode.BINARY, new MemoryStream (data), completed); + broadcast (Opcode.Binary, new MemoryStream (data), completed); }, ex => _logger.Fatal (ex.ToString ())); } diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 30dec1fe..b48608fb 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -1186,7 +1186,7 @@ namespace WebSocketSharp // Mid for (long i = 0; i < times; i++) { if (stream.Read (buffer, 0, FragmentLength) != FragmentLength || - !send (WsFrame.CreateFrame (Fin.More, Opcode.CONT, mask, buffer, compressed))) + !send (WsFrame.CreateFrame (Fin.More, Opcode.Cont, mask, buffer, compressed))) return false; } @@ -1196,7 +1196,7 @@ namespace WebSocketSharp buffer = new byte [tmpLen = rem]; return stream.Read (buffer, 0, tmpLen) == tmpLen && - send (WsFrame.CreateFrame (Fin.Final, Opcode.CONT, mask, buffer, compressed)); + send (WsFrame.CreateFrame (Fin.Final, Opcode.Cont, mask, buffer, compressed)); } // As client @@ -1849,10 +1849,10 @@ namespace WebSocketSharp var len = data.LongLength; if (len <= FragmentLength) send ( - Opcode.BINARY, + Opcode.Binary, len > 0 && _client && _compression == CompressionMethod.None ? data.Copy (len) : data); else - send (Opcode.BINARY, new MemoryStream (data)); + send (Opcode.Binary, new MemoryStream (data)); } /// @@ -1872,7 +1872,7 @@ namespace WebSocketSharp return; } - send (Opcode.BINARY, file.OpenRead ()); + send (Opcode.Binary, file.OpenRead ()); } /// @@ -1893,9 +1893,9 @@ namespace WebSocketSharp var rawData = Encoding.UTF8.GetBytes (data); if (rawData.LongLength <= FragmentLength) - send (Opcode.TEXT, rawData); + send (Opcode.Text, rawData); else - send (Opcode.TEXT, new MemoryStream (rawData)); + send (Opcode.Text, new MemoryStream (rawData)); } /// @@ -1925,11 +1925,11 @@ namespace WebSocketSharp var len = data.LongLength; if (len <= FragmentLength) sendAsync ( - Opcode.BINARY, + Opcode.Binary, len > 0 && _client && _compression == CompressionMethod.None ? data.Copy (len) : data, completed); else - sendAsync (Opcode.BINARY, new MemoryStream (data), completed); + sendAsync (Opcode.Binary, new MemoryStream (data), completed); } /// @@ -1957,7 +1957,7 @@ namespace WebSocketSharp return; } - sendAsync (Opcode.BINARY, file.OpenRead (), completed); + sendAsync (Opcode.Binary, file.OpenRead (), completed); } /// @@ -1986,9 +1986,9 @@ namespace WebSocketSharp var rawData = Encoding.UTF8.GetBytes (data); if (rawData.LongLength <= FragmentLength) - sendAsync (Opcode.TEXT, rawData, completed); + sendAsync (Opcode.Text, rawData, completed); else - sendAsync (Opcode.TEXT, new MemoryStream (rawData), completed); + sendAsync (Opcode.Text, new MemoryStream (rawData), completed); } /// @@ -2042,8 +2042,8 @@ namespace WebSocketSharp len)); var sent = len <= FragmentLength - ? send (Opcode.BINARY, data) - : send (Opcode.BINARY, new MemoryStream (data)); + ? send (Opcode.Binary, data) + : send (Opcode.Binary, new MemoryStream (data)); if (completed != null) completed (sent); diff --git a/websocket-sharp/WsFrame.cs b/websocket-sharp/WsFrame.cs index d4eb4555..54474026 100644 --- a/websocket-sharp/WsFrame.cs +++ b/websocket-sharp/WsFrame.cs @@ -128,13 +128,13 @@ namespace WebSocketSharp internal bool IsBinary { get { - return Opcode == Opcode.BINARY; + return Opcode == Opcode.Binary; } } internal bool IsClose { get { - return Opcode == Opcode.CLOSE; + return Opcode == Opcode.Close; } } @@ -146,21 +146,21 @@ namespace WebSocketSharp internal bool IsContinuation { get { - return Opcode == Opcode.CONT; + return Opcode == Opcode.Cont; } } internal bool IsControl { get { var opcode = Opcode; - return opcode == Opcode.CLOSE || opcode == Opcode.PING || opcode == Opcode.PONG; + return opcode == Opcode.Close || opcode == Opcode.Ping || opcode == Opcode.Pong; } } internal bool IsData { get { var opcode = Opcode; - return opcode == Opcode.BINARY || opcode == Opcode.TEXT; + return opcode == Opcode.Binary || opcode == Opcode.Text; } } @@ -172,7 +172,7 @@ namespace WebSocketSharp internal bool IsFragmented { get { - return Fin == Fin.More || Opcode == Opcode.CONT; + return Fin == Fin.More || Opcode == Opcode.Cont; } } @@ -185,25 +185,25 @@ namespace WebSocketSharp internal bool IsPerMessageCompressed { get { var opcode = Opcode; - return (opcode == Opcode.BINARY || opcode == Opcode.TEXT) && Rsv1 == Rsv.On; + return (opcode == Opcode.Binary || opcode == Opcode.Text) && Rsv1 == Rsv.On; } } internal bool IsPing { get { - return Opcode == Opcode.PING; + return Opcode == Opcode.Ping; } } internal bool IsPong { get { - return Opcode == Opcode.PONG; + return Opcode == Opcode.Pong; } } internal bool IsText { get { - return Opcode == Opcode.TEXT; + return Opcode == Opcode.Text; } } @@ -322,27 +322,27 @@ namespace WebSocketSharp private static bool isBinary (Opcode opcode) { - return opcode == Opcode.BINARY; + return opcode == Opcode.Binary; } private static bool isClose (Opcode opcode) { - return opcode == Opcode.CLOSE; + return opcode == Opcode.Close; } private static bool isContinuation (Opcode opcode) { - return opcode == Opcode.CONT; + return opcode == Opcode.Cont; } private static bool isControl (Opcode opcode) { - return opcode == Opcode.CLOSE || opcode == Opcode.PING || opcode == Opcode.PONG; + return opcode == Opcode.Close || opcode == Opcode.Ping || opcode == Opcode.Pong; } private static bool isData (Opcode opcode) { - return opcode == Opcode.TEXT || opcode == Opcode.BINARY; + return opcode == Opcode.Text || opcode == Opcode.Binary; } private static bool isFinal (Fin fin) @@ -357,17 +357,17 @@ namespace WebSocketSharp private static bool isPing (Opcode opcode) { - return opcode == Opcode.PING; + return opcode == Opcode.Ping; } private static bool isPong (Opcode opcode) { - return opcode == Opcode.PONG; + return opcode == Opcode.Pong; } private static bool isText (Opcode opcode) { - return opcode == Opcode.TEXT; + return opcode == Opcode.Text; } private static WsFrame parse (byte [] header, Stream stream, bool unmask) @@ -556,12 +556,12 @@ Extended Payload Len: {7} internal static WsFrame CreateCloseFrame (Mask mask, PayloadData payload) { - return new WsFrame (Opcode.CLOSE, mask, payload); + return new WsFrame (Opcode.Close, mask, payload); } internal static WsFrame CreatePongFrame (Mask mask, PayloadData payload) { - return new WsFrame (Opcode.PONG, mask, payload); + return new WsFrame (Opcode.Pong, mask, payload); } #endregion @@ -570,12 +570,12 @@ Extended Payload Len: {7} public static WsFrame CreateCloseFrame (Mask mask, byte [] data) { - return new WsFrame (Opcode.CLOSE, mask, new PayloadData (data)); + return new WsFrame (Opcode.Close, mask, new PayloadData (data)); } public static WsFrame CreateCloseFrame (Mask mask, CloseStatusCode code, string reason) { - return new WsFrame (Opcode.CLOSE, mask, new PayloadData (((ushort) code).Append (reason))); + return new WsFrame (Opcode.Close, mask, new PayloadData (((ushort) code).Append (reason))); } public static WsFrame CreateFrame ( @@ -586,12 +586,12 @@ Extended Payload Len: {7} public static WsFrame CreatePingFrame (Mask mask) { - return new WsFrame (Opcode.PING, mask, new PayloadData ()); + return new WsFrame (Opcode.Ping, mask, new PayloadData ()); } public static WsFrame CreatePingFrame (Mask mask, byte [] data) { - return new WsFrame (Opcode.PING, mask, new PayloadData (data)); + return new WsFrame (Opcode.Ping, mask, new PayloadData (data)); } public IEnumerator GetEnumerator ()