diff --git a/Example2/Chat.cs b/Example2/Chat.cs index 1067e401..7b47574b 100644 --- a/Example2/Chat.cs +++ b/Example2/Chat.cs @@ -5,7 +5,7 @@ using WebSocketSharp.Server; namespace Example2 { - public class Chat : WebSocketService + public class Chat : WebSocketBehavior { private static int _num = 0; diff --git a/Example2/Echo.cs b/Example2/Echo.cs index 822ce4c1..94185aea 100644 --- a/Example2/Echo.cs +++ b/Example2/Echo.cs @@ -4,7 +4,7 @@ using WebSocketSharp.Server; namespace Example2 { - public class Echo : WebSocketService + public class Echo : WebSocketBehavior { protected override void OnMessage (MessageEventArgs e) { diff --git a/Example3/Chat.cs b/Example3/Chat.cs index 06d1c536..73bcbe18 100644 --- a/Example3/Chat.cs +++ b/Example3/Chat.cs @@ -5,7 +5,7 @@ using WebSocketSharp.Server; namespace Example3 { - public class Chat : WebSocketService + public class Chat : WebSocketBehavior { private static int _num = 0; diff --git a/Example3/Echo.cs b/Example3/Echo.cs index a682027e..6d334a68 100644 --- a/Example3/Echo.cs +++ b/Example3/Echo.cs @@ -4,7 +4,7 @@ using WebSocketSharp.Server; namespace Example3 { - public class Echo : WebSocketService + public class Echo : WebSocketBehavior { protected override void OnMessage (MessageEventArgs e) { diff --git a/README.md b/README.md index b6585474..57ed7a12 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,7 @@ using WebSocketSharp.Server; namespace Example { - public class Laputa : WebSocketService + public class Laputa : WebSocketBehavior { protected override void OnMessage (MessageEventArgs e) { @@ -277,11 +277,11 @@ Required namespace. using WebSocketSharp.Server; ``` -The `WebSocketServer` and `WebSocketService` classes exist in the `WebSocketSharp.Server` namespace. +The `WebSocketBehavior` and `WebSocketServer` classes exist in the `WebSocketSharp.Server` namespace. #### Step 2 #### -Creating the class that inherits the `WebSocketService` class. +Creating the class that inherits the `WebSocketBehavior` class. For example, if you would like to provide an echo service, @@ -290,7 +290,7 @@ using System; using WebSocketSharp; using WebSocketSharp.Server; -public class Echo : WebSocketService +public class Echo : WebSocketBehavior { protected override void OnMessage (MessageEventArgs e) { @@ -306,7 +306,7 @@ using System; using WebSocketSharp; using WebSocketSharp.Server; -public class Chat : WebSocketService +public class Chat : WebSocketBehavior { private string _suffix; @@ -327,15 +327,17 @@ public class Chat : WebSocketService } ``` -If you override the `WebSocketService.OnMessage (MessageEventArgs)` method, it's called when the `OnMessage` event of the `WebSocket` used in the current session in the WebSocket service occurs. +You can define the behavior of any WebSocket service by creating the class that inherits the `WebSocketBehavior` class. -And if you override the `WebSocketService.OnOpen ()`, `WebSocketService.OnError (ErrorEventArgs)`, and `WebSocketService.OnClose (CloseEventArgs)` methods, each of them is called when each event of the `WebSocket` (the `OnOpen`, `OnError`, and `OnClose` events) occurs. +If you override the `WebSocketBehavior.OnMessage (MessageEventArgs)` method, it's called when the `WebSocket` used in the current session in the service receives a message. -The `WebSocketService.Send` method sends a data to the client on the current session in the WebSocket service. +And if you override the `WebSocketBehavior.OnOpen ()`, `WebSocketBehavior.OnError (ErrorEventArgs)`, and `WebSocketBehavior.OnClose (CloseEventArgs)` methods, each of them is called when each event of the `WebSocket` (the `OnOpen`, `OnError`, and `OnClose` events) occurs. -If you would like to access the sessions in the WebSocket service, you should use the `WebSocketService.Sessions` property (returns a `WebSocketSharp.Server.WebSocketSessionManager`). +The `WebSocketBehavior.Send` method sends a data to the client on the current session in the service. -The `WebSocketService.Sessions.Broadcast` method broadcasts a data to every client in the WebSocket service. +If you would like to access the sessions in the service, you should use the `WebSocketBehavior.Sessions` property (returns a `WebSocketSharp.Server.WebSocketSessionManager`). + +The `WebSocketBehavior.Sessions.Broadcast` method broadcasts a data to every client in the service. #### Step 3 #### @@ -348,13 +350,13 @@ wssv.AddWebSocketService ("/Chat"); wssv.AddWebSocketService ("/ChatWithNyan", () => new Chat (" Nyan!")); ``` -You can add any WebSocket service to your `WebSocketServer` with the specified path to the service, using the `WebSocketServer.AddWebSocketService (string)` or `WebSocketServer.AddWebSocketService (string, Func)` method. +You can add any WebSocket service to your `WebSocketServer` with the specified behavior and path to the service, using the `WebSocketServer.AddWebSocketService (string)` or `WebSocketServer.AddWebSocketService (string, Func)` method. -The type of `TWithNew` must inherit the `WebSocketService` class and must have a public parameterless constructor. +The type of `TBehaviorWithNew` must inherit the `WebSocketBehavior` class, and must have a public parameterless constructor. -And also the type of `T` must inherit the `WebSocketService` class. +And also the type of `TBehavior` must inherit the `WebSocketBehavior` class. -So you can use the classes created in **Step 2** to add the WebSocket service. +So you can use the classes created in **Step 2** to add the service. If you create an instance of the `WebSocketServer` class without a port number, the `WebSocketServer` set the port number to **80** automatically. So it's necessary to run with root permission. @@ -386,7 +388,7 @@ I modified the `System.Net.HttpListener`, `System.Net.HttpListenerContext`, and So websocket-sharp provides the `WebSocketSharp.Server.HttpServer` class. -You can add any WebSocket service to your `HttpServer` with the specified path to the service, using the `HttpServer.AddWebSocketService (string)` or `HttpServer.AddWebSocketService (string, Func)` method. +You can add any WebSocket service to your `HttpServer` with the specified behavior and path to the service, using the `HttpServer.AddWebSocketService (string)` or `HttpServer.AddWebSocketService (string, Func)` method. ```cs var httpsv = new HttpServer (4649); @@ -438,7 +440,7 @@ ws.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyE }; ``` -If you set this property to nothing, the validation does nothing with the server certificate and returns `true`. +If you set this property to nothing, the validation does nothing with the server certificate, and returns `true`. As a **WebSocket Server**, you should create an instance of the `WebSocketServer` or `HttpServer` class with some settings for the secure connection, like the following. @@ -502,10 +504,10 @@ And if you would like to send the **Cookies** with the WebSocket connection requ ws.SetCookie (new Cookie ("name", "nobita")); ``` -As a **WebSocket Server**, if you would like to get the **Query String** included in each WebSocket connection request, you should access the `WebSocketService.Context.QueryString` property, like the following. +As a **WebSocket Server**, if you would like to get the **Query String** included in each WebSocket connection request, you should access the `WebSocketBehavior.Context.QueryString` property, like the following. ```cs -public class Chat : WebSocketService +public class Chat : WebSocketBehavior { private string _name; ... @@ -519,7 +521,7 @@ public class Chat : WebSocketService } ``` -And if you would like to check the **Origin header and Cookies** included in each WebSocket connection request, you should set each validation for the Origin header and Cookies in your `WebSocketService`, for example, using the `AddWebSocketService (string, Func)` method with initializing, like the following. +And if you would like to check the **Origin header and Cookies** included in each WebSocket connection request, you should set each validation for the Origin header and Cookies in your `WebSocketBehavior`, for example, using the `AddWebSocketService (string, Func)` method with initializing, like the following. ```cs wssv.AddWebSocketService ( @@ -544,7 +546,7 @@ wssv.AddWebSocketService ( }); ``` -Also, if you would like to get each value of the Origin header and cookies, you should access each of the `WebSocketService.Context.Origin` and `WebSocketService.Context.CookieCollection` properties. +Also, if you would like to get each value of the Origin header and cookies, you should access each of the `WebSocketBehavior.Context.Origin` and `WebSocketBehavior.Context.CookieCollection` properties. ### Connecting through the HTTP Proxy server ### diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs index c974636c..24d615ef 100644 --- a/websocket-sharp/Server/HttpServer.cs +++ b/websocket-sharp/Server/HttpServer.cs @@ -558,53 +558,54 @@ namespace WebSocketSharp.Server #region Public Methods /// - /// Adds the specified typed WebSocket service with the specified . + /// Adds a WebSocket service with the specified behavior and . /// /// - /// This method converts to URL-decoded string and removes '/' - /// from tail end of . + /// This method converts to URL-decoded string, + /// and removes '/' from tail end of . /// /// - /// A that represents the absolute path to the WebSocket service to add. + /// A that represents the absolute path to the service to add. /// - /// - /// The type of the WebSocket service. The TWithNew must inherit - /// the class and must have a public parameterless constructor. + /// + /// The type of the behavior of the service to add. The TBehaviorWithNew must inherit + /// the class, and must have a public parameterless + /// constructor. /// - public void AddWebSocketService (string path) - where TWithNew : WebSocketService, new () + public void AddWebSocketService (string path) + where TBehaviorWithNew : WebSocketBehavior, new () { - AddWebSocketService (path, () => new TWithNew ()); + AddWebSocketService (path, () => new TBehaviorWithNew ()); } /// - /// Adds the specified typed WebSocket service with the specified and - /// . + /// Adds the WebSocket service with the specified behavior, , + /// and . /// /// /// - /// This method converts to URL-decoded string and - /// removes '/' from tail end of . + /// This method converts to URL-decoded string, + /// and removes '/' from tail end of . /// /// /// returns an initialized specified typed - /// instance. + /// instance. /// /// /// - /// A that represents the absolute path to the WebSocket service to add. + /// A that represents the absolute path to the service to add. /// /// /// A Func<T> delegate that references the method used to initialize a new specified - /// typed instance (a new + /// typed instance (a new /// instance). /// - /// - /// The type of the WebSocket service. The T must inherit the - /// class. + /// + /// The type of the behavior of the service to add. The TBehavior must inherit + /// the class. /// - public void AddWebSocketService (string path, Func initializer) - where T : WebSocketService + public void AddWebSocketService (string path, Func initializer) + where TBehavior : WebSocketBehavior { var msg = path.CheckIfValidServicePath () ?? (initializer == null ? "'initializer' is null." : null); @@ -614,7 +615,7 @@ namespace WebSocketSharp.Server return; } - var host = new WebSocketServiceHost (path, initializer, _logger); + var host = new WebSocketServiceHost (path, initializer, _logger); if (!KeepClean) host.KeepClean = false; @@ -646,15 +647,14 @@ namespace WebSocketSharp.Server /// Removes the WebSocket service with the specified . /// /// - /// This method converts to URL-decoded string and - /// removes '/' from tail end of . + /// This method converts to URL-decoded string, + /// and removes '/' from tail end of . /// /// - /// true if the WebSocket service is successfully found and removed; - /// otherwise, false. + /// true if the service is successfully found and removed; otherwise, false. /// /// - /// A that represents the absolute path to the WebSocket service to find. + /// A that represents the absolute path to the service to find. /// public bool RemoveWebSocketService (string path) { diff --git a/websocket-sharp/Server/IWebSocketSession.cs b/websocket-sharp/Server/IWebSocketSession.cs index 8d5a4bbf..530740a9 100644 --- a/websocket-sharp/Server/IWebSocketSession.cs +++ b/websocket-sharp/Server/IWebSocketSession.cs @@ -74,8 +74,8 @@ namespace WebSocketSharp.Server /// Gets the state of the used in the session. /// /// - /// One of the enum values, indicates the state of the - /// used in the session. + /// One of the enum values, indicates the state of + /// the used in the session. /// WebSocketState State { get; } diff --git a/websocket-sharp/Server/WebSocketService.cs b/websocket-sharp/Server/WebSocketBehavior.cs similarity index 76% rename from websocket-sharp/Server/WebSocketService.cs rename to websocket-sharp/Server/WebSocketBehavior.cs index 3efdc3de..05a00928 100644 --- a/websocket-sharp/Server/WebSocketService.cs +++ b/websocket-sharp/Server/WebSocketBehavior.cs @@ -1,6 +1,6 @@ #region License /* - * WebSocketService.cs + * WebSocketBehavior.cs * * The MIT License * @@ -34,18 +34,19 @@ using WebSocketSharp.Net.WebSockets; namespace WebSocketSharp.Server { /// - /// Exposes a set of the methods and properties for a WebSocket service provided by the - /// or . + /// Exposes the methods and properties used to define the behavior of a WebSocket service + /// provided by the or . /// /// - /// The WebSocketService class is an abstract class. + /// The WebSocketBehavior class is an abstract class. /// - public abstract class WebSocketService : IWebSocketSession + public abstract class WebSocketBehavior : IWebSocketSession { #region Private Fields private WebSocketContext _context; private Func _cookiesValidator; + private string _id; private Func _originValidator; private string _protocol; private WebSocketSessionManager _sessions; @@ -57,9 +58,9 @@ namespace WebSocketSharp.Server #region Protected Constructors /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - protected WebSocketService () + protected WebSocketBehavior () { _start = DateTime.MaxValue; } @@ -71,11 +72,9 @@ namespace WebSocketSharp.Server /// /// Gets the logging functions. /// - /// - /// This property is available after the WebSocket connection has been established. - /// /// - /// A that provides the logging functions. + /// A that provides the logging functions, or + /// if the WebSocket connection isn't established. /// protected Logger Log { get { @@ -88,11 +87,9 @@ namespace WebSocketSharp.Server /// /// Gets the access to the sessions in the WebSocket service. /// - /// - /// This property is available after the WebSocket connection has been established. - /// /// - /// A that provides the access to the sessions. + /// A that provides the access to the sessions, + /// or if the WebSocket connection isn't established. /// protected WebSocketSessionManager Sessions { get { @@ -108,7 +105,8 @@ namespace WebSocketSharp.Server /// Gets the information in the current connection request to the WebSocket service. /// /// - /// A that provides the access to the current connection request. + /// A that provides the access to the current connection request, + /// or if the WebSocket connection isn't established. /// public WebSocketContext Context { get { @@ -128,11 +126,11 @@ namespace WebSocketSharp.Server /// /// A Func<CookieCollection, CookieCollection, bool> delegate that references /// the method(s) used to validate the cookies. 1st passed to - /// this delegate contains the cookies to validate, if any. 2nd + /// this delegate contains the cookies to validate if any. 2nd /// passed to this delegate receives the cookies to send to the client. /// /// - /// This delegate should return true if the cookies are valid; otherwise, false. + /// This delegate should return true if the cookies are valid. /// /// /// The default value is , and it does nothing to validate. @@ -152,10 +150,13 @@ namespace WebSocketSharp.Server /// Gets the unique ID of the current session. /// /// - /// A that represents the unique ID of the current session. + /// A that represents the unique ID of the current session, + /// or if the WebSocket connection isn't established. /// public string ID { - get; private set; + get { + return _id; + } } /// @@ -170,11 +171,10 @@ namespace WebSocketSharp.Server /// /// A Func<string, bool> delegate that references the method(s) used to validate /// the origin header. A passed to this delegate represents the value of - /// the origin header to validate, if any. + /// the origin header to validate if any. /// /// - /// This delegate should return true if the origin header is valid; otherwise, - /// false. + /// This delegate should return true if the origin header is valid. /// /// /// The default value is , and it does nothing to validate. @@ -199,8 +199,8 @@ namespace WebSocketSharp.Server /// /// /// - /// A that represents the subprotocol if any. The default value is - /// . + /// A that represents the subprotocol if any. + /// The default value is . /// /// /// The value to set must be a token defined in @@ -229,7 +229,8 @@ namespace WebSocketSharp.Server /// Gets the time that the current session has started. /// /// - /// A that represents the time that the current session has started. + /// A that represents the time that the current session has started, + /// or if the WebSocket connection isn't established. /// public DateTime StartTime { get { @@ -241,8 +242,8 @@ namespace WebSocketSharp.Server /// Gets the state of the used in the current session. /// /// - /// One of the enum values, indicates the state of the - /// used in the current session. + /// One of the enum values, indicates the state of + /// the used in the current session. /// public WebSocketState State { get { @@ -268,10 +269,10 @@ namespace WebSocketSharp.Server private void onClose (object sender, CloseEventArgs e) { - if (ID == null) + if (_id == null) return; - _sessions.Remove (ID); + _sessions.Remove (_id); OnClose (e); } @@ -287,8 +288,8 @@ namespace WebSocketSharp.Server private void onOpen (object sender, EventArgs e) { - ID = _sessions.Add (this); - if (ID == null) { + _id = _sessions.Add (this); + if (_id == null) { _websocket.Close (CloseStatusCode.Away); return; } @@ -330,22 +331,30 @@ namespace WebSocketSharp.Server #region Protected Methods /// - /// Calls the method with the specified . + /// Calls the method with the specified and + /// . /// + /// + /// This method doesn't call the method if is + /// or empty. + /// /// /// A that represents the error message. /// - protected void Error (string message) + /// + /// An instance that represents the cause of the error if any. + /// + protected void Error (string message, Exception exception) { if (message != null && message.Length > 0) - OnError (new ErrorEventArgs (message)); + OnError (new ErrorEventArgs (message, exception)); } /// /// Called when the WebSocket connection used in the current session has been closed. /// /// - /// A that represents the event data received by + /// A that represents the event data passed to /// a event. /// protected virtual void OnClose (CloseEventArgs e) @@ -353,10 +362,10 @@ namespace WebSocketSharp.Server } /// - /// Called when the current session gets an error. + /// Called when the used in the current session gets an error. /// /// - /// A that represents the event data received by + /// A that represents the event data passed to /// a event. /// protected virtual void OnError (ErrorEventArgs e) @@ -364,10 +373,10 @@ namespace WebSocketSharp.Server } /// - /// Called when the current session receives a message. + /// Called when the used in the current session receives a message. /// /// - /// A that represents the event data received by + /// A that represents the event data passed to /// a event. /// protected virtual void OnMessage (MessageEventArgs e) @@ -384,19 +393,25 @@ namespace WebSocketSharp.Server /// /// Sends a binary to the client on the current session. /// + /// + /// This method is available after the WebSocket connection has been established. + /// /// /// An array of that represents the binary data to send. /// - protected void Send (byte [] data) + protected void Send (byte[] data) { if (_websocket != null) _websocket.Send (data); } /// - /// Sends the specified as a binary data to the client on the current - /// session. + /// Sends the specified as a binary data to the client + /// on the current session. /// + /// + /// This method is available after the WebSocket connection has been established. + /// /// /// A that represents the file to send. /// @@ -409,6 +424,9 @@ namespace WebSocketSharp.Server /// /// Sends a text to the client on the current session. /// + /// + /// This method is available after the WebSocket connection has been established. + /// /// /// A that represents the text data to send. /// @@ -422,17 +440,22 @@ namespace WebSocketSharp.Server /// Sends a binary asynchronously to the client on the current session. /// /// - /// This method doesn't wait for the send to be complete. + /// + /// This method is available after the WebSocket connection has been established. + /// + /// + /// This method doesn't wait for the send to be complete. + /// /// /// /// An array of that represents the binary data to send. /// /// - /// An Action<bool> delegate that references the method(s) called when the send is + /// An Action<bool> delegate that references the method(s) called when the send is /// complete. A passed to this delegate is true if the send is - /// complete successfully; otherwise, false. + /// complete successfully. /// - protected void SendAsync (byte [] data, Action completed) + protected void SendAsync (byte[] data, Action completed) { if (_websocket != null) _websocket.SendAsync (data, completed); @@ -443,15 +466,20 @@ namespace WebSocketSharp.Server /// on the current session. /// /// - /// This method doesn't wait for the send to be complete. + /// + /// This method is available after the WebSocket connection has been established. + /// + /// + /// This method doesn't wait for the send to be complete. + /// /// /// /// A that represents the file to send. /// /// - /// An Action<bool> delegate that references the method(s) called when the send is + /// An Action<bool> delegate that references the method(s) called when the send is /// complete. A passed to this delegate is true if the send is - /// complete successfully; otherwise, false. + /// complete successfully. /// protected void SendAsync (FileInfo file, Action completed) { @@ -463,15 +491,20 @@ namespace WebSocketSharp.Server /// Sends a text asynchronously to the client on the current session. /// /// - /// This method doesn't wait for the send to be complete. + /// + /// This method is available after the WebSocket connection has been established. + /// + /// + /// This method doesn't wait for the send to be complete. + /// /// /// /// A that represents the text data to send. /// /// - /// An Action<bool> delegate that references the method(s) called when the send is + /// An Action<bool> delegate that references the method(s) called when the send is /// complete. A passed to this delegate is true if the send is - /// complete successfully; otherwise, false. + /// complete successfully. /// protected void SendAsync (string data, Action completed) { @@ -480,11 +513,16 @@ namespace WebSocketSharp.Server } /// - /// Sends a binary data from the specified asynchronously to the client on - /// the current session. + /// Sends a binary data from the specified asynchronously to the client + /// on the current session. /// /// - /// This method doesn't wait for the send to be complete. + /// + /// This method is available after the WebSocket connection has been established. + /// + /// + /// This method doesn't wait for the send to be complete. + /// /// /// /// A from which contains the binary data to send. @@ -493,9 +531,9 @@ namespace WebSocketSharp.Server /// An that represents the number of bytes to send. /// /// - /// An Action<bool> delegate that references the method(s) called when the send is + /// An Action<bool> delegate that references the method(s) called when the send is /// complete. A passed to this delegate is true if the send is - /// complete successfully; otherwise, false. + /// complete successfully. /// protected void SendAsync (Stream stream, int length, Action completed) { diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index de2bb9f4..88d20bb8 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -675,53 +675,54 @@ namespace WebSocketSharp.Server #region Public Methods /// - /// Adds the specified typed WebSocket service with the specified . + /// Adds a WebSocket service with the specified behavior and . /// /// - /// This method converts to URL-decoded string and removes '/' - /// from tail end of . + /// This method converts to URL-decoded string, + /// and removes '/' from tail end of . /// /// - /// A that represents the absolute path to the WebSocket service to add. + /// A that represents the absolute path to the service to add. /// - /// - /// The type of the WebSocket service. The TWithNew must inherit - /// the class and must have a public parameterless constructor. + /// + /// The type of the behavior of the service to add. The TBehaviorWithNew must inherit + /// the class, and must have a public parameterless + /// constructor. /// - public void AddWebSocketService (string path) - where TWithNew : WebSocketService, new () + public void AddWebSocketService (string path) + where TBehaviorWithNew : WebSocketBehavior, new () { - AddWebSocketService (path, () => new TWithNew ()); + AddWebSocketService (path, () => new TBehaviorWithNew ()); } /// - /// Adds the specified typed WebSocket service with the specified and - /// . + /// Adds a WebSocket service with the specified behavior, , + /// and . /// /// /// - /// This method converts to URL-decoded string and - /// removes '/' from tail end of . + /// This method converts to URL-decoded string, + /// and removes '/' from tail end of . /// /// /// returns an initialized specified typed - /// instance. + /// instance. /// /// /// - /// A that represents the absolute path to the WebSocket service to add. + /// A that represents the absolute path to the service to add. /// /// /// A Func<T> delegate that references the method used to initialize a new specified - /// typed instance (a new + /// typed instance (a new /// instance). /// - /// - /// The type of the WebSocket service. The T must inherit the - /// class. + /// + /// The type of the behavior of the service to add. The TBehavior must inherit + /// the class. /// - public void AddWebSocketService (string path, Func initializer) - where T : WebSocketService + public void AddWebSocketService (string path, Func initializer) + where TBehavior : WebSocketBehavior { var msg = path.CheckIfValidServicePath () ?? (initializer == null ? "'initializer' is null." : null); @@ -731,7 +732,7 @@ namespace WebSocketSharp.Server return; } - var host = new WebSocketServiceHost (path, initializer, _logger); + var host = new WebSocketServiceHost (path, initializer, _logger); if (!KeepClean) host.KeepClean = false; @@ -742,15 +743,14 @@ namespace WebSocketSharp.Server /// Removes the WebSocket service with the specified . /// /// - /// This method converts to URL-decoded string and - /// removes '/' from tail end of . + /// This method converts to URL-decoded string, + /// and removes '/' from tail end of . /// /// - /// true if the WebSocket service is successfully found and removed; - /// otherwise, false. + /// true if the service is successfully found and removed; otherwise, false. /// /// - /// A that represents the absolute path to the WebSocket service to find. + /// A that represents the absolute path to the service to find. /// public bool RemoveWebSocketService (string path) { diff --git a/websocket-sharp/Server/WebSocketServiceHost.cs b/websocket-sharp/Server/WebSocketServiceHost.cs index a17c6d77..8515ad2f 100644 --- a/websocket-sharp/Server/WebSocketServiceHost.cs +++ b/websocket-sharp/Server/WebSocketServiceHost.cs @@ -66,7 +66,7 @@ namespace WebSocketSharp.Server /// sessions periodically. /// /// - /// true if the WebSocket service cleans up the inactive sessions periodically; + /// true if the service cleans up the inactive sessions periodically; /// otherwise, false. /// public abstract bool KeepClean { get; set; } @@ -75,7 +75,7 @@ namespace WebSocketSharp.Server /// Gets the path to the WebSocket service. /// /// - /// A that represents the absolute path to the WebSocket service. + /// A that represents the absolute path to the service. /// public abstract string Path { get; } @@ -83,15 +83,15 @@ namespace WebSocketSharp.Server /// Gets the access to the sessions in the WebSocket service. /// /// - /// A that manages the sessions. + /// A that manages the sessions in the service. /// public abstract WebSocketSessionManager Sessions { get; } /// - /// Gets the type of the WebSocket service. + /// Gets the of the behavior of the WebSocket service. /// /// - /// A that represents the type of the WebSocket service. + /// A that represents the type of the behavior of the service. /// public abstract Type Type { get; } @@ -112,19 +112,19 @@ namespace WebSocketSharp.Server /// Creates a new session in the WebSocket service. /// /// - /// A instance that represents a new session. + /// A instance that represents a new session. /// - protected abstract WebSocketService CreateSession (); + protected abstract WebSocketBehavior CreateSession (); #endregion } - internal class WebSocketServiceHost : WebSocketServiceHost - where T : WebSocketService + internal class WebSocketServiceHost : WebSocketServiceHost + where TBehavior : WebSocketBehavior { #region Private Fields - private Func _initializer; + private Func _initializer; private string _path; private WebSocketSessionManager _sessions; @@ -132,7 +132,7 @@ namespace WebSocketSharp.Server #region Internal Constructors - internal WebSocketServiceHost (string path, Func initializer, Logger logger) + internal WebSocketServiceHost (string path, Func initializer, Logger logger) { _path = HttpUtility.UrlDecode (path).TrimEndSlash (); _initializer = initializer; @@ -167,7 +167,7 @@ namespace WebSocketSharp.Server public override Type Type { get { - return typeof (T); + return typeof (TBehavior); } } @@ -175,7 +175,7 @@ namespace WebSocketSharp.Server #region Protected Methods - protected override WebSocketService CreateSession () + protected override WebSocketBehavior CreateSession () { return _initializer (); } diff --git a/websocket-sharp/websocket-sharp.csproj b/websocket-sharp/websocket-sharp.csproj index a8f96d2c..47195fb8 100644 --- a/websocket-sharp/websocket-sharp.csproj +++ b/websocket-sharp/websocket-sharp.csproj @@ -69,7 +69,6 @@ - @@ -134,6 +133,7 @@ +