本文整理汇总了C#中WebSocketFrame类的典型用法代码示例。如果您正苦于以下问题:C# WebSocketFrame类的具体用法?C# WebSocketFrame怎么用?C# WebSocketFrame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketFrame类属于命名空间,在下文中一共展示了WebSocketFrame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WebSocketFrameParseResult
public WebSocketFrameParseResult(WebSocketFrame webSocketFrame, byte[] overhead)
{
if (webSocketFrame == null) throw new ArgumentNullException(nameof(webSocketFrame));
if (overhead == null) throw new ArgumentNullException(nameof(overhead));
WebSocketFrame = webSocketFrame;
Overhead = overhead;
}
示例2: MessageEventArgs
internal MessageEventArgs(WebSocketFrame frame)
{
_opcode = frame.Opcode;
_rawData = frame.PayloadData.ApplicationData;
_data = convertToString (_opcode, _rawData);
}
示例3: checkIfValidReceivedFrame
private string checkIfValidReceivedFrame (WebSocketFrame frame)
{
var masked = frame.IsMasked;
return _client && masked
? "A frame from the server is masked."
: !_client && !masked
? "A frame from a client isn't masked."
: _inContinuation && frame.IsData
? "A data frame has been received while receiving the fragmented data."
: frame.IsCompressed && _compression == CompressionMethod.None
? "A compressed frame is without an available decompression method."
: null;
}
示例4: processUnsupportedFrame
private bool processUnsupportedFrame (WebSocketFrame frame, CloseStatusCode code, string reason)
{
_logger.Debug ("An unsupported frame:" + frame.PrintToString (false));
processException (new WebSocketException (code, reason), null);
return false;
}
示例5: processPongFrame
private bool processPongFrame (WebSocketFrame frame)
{
_receivePong.Set ();
_logger.Trace ("Received a Pong.");
return true;
}
示例6: processFragmentedFrame
private bool processFragmentedFrame (WebSocketFrame frame)
{
if (!_inContinuation) {
// Must process first fragment.
if (frame.IsContinuation)
return true;
_fopcode = frame.Opcode;
_fragmentsBuffer = new MemoryStream ();
_inContinuation = true;
}
_fragmentsBuffer.WriteBytes (frame.PayloadData.ApplicationData);
if (frame.IsFinal) {
using (_fragmentsBuffer) {
var data = _compression != CompressionMethod.None
? _fragmentsBuffer.DecompressToArray (_compression)
: _fragmentsBuffer.ToArray ();
enqueueToMessageEventQueue (new MessageEventArgs (_fopcode, data));
}
_fragmentsBuffer = null;
_inContinuation = false;
}
return true;
}
示例7: checkReceivedFrame
private bool checkReceivedFrame (WebSocketFrame frame, out string message)
{
message = null;
var masked = frame.IsMasked;
if (_client && masked) {
message = "A frame from the server is masked.";
return false;
}
if (!_client && !masked) {
message = "A frame from a client isn't masked.";
return false;
}
if (_inContinuation && frame.IsData) {
message = "A data frame has been received while receiving continuation frames.";
return false;
}
if (frame.IsCompressed && _compression == CompressionMethod.None) {
message = "A compressed frame has been received without any agreement for it.";
return false;
}
if (frame.Rsv2 == Rsv.On) {
message = "The RSV2 of a frame is non-zero without any negotiation for it.";
return false;
}
if (frame.Rsv3 == Rsv.On) {
message = "The RSV3 of a frame is non-zero without any negotiation for it.";
return false;
}
return true;
}
示例8: processFragmentedFrame
private bool processFragmentedFrame(WebSocketFrame frame)
{
return frame.IsContinuation // Not first fragment
? true
: processFragments(frame);
}
示例9: processPingFrame
private bool processPingFrame(WebSocketFrame frame)
{
var mask = Mask.Unmask;
return true;
}
示例10: send
private bool send(WebSocketFrame frame)
{
lock (_forConn) {
if (_readyState != WebSocketState.Open) {
_logger.Warn ("Sending has been interrupted.");
return false;
}
return _stream.Write (frame.ToByteArray ());
}
}
示例11: processCloseFrame
private bool processCloseFrame(WebSocketFrame frame)
{
var payload = frame.PayloadData;
close(payload, !payload.ContainsReservedCloseStatusCode, false);
return false;
}
示例12: acceptPingFrame
private bool acceptPingFrame(WebSocketFrame frame)
{
var mask = _client ? Mask.Mask : Mask.Unmask;
if (send (WebSocketFrame.CreatePongFrame (mask, frame.PayloadData)))
_logger.Trace ("Returned a Pong.");
return true;
}
示例13: OpCodeText
public void OpCodeText(object sender, FrameEventArgs e)
{
WebSocketFrame frame = new WebSocketFrame(ASCIIEncoding.UTF8.GetBytes("Echo: " + e.frame.PayloadAsUTF8()));
e.clientConnection.Send(frame.AsBytes());
}
示例14: processCloseFrame
private bool processCloseFrame(WebSocketFrame frame)
{
enqueueToMessageEventQueue(new MessageEventArgs(frame));
return false;
}
示例15: processReceivedFrame
private bool processReceivedFrame (WebSocketFrame frame)
{
string msg;
if (!checkReceivedFrame (frame, out msg))
throw new WebSocketException (CloseStatusCode.ProtocolError, msg);
frame.Unmask ();
return frame.IsFragment
? processFragmentFrame (frame)
: frame.IsData
? processDataFrame (frame)
: frame.IsPing
? processPingFrame (frame)
: frame.IsPong
? processPongFrame (frame)
: frame.IsClose
? processCloseFrame (frame)
: processUnsupportedFrame (frame);
}