Refactored HttpServer.cs, WebSocketServer.cs
This commit is contained in:
parent
31c3ece37f
commit
2fe44b9279
@ -234,7 +234,7 @@ namespace WebSocketSharp
|
|||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string CheckIfStopped (this ServerState state)
|
internal static string CheckIfStartable (this ServerState state)
|
||||||
{
|
{
|
||||||
return state == ServerState.START
|
return state == ServerState.START
|
||||||
? "The server has already started."
|
? "The server has already started."
|
||||||
|
@ -74,20 +74,33 @@ namespace WebSocketSharp.Server
|
|||||||
#region Public Constructors
|
#region Public Constructors
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="HttpServer"/> class that
|
/// Initializes a new instance of the <see cref="HttpServer"/> class.
|
||||||
/// listens for incoming requests on port 80.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// An instance initialized by this constructor listens for the incoming
|
||||||
|
/// requests on port 80.
|
||||||
|
/// </remarks>
|
||||||
public HttpServer ()
|
public HttpServer ()
|
||||||
: this (80)
|
: this (80)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="HttpServer"/> class that
|
/// Initializes a new instance of the <see cref="HttpServer"/> class with
|
||||||
/// listens for incoming requests on the specified <paramref name="port"/>.
|
/// the specified <paramref name="port"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>
|
||||||
|
/// An instance initialized by this constructor listens for the incoming
|
||||||
|
/// requests on <paramref name="port"/>.
|
||||||
|
/// </para>
|
||||||
|
/// <para>
|
||||||
|
/// And if <paramref name="port"/> is 443, that instance provides a secure
|
||||||
|
/// connection.
|
||||||
|
/// </para>
|
||||||
|
/// </remarks>
|
||||||
/// <param name="port">
|
/// <param name="port">
|
||||||
/// An <see cref="int"/> that contains a port number.
|
/// An <see cref="int"/> that represents the port number to listen.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <exception cref="ArgumentOutOfRangeException">
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
/// <paramref name="port"/> is not between 1 and 65535.
|
/// <paramref name="port"/> is not between 1 and 65535.
|
||||||
@ -98,12 +111,15 @@ namespace WebSocketSharp.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="HttpServer"/> class that
|
/// Initializes a new instance of the <see cref="HttpServer"/> class with
|
||||||
/// listens for incoming requests on the specified <paramref name="port"/>
|
/// the specified <paramref name="port"/> and <paramref name="secure"/>.
|
||||||
/// and <paramref name="secure"/>.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// An instance initialized by this constructor listens for the incoming
|
||||||
|
/// requests on <paramref name="port"/>.
|
||||||
|
/// </remarks>
|
||||||
/// <param name="port">
|
/// <param name="port">
|
||||||
/// An <see cref="int"/> that contains a port number.
|
/// An <see cref="int"/> that represents the port number to listen.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="secure">
|
/// <param name="secure">
|
||||||
/// A <see cref="bool"/> that indicates providing a secure connection or not.
|
/// A <see cref="bool"/> that indicates providing a secure connection or not.
|
||||||
@ -150,8 +166,8 @@ namespace WebSocketSharp.Server
|
|||||||
/// Gets or sets the scheme used to authenticate the clients.
|
/// Gets or sets the scheme used to authenticate the clients.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// One of the <see cref="WebSocketSharp.Net.AuthenticationSchemes"/> values
|
/// One of the <see cref="WebSocketSharp.Net.AuthenticationSchemes"/> enum
|
||||||
/// that indicates the scheme used to authenticate the clients. The default
|
/// values, indicates the scheme used to authenticate the clients. The default
|
||||||
/// value is <see cref="WebSocketSharp.Net.AuthenticationSchemes.Anonymous"/>.
|
/// value is <see cref="WebSocketSharp.Net.AuthenticationSchemes.Anonymous"/>.
|
||||||
/// </value>
|
/// </value>
|
||||||
public AuthenticationSchemes AuthenticationSchemes {
|
public AuthenticationSchemes AuthenticationSchemes {
|
||||||
@ -238,9 +254,9 @@ namespace WebSocketSharp.Server
|
|||||||
/// Gets the logging functions.
|
/// Gets the logging functions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// The default logging level is the <see cref="LogLevel.ERROR"/>. If you
|
/// The default logging level is <see cref="LogLevel.ERROR"/>. If you would
|
||||||
/// change the current logging level, you set the <c>Log.Level</c> property
|
/// like to change it, you should set the <c>Log.Level</c> property to any of
|
||||||
/// to any of the <see cref="LogLevel"/> values.
|
/// the <see cref="LogLevel"/> enum values.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="Logger"/> that provides the logging functions.
|
/// A <see cref="Logger"/> that provides the logging functions.
|
||||||
@ -255,7 +271,7 @@ namespace WebSocketSharp.Server
|
|||||||
/// Gets the port on which to listen for incoming requests.
|
/// Gets the port on which to listen for incoming requests.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// An <see cref="int"/> that contains a port number.
|
/// An <see cref="int"/> that represents the port number to listen.
|
||||||
/// </value>
|
/// </value>
|
||||||
public int Port {
|
public int Port {
|
||||||
get {
|
get {
|
||||||
@ -268,7 +284,7 @@ namespace WebSocketSharp.Server
|
|||||||
/// <see cref="HttpServer"/>.
|
/// <see cref="HttpServer"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="string"/> that contains the name of the realm.
|
/// A <see cref="string"/> that represents the name of the realm.
|
||||||
/// The default value is <c>SECRET AREA</c>.
|
/// The default value is <c>SECRET AREA</c>.
|
||||||
/// </value>
|
/// </value>
|
||||||
public string Realm {
|
public string Realm {
|
||||||
@ -288,7 +304,7 @@ namespace WebSocketSharp.Server
|
|||||||
/// Gets or sets the document root path of server.
|
/// Gets or sets the document root path of server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="string"/> that contains the document root path of server.
|
/// A <see cref="string"/> that represents the document root path of server.
|
||||||
/// The default value is <c>./Public</c>.
|
/// The default value is <c>./Public</c>.
|
||||||
/// </value>
|
/// </value>
|
||||||
public string RootPath {
|
public string RootPath {
|
||||||
@ -312,8 +328,8 @@ namespace WebSocketSharp.Server
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A Func<<see cref="IIdentity"/>, <see cref="NetworkCredential"/>>
|
/// A Func<<see cref="IIdentity"/>, <see cref="NetworkCredential"/>>
|
||||||
/// delegate that references the method(s) used to find the credentials. The
|
/// delegate that references the method(s) used to find the credentials.
|
||||||
/// default value is a function that only returns <see langword="null"/>.
|
/// The default value is a function that only returns <see langword="null"/>.
|
||||||
/// </value>
|
/// </value>
|
||||||
public Func<IIdentity, NetworkCredential> UserCredentialsFinder {
|
public Func<IIdentity, NetworkCredential> UserCredentialsFinder {
|
||||||
get {
|
get {
|
||||||
@ -329,7 +345,7 @@ namespace WebSocketSharp.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the functions for the WebSocket services provided by the
|
/// Gets the access to the WebSocket services provided by the
|
||||||
/// <see cref="HttpServer"/>.
|
/// <see cref="HttpServer"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
@ -535,11 +551,6 @@ namespace WebSocketSharp.Server
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string checkIfCanStop (Func<string> checkParams)
|
|
||||||
{
|
|
||||||
return _state.CheckIfStart () ?? checkParams ();
|
|
||||||
}
|
|
||||||
|
|
||||||
private string checkIfCertExists ()
|
private string checkIfCertExists ()
|
||||||
{
|
{
|
||||||
return _secure &&
|
return _secure &&
|
||||||
@ -598,7 +609,7 @@ namespace WebSocketSharp.Server
|
|||||||
/// and removes <c>'/'</c> from tail end of <paramref name="servicePath"/>.
|
/// and removes <c>'/'</c> from tail end of <paramref name="servicePath"/>.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="servicePath">
|
/// <param name="servicePath">
|
||||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket
|
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||||
/// service.
|
/// service.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <typeparam name="TWithNew">
|
/// <typeparam name="TWithNew">
|
||||||
@ -628,7 +639,7 @@ namespace WebSocketSharp.Server
|
|||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="servicePath">
|
/// <param name="servicePath">
|
||||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket
|
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||||
/// service.
|
/// service.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="serviceConstructor">
|
/// <param name="serviceConstructor">
|
||||||
@ -639,7 +650,8 @@ namespace WebSocketSharp.Server
|
|||||||
/// The type of the WebSocket service. The T must inherit the
|
/// The type of the WebSocket service. The T must inherit the
|
||||||
/// <see cref="WebSocketService"/> class.
|
/// <see cref="WebSocketService"/> class.
|
||||||
/// </typeparam>
|
/// </typeparam>
|
||||||
public void AddWebSocketService<T> (string servicePath, Func<T> serviceConstructor)
|
public void AddWebSocketService<T> (
|
||||||
|
string servicePath, Func<T> serviceConstructor)
|
||||||
where T : WebSocketService
|
where T : WebSocketService
|
||||||
{
|
{
|
||||||
var msg = servicePath.CheckIfValidServicePath () ??
|
var msg = servicePath.CheckIfValidServicePath () ??
|
||||||
@ -667,13 +679,14 @@ namespace WebSocketSharp.Server
|
|||||||
/// Gets the contents of the file with the specified <paramref name="path"/>.
|
/// Gets the contents of the file with the specified <paramref name="path"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// An array of <see cref="byte"/> that contains the contents of the file if
|
/// An array of <see cref="byte"/> that receives the contents of the file if
|
||||||
/// it exists; otherwise, <see langword="null"/>.
|
/// it exists; otherwise, <see langword="null"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <param name="path">
|
/// <param name="path">
|
||||||
/// A <see cref="string"/> that contains a virtual path to the file to get.
|
/// A <see cref="string"/> that represents the virtual path to the file
|
||||||
|
/// to get.
|
||||||
/// </param>
|
/// </param>
|
||||||
public byte[] GetFile (string path)
|
public byte [] GetFile (string path)
|
||||||
{
|
{
|
||||||
var filePath = RootPath + path;
|
var filePath = RootPath + path;
|
||||||
if (_windows)
|
if (_windows)
|
||||||
@ -685,8 +698,7 @@ namespace WebSocketSharp.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes the WebSocket service with the specified
|
/// Removes the WebSocket service with the specified <paramref name="servicePath"/>.
|
||||||
/// <paramref name="servicePath"/>.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// This method converts <paramref name="servicePath"/> to URL-decoded string
|
/// This method converts <paramref name="servicePath"/> to URL-decoded string
|
||||||
@ -697,7 +709,7 @@ namespace WebSocketSharp.Server
|
|||||||
/// otherwise, <c>false</c>.
|
/// otherwise, <c>false</c>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <param name="servicePath">
|
/// <param name="servicePath">
|
||||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket
|
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||||
/// service to find.
|
/// service to find.
|
||||||
/// </param>
|
/// </param>
|
||||||
public bool RemoveWebSocketService (string servicePath)
|
public bool RemoveWebSocketService (string servicePath)
|
||||||
@ -719,7 +731,7 @@ namespace WebSocketSharp.Server
|
|||||||
public void Start ()
|
public void Start ()
|
||||||
{
|
{
|
||||||
lock (_sync) {
|
lock (_sync) {
|
||||||
var msg = _state.CheckIfStopped () ?? checkIfCertExists ();
|
var msg = _state.CheckIfStartable () ?? checkIfCertExists ();
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
_logger.Error (
|
_logger.Error (
|
||||||
String.Format (
|
String.Format (
|
||||||
@ -772,9 +784,9 @@ namespace WebSocketSharp.Server
|
|||||||
{
|
{
|
||||||
byte [] data = null;
|
byte [] data = null;
|
||||||
lock (_sync) {
|
lock (_sync) {
|
||||||
var msg = checkIfCanStop (
|
var msg = _state.CheckIfStart () ??
|
||||||
() => code.CheckIfValidCloseStatusCode () ??
|
code.CheckIfValidCloseStatusCode () ??
|
||||||
(data = code.Append (reason)).CheckIfValidControlData ("reason"));
|
(data = code.Append (reason)).CheckIfValidControlData ("reason");
|
||||||
|
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
_logger.Error (
|
_logger.Error (
|
||||||
@ -808,9 +820,8 @@ namespace WebSocketSharp.Server
|
|||||||
{
|
{
|
||||||
byte [] data = null;
|
byte [] data = null;
|
||||||
lock (_sync) {
|
lock (_sync) {
|
||||||
var msg = checkIfCanStop (
|
var msg = _state.CheckIfStart () ??
|
||||||
() => (data = ((ushort) code).Append (reason))
|
(data = ((ushort) code).Append (reason)).CheckIfValidControlData ("reason");
|
||||||
.CheckIfValidControlData ("reason"));
|
|
||||||
|
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
_logger.Error (
|
_logger.Error (
|
||||||
|
@ -48,8 +48,7 @@ using WebSocketSharp.Net.WebSockets;
|
|||||||
namespace WebSocketSharp.Server
|
namespace WebSocketSharp.Server
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides the functions of the server that receives the WebSocket connection
|
/// Provides a WebSocket protocol server.
|
||||||
/// requests.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// The WebSocketServer class provides the multi WebSocket service.
|
/// The WebSocketServer class provides the multi WebSocket service.
|
||||||
@ -78,9 +77,12 @@ namespace WebSocketSharp.Server
|
|||||||
#region Public Constructors
|
#region Public Constructors
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="WebSocketServer"/> class
|
/// Initializes a new instance of the <see cref="WebSocketServer"/> class.
|
||||||
/// that listens for incoming requests on port 80.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// An instance initialized by this constructor listens for the incoming
|
||||||
|
/// connection requests on port 80.
|
||||||
|
/// </remarks>
|
||||||
public WebSocketServer ()
|
public WebSocketServer ()
|
||||||
: this (80)
|
: this (80)
|
||||||
{
|
{
|
||||||
@ -88,11 +90,20 @@ namespace WebSocketSharp.Server
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="WebSocketServer"/> class
|
/// Initializes a new instance of the <see cref="WebSocketServer"/> class
|
||||||
/// that listens for incoming connection attempts on the specified
|
/// with the specified <paramref name="port"/>.
|
||||||
/// <paramref name="port"/>.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>
|
||||||
|
/// An instance initialized by this constructor listens for the incoming
|
||||||
|
/// connection requests on <paramref name="port"/>.
|
||||||
|
/// </para>
|
||||||
|
/// <para>
|
||||||
|
/// And if <paramref name="port"/> is 443, that instance provides a secure
|
||||||
|
/// connection.
|
||||||
|
/// </para>
|
||||||
|
/// </remarks>
|
||||||
/// <param name="port">
|
/// <param name="port">
|
||||||
/// An <see cref="int"/> that contains a port number.
|
/// An <see cref="int"/> that represents the port number to listen.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <exception cref="ArgumentOutOfRangeException">
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
/// <paramref name="port"/> is not between 1 and 65535.
|
/// <paramref name="port"/> is not between 1 and 65535.
|
||||||
@ -104,11 +115,14 @@ namespace WebSocketSharp.Server
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="WebSocketServer"/> class
|
/// Initializes a new instance of the <see cref="WebSocketServer"/> class
|
||||||
/// that listens for incoming connection attempts on the specified WebSocket
|
/// with the specified WebSocket URL.
|
||||||
/// URL.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// An instance initialized by this constructor listens for the incoming
|
||||||
|
/// connection requests on the port number of <paramref name="url"/>.
|
||||||
|
/// </remarks>
|
||||||
/// <param name="url">
|
/// <param name="url">
|
||||||
/// A <see cref="string"/> that contains a WebSocket URL.
|
/// A <see cref="string"/> that represents the WebSocket URL of the server.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <exception cref="ArgumentNullException">
|
/// <exception cref="ArgumentNullException">
|
||||||
/// <paramref name="url"/> is <see langword="null"/>.
|
/// <paramref name="url"/> is <see langword="null"/>.
|
||||||
@ -140,11 +154,14 @@ namespace WebSocketSharp.Server
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="WebSocketServer"/> class
|
/// Initializes a new instance of the <see cref="WebSocketServer"/> class
|
||||||
/// that listens for incoming connection attempts on the specified
|
/// with the specified <paramref name="port"/> and <paramref name="secure"/>.
|
||||||
/// <paramref name="port"/> and <paramref name="secure"/>.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// An instance initialized by this constructor listens for the incoming
|
||||||
|
/// connection requests on <paramref name="port"/>.
|
||||||
|
/// </remarks>
|
||||||
/// <param name="port">
|
/// <param name="port">
|
||||||
/// An <see cref="int"/> that contains a port number.
|
/// An <see cref="int"/> that represents the port number to listen.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="secure">
|
/// <param name="secure">
|
||||||
/// A <see cref="bool"/> that indicates providing a secure connection or not.
|
/// A <see cref="bool"/> that indicates providing a secure connection or not.
|
||||||
@ -163,15 +180,23 @@ namespace WebSocketSharp.Server
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="WebSocketServer"/> class
|
/// Initializes a new instance of the <see cref="WebSocketServer"/> class
|
||||||
/// that listens for incoming connection attempts on the specified
|
/// with the specified <paramref name="address"/> and <paramref name="port"/>.
|
||||||
/// <paramref name="address"/> and <paramref name="port"/>.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>
|
||||||
|
/// An instance initialized by this constructor listens for the incoming
|
||||||
|
/// connection requests on <paramref name="port"/>.
|
||||||
|
/// </para>
|
||||||
|
/// <para>
|
||||||
|
/// And if <paramref name="port"/> is 443, that instance provides a secure
|
||||||
|
/// connection.
|
||||||
|
/// </para>
|
||||||
|
/// </remarks>
|
||||||
/// <param name="address">
|
/// <param name="address">
|
||||||
/// A <see cref="System.Net.IPAddress"/> that represents the local IP
|
/// A <see cref="System.Net.IPAddress"/> that represents the local IP address.
|
||||||
/// address.
|
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="port">
|
/// <param name="port">
|
||||||
/// An <see cref="int"/> that contains a port number.
|
/// An <see cref="int"/> that represents the port number to listen.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <exception cref="ArgumentNullException">
|
/// <exception cref="ArgumentNullException">
|
||||||
/// <paramref name="address"/> is <see langword="null"/>.
|
/// <paramref name="address"/> is <see langword="null"/>.
|
||||||
@ -189,16 +214,18 @@ namespace WebSocketSharp.Server
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="WebSocketServer"/> class
|
/// Initializes a new instance of the <see cref="WebSocketServer"/> class
|
||||||
/// that listens for incoming connection attempts on the specified
|
/// with the specified <paramref name="address"/>, <paramref name="port"/>,
|
||||||
/// <paramref name="address"/>, <paramref name="port"/> and
|
/// and <paramref name="secure"/>.
|
||||||
/// <paramref name="secure"/>.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// An instance initialized by this constructor listens for the incoming
|
||||||
|
/// connection requests on <paramref name="port"/>.
|
||||||
|
/// </remarks>
|
||||||
/// <param name="address">
|
/// <param name="address">
|
||||||
/// A <see cref="System.Net.IPAddress"/> that represents the local IP
|
/// A <see cref="System.Net.IPAddress"/> that represents the local IP address.
|
||||||
/// address.
|
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="port">
|
/// <param name="port">
|
||||||
/// An <see cref="int"/> that contains a port number.
|
/// An <see cref="int"/> that represents the port number to listen.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="secure">
|
/// <param name="secure">
|
||||||
/// A <see cref="bool"/> that indicates providing a secure connection or not.
|
/// A <see cref="bool"/> that indicates providing a secure connection or not.
|
||||||
@ -251,12 +278,11 @@ namespace WebSocketSharp.Server
|
|||||||
#region Public Properties
|
#region Public Properties
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the local IP address on which to listen for incoming connection
|
/// Gets the local IP address of the server.
|
||||||
/// attempts.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="System.Net.IPAddress"/> that represents the local IP
|
/// A <see cref="System.Net.IPAddress"/> that represents the local IP
|
||||||
/// address.
|
/// address of the server.
|
||||||
/// </value>
|
/// </value>
|
||||||
public System.Net.IPAddress Address {
|
public System.Net.IPAddress Address {
|
||||||
get {
|
get {
|
||||||
@ -268,8 +294,8 @@ namespace WebSocketSharp.Server
|
|||||||
/// Gets or sets the scheme used to authenticate the clients.
|
/// Gets or sets the scheme used to authenticate the clients.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// One of the <see cref="WebSocketSharp.Net.AuthenticationSchemes"/> values
|
/// One of the <see cref="WebSocketSharp.Net.AuthenticationSchemes"/> enum
|
||||||
/// that indicates the scheme used to authenticate the clients. The default
|
/// values, indicates the scheme used to authenticate the clients. The default
|
||||||
/// value is <see cref="WebSocketSharp.Net.AuthenticationSchemes.Anonymous"/>.
|
/// value is <see cref="WebSocketSharp.Net.AuthenticationSchemes.Anonymous"/>.
|
||||||
/// </value>
|
/// </value>
|
||||||
public AuthenticationSchemes AuthenticationSchemes {
|
public AuthenticationSchemes AuthenticationSchemes {
|
||||||
@ -352,9 +378,9 @@ namespace WebSocketSharp.Server
|
|||||||
/// Gets the logging functions.
|
/// Gets the logging functions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// The default logging level is the <see cref="LogLevel.ERROR"/>. If you
|
/// The default logging level is <see cref="LogLevel.ERROR"/>. If you would
|
||||||
/// change the current logging level, you set the <c>Log.Level</c> property
|
/// like to change it, you should set the <c>Log.Level</c> property to any of
|
||||||
/// to any of the <see cref="LogLevel"/> values.
|
/// the <see cref="LogLevel"/> enum values.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="Logger"/> that provides the logging functions.
|
/// A <see cref="Logger"/> that provides the logging functions.
|
||||||
@ -366,10 +392,10 @@ namespace WebSocketSharp.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the port on which to listen for incoming connection attempts.
|
/// Gets the port on which to listen for incoming connection requests.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// An <see cref="int"/> that contains a port number.
|
/// An <see cref="int"/> that represents the port number to listen.
|
||||||
/// </value>
|
/// </value>
|
||||||
public int Port {
|
public int Port {
|
||||||
get {
|
get {
|
||||||
@ -382,7 +408,7 @@ namespace WebSocketSharp.Server
|
|||||||
/// <see cref="WebSocketServer"/>.
|
/// <see cref="WebSocketServer"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="string"/> that contains the name of the realm.
|
/// A <see cref="string"/> that represents the name of the realm.
|
||||||
/// The default value is <c>SECRET AREA</c>.
|
/// The default value is <c>SECRET AREA</c>.
|
||||||
/// </value>
|
/// </value>
|
||||||
public string Realm {
|
public string Realm {
|
||||||
@ -404,8 +430,8 @@ namespace WebSocketSharp.Server
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A Func<<see cref="IIdentity"/>, <see cref="NetworkCredential"/>>
|
/// A Func<<see cref="IIdentity"/>, <see cref="NetworkCredential"/>>
|
||||||
/// delegate that references the method(s) used to find the credentials. The
|
/// delegate that references the method(s) used to find the credentials.
|
||||||
/// default value is a function that only returns <see langword="null"/>.
|
/// The default value is a function that only returns <see langword="null"/>.
|
||||||
/// </value>
|
/// </value>
|
||||||
public Func<IIdentity, NetworkCredential> UserCredentialsFinder {
|
public Func<IIdentity, NetworkCredential> UserCredentialsFinder {
|
||||||
get {
|
get {
|
||||||
@ -421,7 +447,7 @@ namespace WebSocketSharp.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the functions for the WebSocket services provided by the
|
/// Gets the access to the WebSocket services provided by the
|
||||||
/// <see cref="WebSocketServer"/>.
|
/// <see cref="WebSocketServer"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
@ -549,11 +575,6 @@ namespace WebSocketSharp.Server
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string checkIfCanStop (Func<string> checkParams)
|
|
||||||
{
|
|
||||||
return _state.CheckIfStart () ?? checkParams ();
|
|
||||||
}
|
|
||||||
|
|
||||||
private string checkIfCertExists ()
|
private string checkIfCertExists ()
|
||||||
{
|
{
|
||||||
return _secure && _cert == null
|
return _secure && _cert == null
|
||||||
@ -635,7 +656,7 @@ namespace WebSocketSharp.Server
|
|||||||
/// and removes <c>'/'</c> from tail end of <paramref name="servicePath"/>.
|
/// and removes <c>'/'</c> from tail end of <paramref name="servicePath"/>.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="servicePath">
|
/// <param name="servicePath">
|
||||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket
|
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||||
/// service.
|
/// service.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <typeparam name="TWithNew">
|
/// <typeparam name="TWithNew">
|
||||||
@ -665,7 +686,7 @@ namespace WebSocketSharp.Server
|
|||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="servicePath">
|
/// <param name="servicePath">
|
||||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket
|
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||||
/// service.
|
/// service.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="serviceConstructor">
|
/// <param name="serviceConstructor">
|
||||||
@ -676,7 +697,8 @@ namespace WebSocketSharp.Server
|
|||||||
/// The type of the WebSocket service. The T must inherit the
|
/// The type of the WebSocket service. The T must inherit the
|
||||||
/// <see cref="WebSocketService"/> class.
|
/// <see cref="WebSocketService"/> class.
|
||||||
/// </typeparam>
|
/// </typeparam>
|
||||||
public void AddWebSocketService<T> (string servicePath, Func<T> serviceConstructor)
|
public void AddWebSocketService<T> (
|
||||||
|
string servicePath, Func<T> serviceConstructor)
|
||||||
where T : WebSocketService
|
where T : WebSocketService
|
||||||
{
|
{
|
||||||
var msg = servicePath.CheckIfValidServicePath () ??
|
var msg = servicePath.CheckIfValidServicePath () ??
|
||||||
@ -713,7 +735,7 @@ namespace WebSocketSharp.Server
|
|||||||
/// otherwise, <c>false</c>.
|
/// otherwise, <c>false</c>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <param name="servicePath">
|
/// <param name="servicePath">
|
||||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket
|
/// A <see cref="string"/> that represents the absolute path to the WebSocket
|
||||||
/// service to find.
|
/// service to find.
|
||||||
/// </param>
|
/// </param>
|
||||||
public bool RemoveWebSocketService (string servicePath)
|
public bool RemoveWebSocketService (string servicePath)
|
||||||
@ -735,7 +757,7 @@ namespace WebSocketSharp.Server
|
|||||||
public void Start ()
|
public void Start ()
|
||||||
{
|
{
|
||||||
lock (_sync) {
|
lock (_sync) {
|
||||||
var msg = _state.CheckIfStopped () ?? checkIfCertExists ();
|
var msg = _state.CheckIfStartable () ?? checkIfCertExists ();
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
_logger.Error (
|
_logger.Error (
|
||||||
String.Format (
|
String.Format (
|
||||||
@ -788,9 +810,9 @@ namespace WebSocketSharp.Server
|
|||||||
{
|
{
|
||||||
byte [] data = null;
|
byte [] data = null;
|
||||||
lock (_sync) {
|
lock (_sync) {
|
||||||
var msg = checkIfCanStop (
|
var msg = _state.CheckIfStart () ??
|
||||||
() => code.CheckIfValidCloseStatusCode () ??
|
code.CheckIfValidCloseStatusCode () ??
|
||||||
(data = code.Append (reason)).CheckIfValidControlData ("reason"));
|
(data = code.Append (reason)).CheckIfValidControlData ("reason");
|
||||||
|
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
_logger.Error (
|
_logger.Error (
|
||||||
@ -824,9 +846,8 @@ namespace WebSocketSharp.Server
|
|||||||
{
|
{
|
||||||
byte [] data = null;
|
byte [] data = null;
|
||||||
lock (_sync) {
|
lock (_sync) {
|
||||||
var msg = checkIfCanStop (
|
var msg = _state.CheckIfStart () ??
|
||||||
() => (data = ((ushort) code).Append (reason))
|
(data = ((ushort) code).Append (reason)).CheckIfValidControlData ("reason");
|
||||||
.CheckIfValidControlData ("reason"));
|
|
||||||
|
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
_logger.Error (
|
_logger.Error (
|
||||||
|
Loading…
Reference in New Issue
Block a user