Modified AcceptWebSocket method with subprotocol
This commit is contained in:
@@ -204,12 +204,34 @@ namespace WebSocketSharp.Net
|
||||
/// A <see cref="HttpListenerWebSocketContext"/> that represents the WebSocket connection
|
||||
/// request.
|
||||
/// </returns>
|
||||
/// <param name="protocol">
|
||||
/// A <see cref="string"/> that represents the subprotocol used in the WebSocket connection.
|
||||
/// </param>
|
||||
/// <param name="logger">
|
||||
/// A <see cref="Logger"/> that provides the logging functions used in the WebSocket attempts.
|
||||
/// </param>
|
||||
public HttpListenerWebSocketContext AcceptWebSocket (Logger logger)
|
||||
/// <exception cref="ArgumentException">
|
||||
/// <para>
|
||||
/// <paramref name="protocol"/> is empty.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// -or-
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <paramref name="protocol"/> contains an invalid character.
|
||||
/// </para>
|
||||
/// </exception>
|
||||
public HttpListenerWebSocketContext AcceptWebSocket (string protocol, Logger logger)
|
||||
{
|
||||
return new HttpListenerWebSocketContext (this, logger);
|
||||
if (protocol != null) {
|
||||
if (protocol.Length == 0)
|
||||
throw new ArgumentException ("An empty string.", "protocol");
|
||||
|
||||
if (!protocol.IsToken ())
|
||||
throw new ArgumentException ("Contains an invalid character.", "protocol");
|
||||
}
|
||||
|
||||
return new HttpListenerWebSocketContext (this, protocol, logger ?? new Logger ());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@@ -51,11 +51,12 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
|
||||
#region Internal Constructors
|
||||
|
||||
internal HttpListenerWebSocketContext (HttpListenerContext context, Logger logger)
|
||||
internal HttpListenerWebSocketContext (
|
||||
HttpListenerContext context, string protocol, Logger logger)
|
||||
{
|
||||
_context = context;
|
||||
_stream = WsStream.CreateServerStream (context);
|
||||
_websocket = new WebSocket (this, logger ?? new Logger ());
|
||||
_websocket = new WebSocket (this, protocol, logger);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@@ -59,7 +59,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
#region Internal Constructors
|
||||
|
||||
internal TcpListenerWebSocketContext (
|
||||
TcpClient client, X509Certificate cert, bool secure, Logger logger)
|
||||
TcpClient client, string protocol, X509Certificate cert, bool secure, Logger logger)
|
||||
{
|
||||
_client = client;
|
||||
_secure = secure;
|
||||
@@ -67,7 +67,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
_request = _stream.ReadHandshake<HandshakeRequest> (
|
||||
HandshakeRequest.Parse, 90000);
|
||||
|
||||
_websocket = new WebSocket (this, logger);
|
||||
_websocket = new WebSocket (this, protocol, logger);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
Reference in New Issue
Block a user