diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs index a3d8f651..dce9a5e7 100644 --- a/websocket-sharp/Server/HttpServer.cs +++ b/websocket-sharp/Server/HttpServer.cs @@ -387,7 +387,7 @@ namespace WebSocketSharp.Server var wsContext = context.AcceptWebSocket (); var path = wsContext.Path.UrlDecode (); - IServiceHost host; + IWebSocketServiceHost host; if (!_serviceHosts.TryGetServiceHost (path, out host)) { context.Response.StatusCode = (int) HttpStatusCode.NotImplemented; diff --git a/websocket-sharp/Server/IServiceHost.cs b/websocket-sharp/Server/IWebSocketServiceHost.cs similarity index 87% rename from websocket-sharp/Server/IServiceHost.cs rename to websocket-sharp/Server/IWebSocketServiceHost.cs index 5fec48b9..d7c1c00a 100644 --- a/websocket-sharp/Server/IServiceHost.cs +++ b/websocket-sharp/Server/IWebSocketServiceHost.cs @@ -1,6 +1,6 @@ #region License /* - * IServiceHost.cs + * IWebSocketServiceHost.cs * * The MIT License * @@ -35,9 +35,7 @@ namespace WebSocketSharp.Server /// /// Exposes the methods and properties for the WebSocket service host. /// - /// - /// - public interface IServiceHost + public interface IWebSocketServiceHost { /// /// Gets the connection count to the WebSocket service host. @@ -82,11 +80,12 @@ namespace WebSocketSharp.Server void Broadcast (string data); /// - /// Sends Pings with the specified to all clients of the WebSocket service host. + /// Sends Pings with the specified to all clients of + /// the WebSocket service host. /// /// - /// A Dictionary<string, bool> that contains the collection of session IDs and values - /// indicating whether the WebSocket service host received the Pongs from each clients in a time. + /// A Dictionary<string, bool> that contains the collection of pairs of session ID and value + /// indicating whether the WebSocket service host received the Pong from each client in a time. /// /// /// A that contains a message to send. @@ -94,50 +93,48 @@ namespace WebSocketSharp.Server Dictionary Broadping (string message); /// - /// Sends a Ping with the specified to the client associated with + /// Sends a Ping with the specified to the client associated with /// the specified ID. /// /// /// true if the WebSocket service host receives a Pong from the client in a time; /// otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the Ping. - /// /// /// A that contains a message to send. /// - bool PingTo (string id, string message); + /// + /// A that contains an ID that represents the destination for the Ping. + /// + bool PingTo (string message, string id); /// /// Sends a binary data to the client associated with the specified ID. /// /// - /// true if the client associated with is successfully found; - /// otherwise, false. + /// true if is successfully sent; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the data. - /// /// /// An array of that contains a binary data to send. /// - bool SendTo (string id, byte [] data); + /// + /// A that contains an ID that represents the destination for the data. + /// + bool SendTo (byte [] data, string id); /// /// Sends a text data to the client associated with the specified ID. /// /// - /// true if the client associated with is successfully found; - /// otherwise, false. + /// true if is successfully sent; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the data. - /// /// /// A that contains a text data to send. /// - bool SendTo (string id, string data); + /// + /// A that contains an ID that represents the destination for the data. + /// + bool SendTo (string data, string id); /// /// Starts the WebSocket service host. diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index 1677b7f7..f0e9d91f 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -226,7 +226,7 @@ namespace WebSocketSharp.Server var path = context.Path.UrlDecode (); websocket.Log = Log; - IServiceHost host; + IWebSocketServiceHost host; if (!_serviceHosts.TryGetServiceHost (path, out host)) { websocket.Close (HttpStatusCode.NotImplemented); diff --git a/websocket-sharp/Server/WebSocketService.cs b/websocket-sharp/Server/WebSocketService.cs index 730ecf27..cd48680f 100644 --- a/websocket-sharp/Server/WebSocketService.cs +++ b/websocket-sharp/Server/WebSocketService.cs @@ -349,8 +349,8 @@ namespace WebSocketSharp.Server /// in the . /// /// - /// A Dictionary<string, bool> that contains the collection of IDs and values indicating - /// whether the each instances received a Pong in a time. + /// A Dictionary<string, bool> that contains the collection of pairs of session ID and value + /// indicating whether the each instance received a Pong in a time. /// public virtual Dictionary Broadping () { @@ -360,12 +360,12 @@ namespace WebSocketSharp.Server } /// - /// Sends Pings with the specified to the clients of every + /// Sends Pings with the specified to the clients of every /// instances in the . /// /// - /// A Dictionary<string, bool> that contains the collection of IDs and values - /// indicating whether the each instances received a Pong in a time. + /// A Dictionary<string, bool> that contains the collection of pairs of session ID and value + /// indicating whether the each instance received a Pong in a time. /// /// /// A that contains a message to send. @@ -406,7 +406,7 @@ namespace WebSocketSharp.Server } /// - /// Sends a Ping with the specified to the client of + /// Sends a Ping with the specified to the client of /// the current instance. /// /// @@ -428,54 +428,46 @@ namespace WebSocketSharp.Server /// with the specified ID. /// /// - /// true if the instance receives a Pong in a time; - /// otherwise, false. + /// true if the instance with receives + /// a Pong in a time; otherwise, false. /// /// /// A that contains an ID that represents the destination for the Ping. /// public virtual bool PingTo (string id) { - return PingTo (id, String.Empty); + return PingTo (String.Empty, id); } /// - /// Sends a Ping with the specified to the client of the - /// instance with the specified ID. + /// Sends a Ping with the specified to the client of + /// the instance with the specified ID. /// /// - /// true if the instance receives a Pong in a time; - /// otherwise, false. + /// true if the instance with receives + /// a Pong in a time; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the Ping. - /// /// /// A that contains a message to send. /// - public virtual bool PingTo (string id, string message) + /// + /// A that contains an ID that represents the destination for the Ping. + /// + public virtual bool PingTo (string message, string id) { if (!IsBound) return false; - if (message == null) - message = String.Empty; - - var msg = id.IsNullOrEmpty () - ? "'id' must not be null or empty." - : Encoding.UTF8.GetBytes (message).Length > 125 - ? "The payload length of a Ping frame must be 125 bytes or less." - : String.Empty; - - if (msg.Length > 0) + if (id.IsNullOrEmpty ()) { + var msg = "'id' must not be null or empty."; Log.Error (msg); Error (msg); return false; } - return _sessions.PingTo (id, message); + return _sessions.PingTo (message, id); } /// @@ -507,26 +499,26 @@ namespace WebSocketSharp.Server /// with the specified ID. /// /// - /// true if the client is successfully found; otherwise, false. + /// true if is successfully sent; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the data. - /// /// /// An array of that contains a binary data to send. /// - public virtual bool SendTo (string id, byte [] data) + /// + /// A that contains an ID that represents the destination for the data. + /// + public virtual bool SendTo (byte [] data, string id) { if (!IsBound) return false; - var msg = id.IsNullOrEmpty () - ? "'id' must not be null or empty." - : data == null - ? "'data' must not be null." - : String.Empty; + var msg = data == null + ? "'data' must not be null." + : id.IsNullOrEmpty () + ? "'id' must not be null or empty." + : null; - if (msg.Length > 0) + if (msg != null) { Log.Error (msg); Error (msg); @@ -534,7 +526,7 @@ namespace WebSocketSharp.Server return false; } - return _sessions.SendTo (id, data); + return _sessions.SendTo (data, id); } /// @@ -542,26 +534,26 @@ namespace WebSocketSharp.Server /// with the specified ID. /// /// - /// true if the client is successfully found; otherwise, false. + /// true if is successfully sent; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the data. - /// /// /// A that contains a text data to send. /// - public virtual bool SendTo (string id, string data) + /// + /// A that contains an ID that represents the destination for the data. + /// + public virtual bool SendTo (string data, string id) { if (!IsBound) return false; - var msg = id.IsNullOrEmpty () - ? "'id' must not be null or empty." - : data == null - ? "'data' must not be null." - : String.Empty; + var msg = data == null + ? "'data' must not be null." + : id.IsNullOrEmpty () + ? "'id' must not be null or empty." + : null; - if (msg.Length > 0) + if (msg != null) { Log.Error (msg); Error (msg); @@ -569,11 +561,11 @@ namespace WebSocketSharp.Server return false; } - return _sessions.SendTo (id, data); + return _sessions.SendTo (data, id); } /// - /// Starts a instance. + /// Starts the current instance. /// public void Start () { diff --git a/websocket-sharp/Server/WebSocketServiceHost.cs b/websocket-sharp/Server/WebSocketServiceHost.cs index 3409255e..8c293fe1 100644 --- a/websocket-sharp/Server/WebSocketServiceHost.cs +++ b/websocket-sharp/Server/WebSocketServiceHost.cs @@ -47,7 +47,7 @@ namespace WebSocketSharp.Server /// The type of the WebSocket service that the server provides. /// The T must inherit the class. /// - public class WebSocketServiceHost : WebSocketServerBase, IServiceHost + public class WebSocketServiceHost : WebSocketServerBase, IWebSocketServiceHost where T : WebSocketService, new () { #region Private Fields @@ -267,20 +267,20 @@ namespace WebSocketSharp.Server /// protected override void AcceptWebSocket (TcpListenerWebSocketContext context) { - var ws = context.WebSocket; + var websocket = context.WebSocket; var path = context.Path.UrlDecode (); - ws.Log = Log; + websocket.Log = Log; if (path != Uri.GetAbsolutePath ().UrlDecode ()) { - ws.Close (HttpStatusCode.NotImplemented); + websocket.Close (HttpStatusCode.NotImplemented); return; } if (Uri.IsAbsoluteUri) - ws.Url = Uri; + websocket.Url = Uri; - ((IServiceHost) this).BindWebSocket (context); + ((IWebSocketServiceHost) this).BindWebSocket (context); } #endregion @@ -322,11 +322,11 @@ namespace WebSocketSharp.Server } /// - /// Sends Pings with the specified to all clients. + /// Sends Pings with the specified to all clients. /// /// - /// A Dictionary<string, bool> that contains the collection of session IDs and values - /// indicating whether the service host received the Pongs from each clients in a time. + /// A Dictionary<string, bool> that contains the collection of pairs of session ID and value + /// indicating whether the service host received the Pong from each client in a time. /// /// /// A that contains a message to send. @@ -347,58 +347,48 @@ namespace WebSocketSharp.Server } /// - /// Sends a Ping with the specified to the client associated with + /// Sends a Ping with the specified to the client associated with /// the specified ID. /// /// /// true if the service host receives a Pong from the client in a time; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the Ping. - /// /// /// A that contains a message to send. /// - public bool PingTo (string id, string message) + /// + /// A that contains an ID that represents the destination for the Ping. + /// + public bool PingTo (string message, string id) { - if (message == null) - message = String.Empty; - - var msg = id.IsNullOrEmpty () - ? "'id' must not be null or empty." - : Encoding.UTF8.GetBytes (message).Length > 125 - ? "The payload length of a Ping frame must be 125 bytes or less." - : null; - - if (msg != null) + if (id.IsNullOrEmpty ()) { - Log.Error (msg); + Log.Error ("'id' must not be null or empty."); return false; } - return _sessions.PingTo (id, message); + return _sessions.PingTo (message, id); } /// /// Sends a binary data to the client associated with the specified ID. /// /// - /// true if the client associated with is successfully found; - /// otherwise, false. + /// true if is successfully sent; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the data. - /// /// /// An array of that contains a binary data to send. /// - public bool SendTo (string id, byte [] data) + /// + /// A that contains an ID that represents the destination for the data. + /// + public bool SendTo (byte [] data, string id) { - var msg = id.IsNullOrEmpty () + var msg = data == null + ? "'data' must not be null." + : id.IsNullOrEmpty () ? "'id' must not be null or empty." - : data == null - ? "'data' must not be null." - : null; + : null; if (msg != null) { @@ -406,29 +396,28 @@ namespace WebSocketSharp.Server return false; } - return _sessions.SendTo (id, data); + return _sessions.SendTo (data, id); } /// /// Sends a text data to the client associated with the specified ID. /// /// - /// true if the client associated with is successfully found; - /// otherwise, false. + /// true if is successfully sent; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the data. - /// /// /// A that contains a text data to send. /// - public bool SendTo (string id, string data) + /// + /// A that contains an ID that represents the destination for the data. + /// + public bool SendTo (string data, string id) { - var msg = id.IsNullOrEmpty () + var msg = data == null + ? "'data' must not be null." + : id.IsNullOrEmpty () ? "'id' must not be null or empty." - : data == null - ? "'data' must not be null." - : null; + : null; if (msg != null) { @@ -436,7 +425,7 @@ namespace WebSocketSharp.Server return false; } - return _sessions.SendTo (id, data); + return _sessions.SendTo (data, id); } /// @@ -494,7 +483,7 @@ namespace WebSocketSharp.Server /// /// A that contains the WebSocket connection request objects to bind. /// - void IServiceHost.BindWebSocket (WebSocketContext context) + void IWebSocketServiceHost.BindWebSocket (WebSocketContext context) { T service = new T (); service.Bind (context, _sessions); @@ -507,7 +496,7 @@ namespace WebSocketSharp.Server /// /// An array of to broadcast. /// - void IServiceHost.Broadcast (byte [] data) + void IWebSocketServiceHost.Broadcast (byte [] data) { _sessions.Broadcast (data); } @@ -518,78 +507,76 @@ namespace WebSocketSharp.Server /// /// A to broadcast. /// - void IServiceHost.Broadcast (string data) + void IWebSocketServiceHost.Broadcast (string data) { _sessions.Broadcast (data); } /// - /// Sends Pings with the specified to all clients. + /// Sends Pings with the specified to all clients. /// /// - /// A Dictionary<string, bool> that contains the collection of session IDs and values - /// indicating whether the service host received the Pongs from each clients in a time. + /// A Dictionary<string, bool> that contains the collection of pairs of session ID and value + /// indicating whether the service host received the Pong from each client in a time. /// /// /// A that contains a message to send. /// - Dictionary IServiceHost.Broadping (string message) + Dictionary IWebSocketServiceHost.Broadping (string message) { return _sessions.Broadping (message); } /// - /// Sends a Ping with the specified to the client associated with + /// Sends a Ping with the specified to the client associated with /// the specified ID. /// /// /// true if the service host receives a Pong from the client in a time; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the Ping. - /// /// /// A that contains a message to send. /// - bool IServiceHost.PingTo (string id, string message) + /// + /// A that contains an ID that represents the destination for the Ping. + /// + bool IWebSocketServiceHost.PingTo (string message, string id) { - return _sessions.PingTo (id, message); + return _sessions.PingTo (message, id); } /// /// Sends a binary data to the client associated with the specified ID. /// /// - /// true if the client associated with is successfully found; - /// otherwise, false. + /// true if is successfully sent; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the data. - /// /// /// An array of that contains a binary data to send. /// - bool IServiceHost.SendTo (string id, byte [] data) + /// + /// A that contains an ID that represents the destination for the data. + /// + bool IWebSocketServiceHost.SendTo (byte [] data, string id) { - return _sessions.SendTo (id, data); + return _sessions.SendTo (data, id); } /// /// Sends a text data to the client associated with the specified ID. /// /// - /// true if the client associated with is successfully found; - /// otherwise, false. + /// true if is successfully sent; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the data. - /// /// /// A that contains a text data to send. /// - bool IServiceHost.SendTo (string id, string data) + /// + /// A that contains an ID that represents the destination for the data. + /// + bool IWebSocketServiceHost.SendTo (string data, string id) { - return _sessions.SendTo (id, data); + return _sessions.SendTo (data, id); } /// @@ -602,7 +589,7 @@ namespace WebSocketSharp.Server /// /// A that contains the reason for stop. /// - void IServiceHost.Stop (ushort code, string reason) + void IWebSocketServiceHost.Stop (ushort code, string reason) { base.Stop (); _sessions.Stop (code, reason); diff --git a/websocket-sharp/Server/WebSocketServiceHostManager.cs b/websocket-sharp/Server/WebSocketServiceHostManager.cs index c768b99c..0bd1fcf0 100644 --- a/websocket-sharp/Server/WebSocketServiceHostManager.cs +++ b/websocket-sharp/Server/WebSocketServiceHostManager.cs @@ -39,10 +39,10 @@ namespace WebSocketSharp.Server { #region Private Fields - private volatile bool _keepClean; - private Logger _logger; - private Dictionary _serviceHosts; - private object _sync; + private volatile bool _keepClean; + private Logger _logger; + private Dictionary _serviceHosts; + private object _sync; #endregion @@ -57,7 +57,7 @@ namespace WebSocketSharp.Server { _logger = logger; _keepClean = true; - _serviceHosts = new Dictionary (); + _serviceHosts = new Dictionary (); _sync = new object (); } @@ -133,7 +133,7 @@ namespace WebSocketSharp.Server } } - internal IEnumerable ServiceHosts { + internal IEnumerable ServiceHosts { get { lock (_sync) { @@ -146,11 +146,11 @@ namespace WebSocketSharp.Server #region Private Methods - private Dictionary copy () + private Dictionary copy () { lock (_sync) { - return new Dictionary (_serviceHosts); + return new Dictionary (_serviceHosts); } } @@ -158,15 +158,15 @@ namespace WebSocketSharp.Server #region Internal Methods - internal void Add (string servicePath, IServiceHost serviceHost) + internal void Add (string servicePath, IWebSocketServiceHost serviceHost) { lock (_sync) { - IServiceHost host; + IWebSocketServiceHost host; if (_serviceHosts.TryGetValue (servicePath, out host)) { _logger.Error ( - "The WebSocket service host with the specified path already exists.\npath: " + servicePath); + "The WebSocket service with the specified path already exists.\npath: " + servicePath); return; } @@ -176,13 +176,13 @@ namespace WebSocketSharp.Server internal bool Remove (string servicePath) { - IServiceHost host; + IWebSocketServiceHost host; lock (_sync) { if (!_serviceHosts.TryGetValue (servicePath, out host)) { _logger.Error ( - "The WebSocket service host with the specified path not found.\npath: " + servicePath); + "The WebSocket service with the specified path not found.\npath: " + servicePath); return false; } @@ -215,7 +215,7 @@ namespace WebSocketSharp.Server } } - internal bool TryGetServiceHost (string servicePath, out IServiceHost serviceHost) + internal bool TryGetServiceHost (string servicePath, out IWebSocketServiceHost serviceHost) { lock (_sync) { @@ -290,7 +290,7 @@ namespace WebSocketSharp.Server return false; } - IServiceHost host; + IWebSocketServiceHost host; if (!TryGetServiceHost (servicePath, out host)) { _logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath); @@ -328,7 +328,7 @@ namespace WebSocketSharp.Server return false; } - IServiceHost host; + IWebSocketServiceHost host; if (!TryGetServiceHost (servicePath, out host)) { _logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath); @@ -401,7 +401,7 @@ namespace WebSocketSharp.Server return null; } - IServiceHost host; + IWebSocketServiceHost host; if (!TryGetServiceHost (servicePath, out host)) { _logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath); @@ -429,7 +429,7 @@ namespace WebSocketSharp.Server return -1; } - IServiceHost host; + IWebSocketServiceHost host; if (!TryGetServiceHost (servicePath, out host)) { _logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath); @@ -458,16 +458,11 @@ namespace WebSocketSharp.Server /// public bool PingTo (string message, string id, string servicePath) { - if (message == null) - message = String.Empty; - - var msg = Encoding.UTF8.GetBytes (message).Length > 125 - ? "The payload length of a Ping frame must be 125 bytes or less." - : id.IsNullOrEmpty () - ? "'id' must not be null or empty." - : servicePath.IsNullOrEmpty () - ? "'servicePath' must not be null or empty." - : null; + var msg = id.IsNullOrEmpty () + ? "'id' must not be null or empty." + : servicePath.IsNullOrEmpty () + ? "'servicePath' must not be null or empty." + : null; if (msg != null) { @@ -475,14 +470,14 @@ namespace WebSocketSharp.Server return false; } - IServiceHost host; + IWebSocketServiceHost host; if (!TryGetServiceHost (servicePath, out host)) { _logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath); return false; } - return host.PingTo (id, message); + return host.PingTo (message, id); } /// @@ -517,14 +512,14 @@ namespace WebSocketSharp.Server return false; } - IServiceHost host; + IWebSocketServiceHost host; if (!TryGetServiceHost (servicePath, out host)) { _logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath); return false; } - return host.SendTo (id, data); + return host.SendTo (data, id); } /// @@ -559,14 +554,14 @@ namespace WebSocketSharp.Server return false; } - IServiceHost host; + IWebSocketServiceHost host; if (!TryGetServiceHost (servicePath, out host)) { _logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath); return false; } - return host.SendTo (id, data); + return host.SendTo (data, id); } #endregion diff --git a/websocket-sharp/Server/WebSocketServiceManager.cs b/websocket-sharp/Server/WebSocketServiceManager.cs index 5e00e287..a49078a5 100644 --- a/websocket-sharp/Server/WebSocketServiceManager.cs +++ b/websocket-sharp/Server/WebSocketServiceManager.cs @@ -361,12 +361,12 @@ namespace WebSocketSharp.Server } /// - /// Sends Pings with the specified to the clients of every + /// Sends Pings with the specified to the clients of every /// instances managed by the . /// /// - /// A Dictionary<string, bool> that contains the collection of IDs and values indicating - /// whether each instances received a Pong in a time. + /// A Dictionary<string, bool> that contains the collection of pairs of session ID and value + /// indicating whether the each instance received a Pong in a time. /// /// /// A that contains a message to send. @@ -381,28 +381,30 @@ namespace WebSocketSharp.Server } /// - /// Sends a Ping with the specified to the client of the - /// instance with the specified ID. + /// Sends a Ping with the specified to the client of + /// the instance with the specified ID. /// /// - /// true if the instance receives a Pong in a time; - /// otherwise, false. + /// true if the instance with receives + /// a Pong in a time; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the Ping. - /// /// /// A that contains a message to send. /// - internal bool PingTo (string id, string message) + /// + /// A that contains an ID that represents the destination for the Ping. + /// + internal bool PingTo (string message, string id) { WebSocketService service; - if (TryGetServiceInstance (id, out service)) - return service.Ping (message); + if (!TryGetServiceInstance (id, out service)) + { + _logger.Error ( + "The WebSocket service instance with the specified ID not found.\nID: " + id); + return false; + } - _logger.Error ( - "The WebSocket service instance with the specified ID not found.\nID: " + id); - return false; + return service.Ping (message); } internal bool Remove (string id) @@ -418,27 +420,26 @@ namespace WebSocketSharp.Server /// with the specified ID. /// /// - /// true if the instance with - /// is successfully found; otherwise, false. + /// true if is successfully sent; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the data. - /// /// /// An array of that contains a binary data to send. /// - internal bool SendTo (string id, byte [] data) + /// + /// A that contains an ID that represents the destination for the data. + /// + internal bool SendTo (byte [] data, string id) { WebSocketService service; - if (TryGetServiceInstance (id, out service)) + if (!TryGetServiceInstance (id, out service)) { - service.Send (data); - return true; + _logger.Error ( + "The WebSocket service instance with the specified ID not found.\nID: " + id); + return false; } - _logger.Error ( - "The WebSocket service instance with the specified ID not found.\nID: " + id); - return false; + service.Send (data); + return true; } /// @@ -446,27 +447,26 @@ namespace WebSocketSharp.Server /// with the specified ID. /// /// - /// true if the instance with - /// is successfully found; otherwise, false. + /// true if is successfully sent; otherwise, false. /// - /// - /// A that contains an ID that represents the destination for the data. - /// /// /// A that contains a text data to send. /// - internal bool SendTo (string id, string data) + /// + /// A that contains an ID that represents the destination for the data. + /// + internal bool SendTo (string data, string id) { WebSocketService service; - if (TryGetServiceInstance (id, out service)) + if (!TryGetServiceInstance (id, out service)) { - service.Send (data); - return true; + _logger.Error ( + "The WebSocket service instance with the specified ID not found.\nID: " + id); + return false; } - _logger.Error ( - "The WebSocket service instance with the specified ID not found.\nID: " + id); - return false; + service.Send (data); + return true; } internal void Stop () @@ -499,10 +499,7 @@ namespace WebSocketSharp.Server lock (_sync) { if (_stopped) - { - _sweeping = false; - return; - } + break; WebSocketService service; if (_services.TryGetValue (id, out service)) diff --git a/websocket-sharp/websocket-sharp.csproj b/websocket-sharp/websocket-sharp.csproj index cc1147e0..7d778d9a 100644 --- a/websocket-sharp/websocket-sharp.csproj +++ b/websocket-sharp/websocket-sharp.csproj @@ -100,7 +100,6 @@ - @@ -128,6 +127,7 @@ +