Modified SendTo and BroadcastTo methods
This commit is contained in:
parent
133ff88b0d
commit
f103cd2faf
@ -359,66 +359,58 @@ namespace WebSocketSharp.Server
|
|||||||
/// Broadcasts the specified array of <see cref="byte"/> to all clients of the WebSocket service
|
/// Broadcasts the specified array of <see cref="byte"/> to all clients of the WebSocket service
|
||||||
/// with the specified <paramref name="servicePath"/>.
|
/// with the specified <paramref name="servicePath"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
|
||||||
/// <c>true</c> if <paramref name="data"/> is broadcasted; otherwise, <c>false</c>.
|
|
||||||
/// </returns>
|
|
||||||
/// <param name="data">
|
/// <param name="data">
|
||||||
/// An array of <see cref="byte"/> to broadcast.
|
/// An array of <see cref="byte"/> to broadcast.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="servicePath">
|
/// <param name="servicePath">
|
||||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||||
/// </param>
|
/// </param>
|
||||||
public bool BroadcastTo (byte [] data, string servicePath)
|
public void BroadcastTo (byte [] data, string servicePath)
|
||||||
{
|
{
|
||||||
var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData () ?? servicePath.CheckIfValidServicePath ();
|
var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData () ?? servicePath.CheckIfValidServicePath ();
|
||||||
if (msg != null)
|
if (msg != null)
|
||||||
{
|
{
|
||||||
_logger.Error (msg);
|
_logger.Error (msg);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IWebSocketServiceHost host;
|
IWebSocketServiceHost host;
|
||||||
if (!TryGetServiceHostInternally (servicePath, out host))
|
if (!TryGetServiceHostInternally (servicePath, out host))
|
||||||
{
|
{
|
||||||
_logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath);
|
_logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
host.Sessions.BroadcastInternally (data);
|
host.Sessions.BroadcastInternally (data);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Broadcasts the specified <see cref="string"/> to all clients of the WebSocket service
|
/// Broadcasts the specified <see cref="string"/> to all clients of the WebSocket service
|
||||||
/// with the specified <paramref name="servicePath"/>.
|
/// with the specified <paramref name="servicePath"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
|
||||||
/// <c>true</c> if <paramref name="data"/> is broadcasted; otherwise, <c>false</c>.
|
|
||||||
/// </returns>
|
|
||||||
/// <param name="data">
|
/// <param name="data">
|
||||||
/// A <see cref="string"/> to broadcast.
|
/// A <see cref="string"/> to broadcast.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="servicePath">
|
/// <param name="servicePath">
|
||||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||||
/// </param>
|
/// </param>
|
||||||
public bool BroadcastTo (string data, string servicePath)
|
public void BroadcastTo (string data, string servicePath)
|
||||||
{
|
{
|
||||||
var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData () ?? servicePath.CheckIfValidServicePath ();
|
var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData () ?? servicePath.CheckIfValidServicePath ();
|
||||||
if (msg != null)
|
if (msg != null)
|
||||||
{
|
{
|
||||||
_logger.Error (msg);
|
_logger.Error (msg);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IWebSocketServiceHost host;
|
IWebSocketServiceHost host;
|
||||||
if (!TryGetServiceHostInternally (servicePath, out host))
|
if (!TryGetServiceHostInternally (servicePath, out host))
|
||||||
{
|
{
|
||||||
_logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath);
|
_logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
host.Sessions.BroadcastInternally (data);
|
host.Sessions.BroadcastInternally (data);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -710,9 +702,6 @@ namespace WebSocketSharp.Server
|
|||||||
/// Sends a binary <paramref name="data"/> to the client associated with the specified
|
/// Sends a binary <paramref name="data"/> to the client associated with the specified
|
||||||
/// <paramref name="id"/> and <paramref name="servicePath"/>.
|
/// <paramref name="id"/> and <paramref name="servicePath"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
|
||||||
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
|
|
||||||
/// </returns>
|
|
||||||
/// <param name="data">
|
/// <param name="data">
|
||||||
/// An array of <see cref="byte"/> that contains a binary data to send.
|
/// An array of <see cref="byte"/> that contains a binary data to send.
|
||||||
/// </param>
|
/// </param>
|
||||||
@ -722,32 +711,29 @@ namespace WebSocketSharp.Server
|
|||||||
/// <param name="servicePath">
|
/// <param name="servicePath">
|
||||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||||
/// </param>
|
/// </param>
|
||||||
public bool SendTo (byte [] data, string id, string servicePath)
|
public void SendTo (byte [] data, string id, string servicePath)
|
||||||
{
|
{
|
||||||
var msg = _state.CheckIfStarted () ?? servicePath.CheckIfValidServicePath ();
|
var msg = _state.CheckIfStarted () ?? servicePath.CheckIfValidServicePath ();
|
||||||
if (msg != null)
|
if (msg != null)
|
||||||
{
|
{
|
||||||
_logger.Error (msg);
|
_logger.Error (msg);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IWebSocketServiceHost host;
|
IWebSocketServiceHost host;
|
||||||
if (!TryGetServiceHostInternally (servicePath, out host))
|
if (!TryGetServiceHostInternally (servicePath, out host))
|
||||||
{
|
{
|
||||||
_logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath);
|
_logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return host.Sessions.SendTo (data, id);
|
host.Sessions.SendTo (data, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a text <paramref name="data"/> to the client associated with the specified
|
/// Sends a text <paramref name="data"/> to the client associated with the specified
|
||||||
/// <paramref name="id"/> and <paramref name="servicePath"/>.
|
/// <paramref name="id"/> and <paramref name="servicePath"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
|
||||||
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
|
|
||||||
/// </returns>
|
|
||||||
/// <param name="data">
|
/// <param name="data">
|
||||||
/// A <see cref="string"/> that contains a text data to send.
|
/// A <see cref="string"/> that contains a text data to send.
|
||||||
/// </param>
|
/// </param>
|
||||||
@ -757,23 +743,23 @@ namespace WebSocketSharp.Server
|
|||||||
/// <param name="servicePath">
|
/// <param name="servicePath">
|
||||||
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
/// A <see cref="string"/> that contains an absolute path to the WebSocket service to find.
|
||||||
/// </param>
|
/// </param>
|
||||||
public bool SendTo (string data, string id, string servicePath)
|
public void SendTo (string data, string id, string servicePath)
|
||||||
{
|
{
|
||||||
var msg = _state.CheckIfStarted () ?? servicePath.CheckIfValidServicePath ();
|
var msg = _state.CheckIfStarted () ?? servicePath.CheckIfValidServicePath ();
|
||||||
if (msg != null)
|
if (msg != null)
|
||||||
{
|
{
|
||||||
_logger.Error (msg);
|
_logger.Error (msg);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IWebSocketServiceHost host;
|
IWebSocketServiceHost host;
|
||||||
if (!TryGetServiceHostInternally (servicePath, out host))
|
if (!TryGetServiceHostInternally (servicePath, out host))
|
||||||
{
|
{
|
||||||
_logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath);
|
_logger.Error ("The WebSocket service with the specified path not found.\npath: " + servicePath);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return host.Sessions.SendTo (data, id);
|
host.Sessions.SendTo (data, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -586,66 +586,58 @@ namespace WebSocketSharp.Server
|
|||||||
/// Sends a binary <paramref name="data"/> to the client associated with the specified
|
/// Sends a binary <paramref name="data"/> to the client associated with the specified
|
||||||
/// <paramref name="id"/>.
|
/// <paramref name="id"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
|
||||||
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
|
|
||||||
/// </returns>
|
|
||||||
/// <param name="data">
|
/// <param name="data">
|
||||||
/// An array of <see cref="byte"/> that contains a binary data to send.
|
/// An array of <see cref="byte"/> that contains a binary data to send.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="id">
|
/// <param name="id">
|
||||||
/// A <see cref="string"/> that contains a session ID that represents the destination for the data.
|
/// A <see cref="string"/> that contains a session ID that represents the destination for the data.
|
||||||
/// </param>
|
/// </param>
|
||||||
public bool SendTo (byte [] data, string id)
|
public void SendTo (byte [] data, string id)
|
||||||
{
|
{
|
||||||
var msg = _state.CheckIfStarted () ?? id.CheckIfValidSessionID ();
|
var msg = _state.CheckIfStarted () ?? id.CheckIfValidSessionID ();
|
||||||
if (msg != null)
|
if (msg != null)
|
||||||
{
|
{
|
||||||
_logger.Error (msg);
|
_logger.Error (msg);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketService service;
|
WebSocketService service;
|
||||||
if (!TryGetServiceInstance (id, out service))
|
if (!TryGetServiceInstance (id, out service))
|
||||||
{
|
{
|
||||||
_logger.Error ("The WebSocket session with the specified ID not found.\nID: " + id);
|
_logger.Error ("The WebSocket session with the specified ID not found.\nID: " + id);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
service.Send (data);
|
service.Send (data);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a text <paramref name="data"/> to the client associated with the specified
|
/// Sends a text <paramref name="data"/> to the client associated with the specified
|
||||||
/// <paramref name="id"/>.
|
/// <paramref name="id"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
|
||||||
/// <c>true</c> if <paramref name="data"/> is successfully sent; otherwise, <c>false</c>.
|
|
||||||
/// </returns>
|
|
||||||
/// <param name="data">
|
/// <param name="data">
|
||||||
/// A <see cref="string"/> that contains a text data to send.
|
/// A <see cref="string"/> that contains a text data to send.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="id">
|
/// <param name="id">
|
||||||
/// A <see cref="string"/> that contains a session ID that represents the destination for the data.
|
/// A <see cref="string"/> that contains a session ID that represents the destination for the data.
|
||||||
/// </param>
|
/// </param>
|
||||||
public bool SendTo (string data, string id)
|
public void SendTo (string data, string id)
|
||||||
{
|
{
|
||||||
var msg = _state.CheckIfStarted () ?? id.CheckIfValidSessionID ();
|
var msg = _state.CheckIfStarted () ?? id.CheckIfValidSessionID ();
|
||||||
if (msg != null)
|
if (msg != null)
|
||||||
{
|
{
|
||||||
_logger.Error (msg);
|
_logger.Error (msg);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketService service;
|
WebSocketService service;
|
||||||
if (!TryGetServiceInstance (id, out service))
|
if (!TryGetServiceInstance (id, out service))
|
||||||
{
|
{
|
||||||
_logger.Error ("The WebSocket session with the specified ID not found.\nID: " + id);
|
_logger.Error ("The WebSocket session with the specified ID not found.\nID: " + id);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
service.Send (data);
|
service.Send (data);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user