Renamed IServiceHost.cs to IWebSocketServiceHost.cs

This commit is contained in:
sta 2013-08-29 11:58:03 +09:00
parent b3fa68d8ce
commit 9daaa33111
8 changed files with 202 additions and 234 deletions

View File

@ -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;

View File

@ -1,6 +1,6 @@
#region License
/*
* IServiceHost.cs
* IWebSocketServiceHost.cs
*
* The MIT License
*
@ -35,9 +35,7 @@ namespace WebSocketSharp.Server
/// <summary>
/// Exposes the methods and properties for the WebSocket service host.
/// </summary>
/// <remarks>
/// </remarks>
public interface IServiceHost
public interface IWebSocketServiceHost
{
/// <summary>
/// Gets the connection count to the WebSocket service host.
@ -82,11 +80,12 @@ namespace WebSocketSharp.Server
void Broadcast (string data);
/// <summary>
/// Sends Pings with the specified <see cref="string"/> to all clients of the WebSocket service host.
/// Sends Pings with the specified <paramref name="message"/> to all clients of
/// the WebSocket service host.
/// </summary>
/// <returns>
/// A Dictionary&lt;string, bool&gt; 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&lt;string, bool&gt; 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.
/// </returns>
/// <param name="message">
/// A <see cref="string"/> that contains a message to send.
@ -94,50 +93,48 @@ namespace WebSocketSharp.Server
Dictionary<string, bool> Broadping (string message);
/// <summary>
/// Sends a Ping with the specified <see cref="string"/> to the client associated with
/// Sends a Ping with the specified <paramref name="message"/> to the client associated with
/// the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the WebSocket service host receives a Pong from the client in a time;
/// otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the Ping.
/// </param>
/// <param name="message">
/// A <see cref="string"/> that contains a message to send.
/// </param>
bool PingTo (string id, string message);
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the Ping.
/// </param>
bool PingTo (string message, string id);
/// <summary>
/// Sends a binary data to the client associated with the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the client associated with <paramref name="id"/> is successfully found;
/// otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
/// <param name="data">
/// An array of <see cref="byte"/> that contains a binary data to send.
/// </param>
bool SendTo (string id, byte [] data);
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
bool SendTo (byte [] data, string id);
/// <summary>
/// Sends a text data to the client associated with the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the client associated with <paramref name="id"/> is successfully found;
/// otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
/// <param name="data">
/// A <see cref="string"/> that contains a text data to send.
/// </param>
bool SendTo (string id, string data);
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
bool SendTo (string data, string id);
/// <summary>
/// Starts the WebSocket service host.

View File

@ -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);

View File

@ -349,8 +349,8 @@ namespace WebSocketSharp.Server
/// in the <see cref="WebSocketService.Sessions"/>.
/// </summary>
/// <returns>
/// A Dictionary&lt;string, bool&gt; that contains the collection of IDs and values indicating
/// whether the each <see cref="WebSocketService"/> instances received a Pong in a time.
/// A Dictionary&lt;string, bool&gt; that contains the collection of pairs of session ID and value
/// indicating whether the each <see cref="WebSocketService"/> instance received a Pong in a time.
/// </returns>
public virtual Dictionary<string, bool> Broadping ()
{
@ -360,12 +360,12 @@ namespace WebSocketSharp.Server
}
/// <summary>
/// Sends Pings with the specified <see cref="string"/> to the clients of every <see cref="WebSocketService"/>
/// Sends Pings with the specified <paramref name="message"/> to the clients of every <see cref="WebSocketService"/>
/// instances in the <see cref="WebSocketService.Sessions"/>.
/// </summary>
/// <returns>
/// A Dictionary&lt;string, bool&gt; that contains the collection of IDs and values
/// indicating whether the each <see cref="WebSocketService"/> instances received a Pong in a time.
/// A Dictionary&lt;string, bool&gt; that contains the collection of pairs of session ID and value
/// indicating whether the each <see cref="WebSocketService"/> instance received a Pong in a time.
/// </returns>
/// <param name="message">
/// A <see cref="string"/> that contains a message to send.
@ -406,7 +406,7 @@ namespace WebSocketSharp.Server
}
/// <summary>
/// Sends a Ping with the specified <see cref="string"/> to the client of
/// Sends a Ping with the specified <paramref name="message"/> to the client of
/// the current <see cref="WebSocketService"/> instance.
/// </summary>
/// <returns>
@ -428,54 +428,46 @@ namespace WebSocketSharp.Server
/// with the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the <see cref="WebSocketService"/> instance receives a Pong in a time;
/// otherwise, <c>false</c>.
/// <c>true</c> if the <see cref="WebSocketService"/> instance with <paramref name="id"/> receives
/// a Pong in a time; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the Ping.
/// </param>
public virtual bool PingTo (string id)
{
return PingTo (id, String.Empty);
return PingTo (String.Empty, id);
}
/// <summary>
/// Sends a Ping with the specified <see cref="string"/> to the client of the <see cref="WebSocketService"/>
/// instance with the specified ID.
/// Sends a Ping with the specified <paramref name="message"/> to the client of
/// the <see cref="WebSocketService"/> instance with the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the <see cref="WebSocketService"/> instance receives a Pong in a time;
/// otherwise, <c>false</c>.
/// <c>true</c> if the <see cref="WebSocketService"/> instance with <paramref name="id"/> receives
/// a Pong in a time; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the Ping.
/// </param>
/// <param name="message">
/// A <see cref="string"/> that contains a message to send.
/// </param>
public virtual bool PingTo (string id, string message)
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the Ping.
/// </param>
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);
}
/// <summary>
@ -507,26 +499,26 @@ namespace WebSocketSharp.Server
/// with the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the client is successfully found; otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
/// <param name="data">
/// An array of <see cref="byte"/> that contains a binary data to send.
/// </param>
public virtual bool SendTo (string id, byte [] data)
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
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);
}
/// <summary>
@ -542,26 +534,26 @@ namespace WebSocketSharp.Server
/// with the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the client is successfully found; otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
/// <param name="data">
/// A <see cref="string"/> that contains a text data to send.
/// </param>
public virtual bool SendTo (string id, string data)
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
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);
}
/// <summary>
/// Starts a <see cref="WebSocketService"/> instance.
/// Starts the current <see cref="WebSocketService"/> instance.
/// </summary>
public void Start ()
{

View File

@ -47,7 +47,7 @@ namespace WebSocketSharp.Server
/// The type of the WebSocket service that the server provides.
/// The T must inherit the <see cref="WebSocketService"/> class.
/// </typeparam>
public class WebSocketServiceHost<T> : WebSocketServerBase, IServiceHost
public class WebSocketServiceHost<T> : WebSocketServerBase, IWebSocketServiceHost
where T : WebSocketService, new ()
{
#region Private Fields
@ -267,20 +267,20 @@ namespace WebSocketSharp.Server
/// </param>
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
}
/// <summary>
/// Sends Pings with the specified <see cref="string"/> to all clients.
/// Sends Pings with the specified <paramref name="message"/> to all clients.
/// </summary>
/// <returns>
/// A Dictionary&lt;string, bool&gt; 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&lt;string, bool&gt; 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.
/// </returns>
/// <param name="message">
/// A <see cref="string"/> that contains a message to send.
@ -347,58 +347,48 @@ namespace WebSocketSharp.Server
}
/// <summary>
/// Sends a Ping with the specified <see cref="string"/> to the client associated with
/// Sends a Ping with the specified <paramref name="message"/> to the client associated with
/// the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the service host receives a Pong from the client in a time; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the Ping.
/// </param>
/// <param name="message">
/// A <see cref="string"/> that contains a message to send.
/// </param>
public bool PingTo (string id, string message)
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the Ping.
/// </param>
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);
}
/// <summary>
/// Sends a binary data to the client associated with the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the client associated with <paramref name="id"/> is successfully found;
/// otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
/// <param name="data">
/// An array of <see cref="byte"/> that contains a binary data to send.
/// </param>
public bool SendTo (string id, byte [] data)
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
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);
}
/// <summary>
/// Sends a text data to the client associated with the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the client associated with <paramref name="id"/> is successfully found;
/// otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
/// <param name="data">
/// A <see cref="string"/> that contains a text data to send.
/// </param>
public bool SendTo (string id, string data)
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
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);
}
/// <summary>
@ -494,7 +483,7 @@ namespace WebSocketSharp.Server
/// <param name="context">
/// A <see cref="WebSocketContext"/> that contains the WebSocket connection request objects to bind.
/// </param>
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
/// <param name="data">
/// An array of <see cref="byte"/> to broadcast.
/// </param>
void IServiceHost.Broadcast (byte [] data)
void IWebSocketServiceHost.Broadcast (byte [] data)
{
_sessions.Broadcast (data);
}
@ -518,78 +507,76 @@ namespace WebSocketSharp.Server
/// <param name="data">
/// A <see cref="string"/> to broadcast.
/// </param>
void IServiceHost.Broadcast (string data)
void IWebSocketServiceHost.Broadcast (string data)
{
_sessions.Broadcast (data);
}
/// <summary>
/// Sends Pings with the specified <see cref="string"/> to all clients.
/// Sends Pings with the specified <paramref name="message"/> to all clients.
/// </summary>
/// <returns>
/// A Dictionary&lt;string, bool&gt; 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&lt;string, bool&gt; 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.
/// </returns>
/// <param name="message">
/// A <see cref="string"/> that contains a message to send.
/// </param>
Dictionary<string, bool> IServiceHost.Broadping (string message)
Dictionary<string, bool> IWebSocketServiceHost.Broadping (string message)
{
return _sessions.Broadping (message);
}
/// <summary>
/// Sends a Ping with the specified <see cref="string"/> to the client associated with
/// Sends a Ping with the specified <paramref name="message"/> to the client associated with
/// the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the service host receives a Pong from the client in a time; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the Ping.
/// </param>
/// <param name="message">
/// A <see cref="string"/> that contains a message to send.
/// </param>
bool IServiceHost.PingTo (string id, string message)
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the Ping.
/// </param>
bool IWebSocketServiceHost.PingTo (string message, string id)
{
return _sessions.PingTo (id, message);
return _sessions.PingTo (message, id);
}
/// <summary>
/// Sends a binary data to the client associated with the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the client associated with <paramref name="id"/> is successfully found;
/// otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
/// <param name="data">
/// An array of <see cref="byte"/> that contains a binary data to send.
/// </param>
bool IServiceHost.SendTo (string id, byte [] data)
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
bool IWebSocketServiceHost.SendTo (byte [] data, string id)
{
return _sessions.SendTo (id, data);
return _sessions.SendTo (data, id);
}
/// <summary>
/// Sends a text data to the client associated with the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the client associated with <paramref name="id"/> is successfully found;
/// otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
/// <param name="data">
/// A <see cref="string"/> that contains a text data to send.
/// </param>
bool IServiceHost.SendTo (string id, string data)
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
bool IWebSocketServiceHost.SendTo (string data, string id)
{
return _sessions.SendTo (id, data);
return _sessions.SendTo (data, id);
}
/// <summary>
@ -602,7 +589,7 @@ namespace WebSocketSharp.Server
/// <param name="reason">
/// A <see cref="string"/> that contains the reason for stop.
/// </param>
void IServiceHost.Stop (ushort code, string reason)
void IWebSocketServiceHost.Stop (ushort code, string reason)
{
base.Stop ();
_sessions.Stop (code, reason);

View File

@ -39,10 +39,10 @@ namespace WebSocketSharp.Server
{
#region Private Fields
private volatile bool _keepClean;
private Logger _logger;
private Dictionary<string, IServiceHost> _serviceHosts;
private object _sync;
private volatile bool _keepClean;
private Logger _logger;
private Dictionary<string, IWebSocketServiceHost> _serviceHosts;
private object _sync;
#endregion
@ -57,7 +57,7 @@ namespace WebSocketSharp.Server
{
_logger = logger;
_keepClean = true;
_serviceHosts = new Dictionary<string, IServiceHost> ();
_serviceHosts = new Dictionary<string, IWebSocketServiceHost> ();
_sync = new object ();
}
@ -133,7 +133,7 @@ namespace WebSocketSharp.Server
}
}
internal IEnumerable<IServiceHost> ServiceHosts {
internal IEnumerable<IWebSocketServiceHost> ServiceHosts {
get {
lock (_sync)
{
@ -146,11 +146,11 @@ namespace WebSocketSharp.Server
#region Private Methods
private Dictionary<string, IServiceHost> copy ()
private Dictionary<string, IWebSocketServiceHost> copy ()
{
lock (_sync)
{
return new Dictionary<string, IServiceHost> (_serviceHosts);
return new Dictionary<string, IWebSocketServiceHost> (_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
/// </param>
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);
}
/// <summary>
@ -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);
}
/// <summary>
@ -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

View File

@ -361,12 +361,12 @@ namespace WebSocketSharp.Server
}
/// <summary>
/// Sends Pings with the specified <see cref="string"/> to the clients of every
/// Sends Pings with the specified <paramref name="message"/> to the clients of every
/// <see cref="WebSocketService"/> instances managed by the <see cref="WebSocketServiceManager"/>.
/// </summary>
/// <returns>
/// A Dictionary&lt;string, bool&gt; that contains the collection of IDs and values indicating
/// whether each <see cref="WebSocketService"/> instances received a Pong in a time.
/// A Dictionary&lt;string, bool&gt; that contains the collection of pairs of session ID and value
/// indicating whether the each <see cref="WebSocketService"/> instance received a Pong in a time.
/// </returns>
/// <param name="message">
/// A <see cref="string"/> that contains a message to send.
@ -381,28 +381,30 @@ namespace WebSocketSharp.Server
}
/// <summary>
/// Sends a Ping with the specified <see cref="string"/> to the client of the <see cref="WebSocketService"/>
/// instance with the specified ID.
/// Sends a Ping with the specified <paramref name="message"/> to the client of
/// the <see cref="WebSocketService"/> instance with the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the <see cref="WebSocketService"/> instance receives a Pong in a time;
/// otherwise, <c>false</c>.
/// <c>true</c> if the <see cref="WebSocketService"/> instance with <paramref name="id"/> receives
/// a Pong in a time; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the Ping.
/// </param>
/// <param name="message">
/// A <see cref="string"/> that contains a message to send.
/// </param>
internal bool PingTo (string id, string message)
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the Ping.
/// </param>
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.
/// </summary>
/// <returns>
/// <c>true</c> if the <see cref="WebSocketService"/> instance with <paramref name="id"/>
/// is successfully found; otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
/// <param name="data">
/// An array of <see cref="byte"/> that contains a binary data to send.
/// </param>
internal bool SendTo (string id, byte [] data)
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
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;
}
/// <summary>
@ -446,27 +447,26 @@ namespace WebSocketSharp.Server
/// with the specified ID.
/// </summary>
/// <returns>
/// <c>true</c> if the <see cref="WebSocketService"/> instance with <paramref name="id"/>
/// is successfully found; otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
/// </returns>
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
/// <param name="data">
/// A <see cref="string"/> that contains a text data to send.
/// </param>
internal bool SendTo (string id, string data)
/// <param name="id">
/// A <see cref="string"/> that contains an ID that represents the destination for the data.
/// </param>
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))

View File

@ -100,7 +100,6 @@
<Compile Include="Net\HttpStatusCode.cs" />
<Compile Include="Server\WebSocketServerBase.cs" />
<Compile Include="Net\Security\SslStream.cs" />
<Compile Include="Server\IServiceHost.cs" />
<Compile Include="Server\WebSocketServiceHost.cs" />
<Compile Include="CloseStatusCode.cs" />
<Compile Include="Fin.cs" />
@ -128,6 +127,7 @@
<Compile Include="HandshakeRequest.cs" />
<Compile Include="HandshakeResponse.cs" />
<Compile Include="Server\WebSocketServiceHostManager.cs" />
<Compile Include="Server\IWebSocketServiceHost.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>