本文整理汇总了C#中WebSocketMessageType类的典型用法代码示例。如果您正苦于以下问题:C# WebSocketMessageType类的具体用法?C# WebSocketMessageType怎么用?C# WebSocketMessageType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketMessageType类属于命名空间,在下文中一共展示了WebSocketMessageType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WebSocketMessageWriteRfc6455Stream
public WebSocketMessageWriteRfc6455Stream(WebSocketRfc6455 client, WebSocketMessageType messageType, WebSocketExtensionFlags extensionFlags)
: this(client, messageType)
{
ExtensionFlags.Rsv1 = extensionFlags.Rsv1;
ExtensionFlags.Rsv2 = extensionFlags.Rsv2;
ExtensionFlags.Rsv3 = extensionFlags.Rsv3;
}
示例2: SendAsync
public virtual Task SendAsync(ArraySegment<byte> message, WebSocketMessageType messageType, bool endOfMessage = true)
{
if (WebSocket.State != WebSocketState.Open)
{
return TaskAsyncHelper.Empty;
}
var sendContext = new SendContext(this, message, messageType, endOfMessage);
return _sendQueue.Enqueue(async state =>
{
var context = (SendContext)state;
if (context.Handler.WebSocket.State != WebSocketState.Open)
{
return;
}
try
{
await context.Handler.WebSocket.SendAsync(context.Message, context.MessageType, context.EndOfMessage, CancellationToken.None);
}
catch (Exception ex)
{
// Swallow exceptions on send
Trace.TraceError("Error while sending: " + ex);
}
},
sendContext);
}
示例3: OnMessageReceived
public override Task OnMessageReceived(ArraySegment<byte> message, WebSocketMessageType type)
{
if (this.MessageReceived != null)
this.MessageReceived(this, new SocketMessage(this.Id, new UTF8Encoding().GetString(message.Array)));
return base.OnMessageReceived(message, type);
}
示例4: TestChatHanlder_OnReceive
private void TestChatHanlder_OnReceive(WebSocket Socket, WebSocketMessageType Type, byte[] ReceiveMessage)
{
//並行廣播給所有使用者,也可以轉發給指定使用者
Parallel.ForEach(WebSocketList, async socket => {
await socket.SendAsync(new ArraySegment<byte>(ReceiveMessage), Type, true, CancellationToken.None);
});
}
示例5: WebSocketMessageProperty
internal WebSocketMessageProperty(WebSocketContext context, string subProtocol, WebSocketMessageType incomingMessageType, ReadOnlyDictionary<string, object> properties)
{
this.context = context;
this.subProtocol = subProtocol;
this.messageType = incomingMessageType;
this.properties = properties;
}
示例6: GetWinHttpMessageType
internal static Interop.WinHttp.WINHTTP_WEB_SOCKET_BUFFER_TYPE GetWinHttpMessageType(WebSocketMessageType messageType, bool endOfMessage)
{
switch (messageType)
{
case WebSocketMessageType.Binary:
if (endOfMessage)
{
return Interop.WinHttp.WINHTTP_WEB_SOCKET_BUFFER_TYPE.WINHTTP_WEB_SOCKET_BINARY_MESSAGE_BUFFER_TYPE;
}
else
{
return Interop.WinHttp.WINHTTP_WEB_SOCKET_BUFFER_TYPE.WINHTTP_WEB_SOCKET_BINARY_FRAGMENT_BUFFER_TYPE;
}
case WebSocketMessageType.Text:
if (endOfMessage)
{
return Interop.WinHttp.WINHTTP_WEB_SOCKET_BUFFER_TYPE.WINHTTP_WEB_SOCKET_UTF8_MESSAGE_BUFFER_TYPE;
}
else
{
return Interop.WinHttp.WINHTTP_WEB_SOCKET_BUFFER_TYPE.WINHTTP_WEB_SOCKET_UTF8_FRAGMENT_BUFFER_TYPE;
}
case WebSocketMessageType.Close:
return Interop.WinHttp.WINHTTP_WEB_SOCKET_BUFFER_TYPE.WINHTTP_WEB_SOCKET_CLOSE_BUFFER_TYPE;
default:
Debug.Fail("Unknown WebSocketMessageType.");
return Interop.WinHttp.WINHTTP_WEB_SOCKET_BUFFER_TYPE.WINHTTP_WEB_SOCKET_CLOSE_BUFFER_TYPE;
}
}
示例7: SendContext
public SendContext(ArraySegment<byte> buffer, bool endOfMessage, WebSocketMessageType type, CancellationToken cancelToken)
{
this.Buffer = buffer;
this.EndOfMessage = endOfMessage;
this.Type = type;
this.CancelToken = cancelToken;
}
示例8: PendingSend
public PendingSend(TaskCompletionSource<bool> tcs, WebSocketMessageType type, ArraySegment<byte> buffer, CancellationToken cancellationToken)
{
Type = type;
_tcs = tcs;
Buffer = buffer;
CancellationToken = cancellationToken;
}
示例9: SendAsync
public Task SendAsync(
ArraySegment<byte> bytes,
WebSocketMessageType webSocketMessageType,
bool endOfMessage,
CancellationToken cancellationToken)
{
return this.socket.SendAsync(bytes, webSocketMessageType, endOfMessage, cancellationToken);
}
示例10: SendAsync
public Task SendAsync(
ArraySegment<byte> buffer,
WebSocketMessageType messageType,
bool endOfMessage,
CancellationToken cancellationToken)
{
throw new PlatformNotSupportedException(SR.net_WebSockets_UnsupportedPlatform);
}
示例11: SendAsync
public Task SendAsync(
ArraySegment<byte> buffer,
WebSocketMessageType messageType,
bool endOfMessage,
CancellationToken cancellationToken)
{
return _webSocket.SendAsync(buffer, messageType, endOfMessage, cancellationToken);
}
示例12: SendAsync
public Task SendAsync(
ArraySegment<byte> bytes,
WebSocketMessageType webSocketMessageType,
bool endOfMessage,
CancellationToken cancellationToken)
{
return Task.Run(() => this.socket.Send(new[] { bytes }), cancellationToken);
}
示例13: WebSocketReceiveResult
public WebSocketReceiveResult (int count,
WebSocketMessageType messageType,
bool endOfMessage,
WebSocketCloseStatus? closeStatus,
string closeStatusDescription)
{
throw new NotImplementedException ();
}
示例14: ConstructorTest_Success
public void ConstructorTest_Success(int count, WebSocketMessageType messageType, bool endOfMessage, WebSocketCloseStatus? closeStatus, string closeStatusDescription)
{
var wsrr = new WebSocketReceiveResult(count, messageType, endOfMessage, closeStatus, closeStatusDescription);
Assert.Equal(wsrr.Count, count);
Assert.Equal(wsrr.MessageType, messageType);
Assert.Equal(wsrr.EndOfMessage, endOfMessage);
Assert.Equal(wsrr.CloseStatus, closeStatus);
Assert.Equal(wsrr.CloseStatusDescription, closeStatusDescription);
}
示例15: WebSocketMessageWriteRfc6455Stream
public WebSocketMessageWriteRfc6455Stream(WebSocketRfc6455 webSocket, WebSocketMessageType messageType)
{
if (webSocket == null)
throw new ArgumentNullException("webSocket");
_internalUsedBufferLength = 0;
_messageType = messageType;
_webSocket = webSocket;
}