12 private static TimeSpan? defaultKeepAliveInterval;
48 if (!defaultKeepAliveInterval.HasValue)
50 if (WebSocketProtocolComponent.IsSupported)
52 defaultKeepAliveInterval = WebSocketProtocolComponent.WebSocketGetDefaultKeepAliveInterval();
59 return defaultKeepAliveInterval.Value;
69 WebSocketHelpers.ValidateBufferSizes(receiveBufferSize, sendBufferSize);
70 return WebSocketBuffer.CreateInternalBufferArraySegment(receiveBufferSize, sendBufferSize, isServerBuffer:
false);
78 WebSocketHelpers.ValidateBufferSizes(receiveBufferSize, 16);
79 return WebSocketBuffer.CreateInternalBufferArraySegment(receiveBufferSize, 16, isServerBuffer:
true);
94 if (!WebSocketProtocolComponent.IsSupported)
96 WebSocketHelpers.ThrowPlatformNotSupportedException_WSPC();
98 WebSocketHelpers.ValidateInnerStream(innerStream);
99 WebSocketHelpers.ValidateOptions(subProtocol, receiveBufferSize, sendBufferSize, keepAliveInterval);
100 WebSocketHelpers.ValidateArraySegment(internalBuffer,
"internalBuffer");
101 WebSocketBuffer.Validate(internalBuffer.
Count, receiveBufferSize, sendBufferSize, isServerBuffer:
false);
102 return new InternalClientWebSocket(innerStream, subProtocol, receiveBufferSize, sendBufferSize, keepAliveInterval, useZeroMaskingKey, internalBuffer);
107 if (!WebSocketProtocolComponent.IsSupported)
109 WebSocketHelpers.ThrowPlatformNotSupportedException_WSPC();
111 WebSocketHelpers.ValidateInnerStream(innerStream);
112 WebSocketHelpers.ValidateOptions(subProtocol, receiveBufferSize, 16, keepAliveInterval);
113 WebSocketHelpers.ValidateArraySegment(internalBuffer,
"internalBuffer");
114 WebSocketBuffer.Validate(internalBuffer.
Count, receiveBufferSize, 16, isServerBuffer:
true);
115 return new ServerWebSocket(innerStream, subProtocol, receiveBufferSize, keepAliveInterval, internalBuffer);
130 [Obsolete(
"This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.")]
133 return BinaryCompatibility.TargetsAtLeast_Desktop_V4_5;
137 public abstract void Abort();
154 public abstract void Dispose();
175 string text =
string.Empty;
176 if (validStates !=
null && validStates.Length != 0)
180 if (state == webSocketState)
185 text =
string.Join(
", ", validStates);
187 throw new WebSocketException(SR.GetString(
"net_WebSockets_InvalidState", state, text));
WebSocketCloseStatus
Represents well known WebSocket close codes as defined in section 11.7 of the WebSocket protocol spec...
Propagates notification that operations should be canceled.
static TimeSpan DefaultKeepAliveInterval
Gets the default WebSocket protocol keep-alive interval in milliseconds.
abstract Task CloseOutputAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken)
Initiates or completes the close handshake defined in the WebSocket protocol specification section 7.
abstract string CloseStatusDescription
Allows the remote endpoint to describe the reason why the connection was closed.
WebSocketState
Defines the different states a WebSockets instance can be in.
EditorBrowsableState
Specifies the browsable state of a property or method from within an editor.
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
Makes a request to a Uniform Resource Identifier (URI). This is an abstract class.
WebSocketMessageType
Indicates the message type.
abstract WebSocketState State
Returns the current state of the WebSocket connection.
abstract void Abort()
Aborts the WebSocket connection and cancels any pending IO operations.
static ArraySegment< byte > CreateClientBuffer(int receiveBufferSize, int sendBufferSize)
Create client buffers to use with this T:System.Net.WebSockets.WebSocket instance.
static readonly TimeSpan InfiniteTimeSpan
A constant used to specify an infinite waiting period, for methods that accept a T:System....
static ArraySegment< byte > CreateServerBuffer(int receiveBufferSize)
Creates a WebSocket server buffer.
static void ThrowOnInvalidState(WebSocketState state, params WebSocketState[] validStates)
Verifies that the connection is in an expected state.
The WebSocket class allows applications to send and receive data after the WebSocket upgrade has comp...
static bool IsStateTerminal(WebSocketState state)
Returns a value that indicates if the state of the WebSocket instance is closed or aborted.
static bool RegisterPrefix(string prefix, IWebRequestCreate creator)
Registers a T:System.Net.WebRequest descendant for the specified URI.
abstract Task SendAsync(ArraySegment< byte > buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken)
Sends data over the T:System.Net.WebSockets.WebSocket connection asynchronously.
abstract Task CloseAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken)
Closes the WebSocket connection as an asynchronous operation using the close handshake defined in the...
abstract Task< WebSocketReceiveResult > ReceiveAsync(ArraySegment< byte > buffer, CancellationToken cancellationToken)
Receives data from the T:System.Net.WebSockets.WebSocket connection asynchronously.
Contains constants that specify infinite time-out intervals. This class cannot be inherited.
static WebSocket CreateClientWebSocket(Stream innerStream, string subProtocol, int receiveBufferSize, int sendBufferSize, TimeSpan keepAliveInterval, bool useZeroMaskingKey, ArraySegment< byte > internalBuffer)
This API supports the .NET Framework infrastructure and is not intended to be used directly from your...
Represents an exception that occurred when performing an operation on a WebSocket connection.
int Count
Gets the number of elements in the range delimited by the array segment.
abstract ? WebSocketCloseStatus CloseStatus
Indicates the reason why the remote endpoint initiated the close handshake.
Represents a time interval.To browse the .NET Framework source code for this type,...
abstract string SubProtocol
The subprotocol that was negotiated during the opening handshake.
abstract void Dispose()
Used to clean up unmanaged resources for ASP.NET and self-hosted implementations.
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
static void RegisterPrefixes()
This API supports the .NET Framework infrastructure and is not intended to be used directly from your...
static bool IsApplicationTargeting45()
Returns a value that indicates if the WebSocket instance is targeting .NET Framework 4....
Represents an asynchronous operation that can return a value.
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....