Modified checking if can send
This commit is contained in:
		@@ -223,18 +223,24 @@ namespace WebSocketSharp
 | 
			
		||||
                 : null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    internal static string CheckIfStarted (this ServerState state)
 | 
			
		||||
    internal static string CheckIfStart (this ServerState state)
 | 
			
		||||
    {
 | 
			
		||||
      return state != ServerState.START
 | 
			
		||||
             ? "Any of not started, on shutdown or stopped."
 | 
			
		||||
             : null;
 | 
			
		||||
      return state == ServerState.READY
 | 
			
		||||
             ? "The server hasn't started yet."
 | 
			
		||||
             : state == ServerState.SHUTDOWN
 | 
			
		||||
               ? "The server is shutting down."
 | 
			
		||||
               : state == ServerState.STOP
 | 
			
		||||
                 ? "The server has already stopped."
 | 
			
		||||
                 : null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    internal static string CheckIfStopped (this ServerState state)
 | 
			
		||||
    {
 | 
			
		||||
      return state == ServerState.START || state == ServerState.SHUTDOWN
 | 
			
		||||
             ? "Already started or on shutdown."
 | 
			
		||||
             : null;
 | 
			
		||||
      return state == ServerState.START
 | 
			
		||||
             ? "The server has already started."
 | 
			
		||||
             : state == ServerState.SHUTDOWN
 | 
			
		||||
               ? "The server is shutting down."
 | 
			
		||||
               : null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    internal static string CheckIfValidCloseStatusCode (this ushort code)
 | 
			
		||||
@@ -259,6 +265,13 @@ namespace WebSocketSharp
 | 
			
		||||
             : null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    internal static string CheckIfValidSendData (this FileInfo file)
 | 
			
		||||
    {
 | 
			
		||||
      return file == null
 | 
			
		||||
             ? "'file' must not be null."
 | 
			
		||||
             : null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    internal static string CheckIfValidSendData (this string data)
 | 
			
		||||
    {
 | 
			
		||||
      return data == null
 | 
			
		||||
 
 | 
			
		||||
@@ -537,7 +537,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
 | 
			
		||||
    private string checkIfCanStop (Func<string> checkParams)
 | 
			
		||||
    {
 | 
			
		||||
      return _state.CheckIfStarted () ?? checkParams ();
 | 
			
		||||
      return _state.CheckIfStart () ?? checkParams ();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private string checkIfCertExists ()
 | 
			
		||||
@@ -742,7 +742,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    public void Stop ()
 | 
			
		||||
    {
 | 
			
		||||
      lock (_sync) {
 | 
			
		||||
        var msg = _state.CheckIfStarted ();
 | 
			
		||||
        var msg = _state.CheckIfStart ();
 | 
			
		||||
        if (msg != null) {
 | 
			
		||||
          _logger.Error (String.Format ("{0}\nstate: {1}", msg, _state));
 | 
			
		||||
          return;
 | 
			
		||||
 
 | 
			
		||||
@@ -551,7 +551,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
 | 
			
		||||
    private string checkIfCanStop (Func<string> checkParams)
 | 
			
		||||
    {
 | 
			
		||||
      return _state.CheckIfStarted () ?? checkParams ();
 | 
			
		||||
      return _state.CheckIfStart () ?? checkParams ();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private string checkIfCertExists ()
 | 
			
		||||
@@ -758,7 +758,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    public void Stop ()
 | 
			
		||||
    {
 | 
			
		||||
      lock (_sync) {
 | 
			
		||||
        var msg = _state.CheckIfStarted ();
 | 
			
		||||
        var msg = _state.CheckIfStart ();
 | 
			
		||||
        if (msg != null) {
 | 
			
		||||
          _logger.Error (String.Format ("{0}\nstate: {1}", msg, _state));
 | 
			
		||||
          return;
 | 
			
		||||
 
 | 
			
		||||
@@ -270,11 +270,11 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> to the client of the current
 | 
			
		||||
    /// <see cref="WebSocketService"/> instance.
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> to the client on the current
 | 
			
		||||
    /// session in the WebSocket service.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to send.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    protected void Send (byte [] data)
 | 
			
		||||
    {
 | 
			
		||||
@@ -283,11 +283,11 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary data from the specified <see cref="FileInfo"/> to
 | 
			
		||||
    /// the client of the current <see cref="WebSocketService"/> instance.
 | 
			
		||||
    /// Sends the specified <paramref name="file"/> as a binary data
 | 
			
		||||
    /// to the client on the current session in the WebSocket service.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="file">
 | 
			
		||||
    /// A <see cref="FileInfo"/> from which contains the binary data to send.
 | 
			
		||||
    /// A <see cref="FileInfo"/> that represents the file to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    protected void Send (FileInfo file)
 | 
			
		||||
    {
 | 
			
		||||
@@ -296,8 +296,8 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a text <paramref name="data"/> to the client of the current
 | 
			
		||||
    /// <see cref="WebSocketService"/> instance.
 | 
			
		||||
    /// Sends a text <paramref name="data"/> to the client on the current
 | 
			
		||||
    /// session in the WebSocket service.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// A <see cref="string"/> that represents the text data to send.
 | 
			
		||||
@@ -309,20 +309,19 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> asynchronously to the client of the
 | 
			
		||||
    /// current <see cref="WebSocketService"/> instance.
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> asynchronously to the client
 | 
			
		||||
    /// on the current session in the WebSocket service.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to send.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="completed">
 | 
			
		||||
    /// An Action<bool> delegate that references the method(s) called when
 | 
			
		||||
    /// the send is complete.
 | 
			
		||||
    /// A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
 | 
			
		||||
    /// complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// the send is complete. A <see cref="bool"/> passed to this delegate is
 | 
			
		||||
    /// <c>true</c> if the send is complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    protected void SendAsync (byte [] data, Action<bool> completed)
 | 
			
		||||
    {
 | 
			
		||||
@@ -331,21 +330,20 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary data from the specified <see cref="FileInfo"/>
 | 
			
		||||
    /// asynchronously to the client of the current <see cref="WebSocketService"/>
 | 
			
		||||
    /// instance.
 | 
			
		||||
    /// Sends the specified <paramref name="file"/> as a binary data
 | 
			
		||||
    /// asynchronously to the client on the current session in the WebSocket
 | 
			
		||||
    /// service.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <param name="file">
 | 
			
		||||
    /// A <see cref="FileInfo"/> from which contains the binary data to send.
 | 
			
		||||
    /// A <see cref="FileInfo"/> that represents the file to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="completed">
 | 
			
		||||
    /// An Action<bool> delegate that references the method(s) called when
 | 
			
		||||
    /// the send is complete.
 | 
			
		||||
    /// A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
 | 
			
		||||
    /// complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// the send is complete. A <see cref="bool"/> passed to this delegate is
 | 
			
		||||
    /// <c>true</c> if the send is complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    protected void SendAsync (FileInfo file, Action<bool> completed)
 | 
			
		||||
    {
 | 
			
		||||
@@ -354,8 +352,8 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a text <paramref name="data"/> asynchronously to the client of the
 | 
			
		||||
    /// current <see cref="WebSocketService"/> instance.
 | 
			
		||||
    /// Sends a text <paramref name="data"/> asynchronously to the client
 | 
			
		||||
    /// on the current session in the WebSocket service.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
@@ -365,9 +363,8 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="completed">
 | 
			
		||||
    /// An Action<bool> delegate that references the method(s) called when
 | 
			
		||||
    /// the send is complete.
 | 
			
		||||
    /// A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
 | 
			
		||||
    /// complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// the send is complete. A <see cref="bool"/> passed to this delegate is
 | 
			
		||||
    /// <c>true</c> if the send is complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    protected void SendAsync (string data, Action<bool> completed)
 | 
			
		||||
    {
 | 
			
		||||
@@ -377,22 +374,21 @@ namespace WebSocketSharp.Server
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary data from the specified <see cref="Stream"/> asynchronously
 | 
			
		||||
    /// to the client of the current <see cref="WebSocketService"/> instance.
 | 
			
		||||
    /// to the client on the current session in the WebSocket service.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <param name="stream">
 | 
			
		||||
    /// A <see cref="Stream"/> object from which contains the binary data to send.
 | 
			
		||||
    /// A <see cref="Stream"/> from which contains the binary data to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="length">
 | 
			
		||||
    /// An <see cref="int"/> that represents the number of bytes to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="completed">
 | 
			
		||||
    /// An Action<bool> delegate that references the method(s) called when
 | 
			
		||||
    /// the send is complete.
 | 
			
		||||
    /// A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
 | 
			
		||||
    /// complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// the send is complete. A <see cref="bool"/> passed to this delegate is
 | 
			
		||||
    /// <c>true</c> if the send is complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    protected void SendAsync (Stream stream, int length, Action<bool> completed)
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -263,6 +263,11 @@ namespace WebSocketSharp.Server
 | 
			
		||||
      return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private string checkIfCanSend (Func<string> checkParams)
 | 
			
		||||
    {
 | 
			
		||||
      return _state.CheckIfStart () ?? checkParams ();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #endregion
 | 
			
		||||
 | 
			
		||||
    #region Internal Methods
 | 
			
		||||
@@ -359,15 +364,16 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    #region Public Methods
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Broadcasts a binary <paramref name="data"/> to all clients of the
 | 
			
		||||
    /// WebSocket services provided by the server.
 | 
			
		||||
    /// Broadcasts a binary <paramref name="data"/> to all clients
 | 
			
		||||
    /// of the WebSocket services provided by the server.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to broadcast.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data
 | 
			
		||||
    /// to broadcast.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void Broadcast (byte [] data)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
 | 
			
		||||
      var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        return;
 | 
			
		||||
@@ -380,15 +386,15 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Broadcasts a text <paramref name="data"/> to all clients of the WebSocket
 | 
			
		||||
    /// services provided by the server.
 | 
			
		||||
    /// Broadcasts a text <paramref name="data"/> to all clients
 | 
			
		||||
    /// of the WebSocket services provided by the server.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// A <see cref="string"/> that represents the text data to broadcast.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void Broadcast (string data)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
 | 
			
		||||
      var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        return;
 | 
			
		||||
@@ -409,7 +415,8 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// This method doesn't wait for the broadcast to be complete.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to broadcast.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data
 | 
			
		||||
    /// to broadcast.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="completed">
 | 
			
		||||
    /// A <see cref="Action"/> delegate that references the method(s) called when
 | 
			
		||||
@@ -417,7 +424,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void BroadcastAsync (byte [] data, Action completed)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
 | 
			
		||||
      var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        return;
 | 
			
		||||
@@ -430,8 +437,8 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Broadcasts a text <paramref name="data"/> asynchronously to all clients of
 | 
			
		||||
    /// the WebSocket services provided by the server.
 | 
			
		||||
    /// Broadcasts a text <paramref name="data"/> asynchronously to all clients
 | 
			
		||||
    /// of the WebSocket services provided by the server.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the broadcast to be complete.
 | 
			
		||||
@@ -445,7 +452,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void BroadcastAsync (string data, Action completed)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
 | 
			
		||||
      var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        return;
 | 
			
		||||
@@ -460,15 +467,14 @@ namespace WebSocketSharp.Server
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Broadcasts a binary data from the specified <see cref="Stream"/>
 | 
			
		||||
    /// asynchronously to all clients of the WebSocket services provided by the
 | 
			
		||||
    /// server.
 | 
			
		||||
    /// asynchronously to all clients of the WebSocket services provided
 | 
			
		||||
    /// by the server.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the broadcast to be complete.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <param name="stream">
 | 
			
		||||
    /// A <see cref="Stream"/> object from which contains the binary data to
 | 
			
		||||
    /// broadcast.
 | 
			
		||||
    /// A <see cref="Stream"/> from which contains the binary data to broadcast.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="length">
 | 
			
		||||
    /// An <see cref="int"/> that represents the number of bytes to broadcast.
 | 
			
		||||
@@ -479,9 +485,9 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void BroadcastAsync (Stream stream, int length, Action completed)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted () ??
 | 
			
		||||
                stream.CheckIfCanRead () ??
 | 
			
		||||
                (length < 1 ? "'length' must be greater than 0." : null);
 | 
			
		||||
      var msg = checkIfCanSend (
 | 
			
		||||
        () => stream.CheckIfCanRead () ??
 | 
			
		||||
              (length < 1 ? "'length' must be greater than 0." : null));
 | 
			
		||||
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
@@ -521,7 +527,8 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// service to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to broadcast.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data
 | 
			
		||||
    /// to broadcast.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void BroadcastTo (string servicePath, byte [] data)
 | 
			
		||||
    {
 | 
			
		||||
@@ -531,8 +538,8 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Broadcasts a text <paramref name="data"/> to all clients of the WebSocket
 | 
			
		||||
    /// service with the specified <paramref name="servicePath"/>.
 | 
			
		||||
    /// Broadcasts a text <paramref name="data"/> to all clients of the
 | 
			
		||||
    /// WebSocket service with the specified <paramref name="servicePath"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="servicePath">
 | 
			
		||||
    /// A <see cref="string"/> that represents the absolute path to the WebSocket
 | 
			
		||||
@@ -560,7 +567,8 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// service to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to broadcast.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data
 | 
			
		||||
    /// to broadcast.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="completed">
 | 
			
		||||
    /// A <see cref="Action"/> delegate that references the method(s) called when
 | 
			
		||||
@@ -575,8 +583,8 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Broadcasts a text <paramref name="data"/> asynchronously to all clients of
 | 
			
		||||
    /// the WebSocket service with the specified <paramref name="servicePath"/>.
 | 
			
		||||
    /// Broadcasts a text <paramref name="data"/> asynchronously to all clients
 | 
			
		||||
    /// of the WebSocket service with the specified <paramref name="servicePath"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the broadcast to be complete.
 | 
			
		||||
@@ -602,8 +610,8 @@ namespace WebSocketSharp.Server
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Broadcasts a binary data from the specified <see cref="Stream"/>
 | 
			
		||||
    /// asynchronously to all clients of the WebSocket service with the specified
 | 
			
		||||
    /// <paramref name="servicePath"/>.
 | 
			
		||||
    /// asynchronously to all clients of the WebSocket service with the
 | 
			
		||||
    /// specified <paramref name="servicePath"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the broadcast to be complete.
 | 
			
		||||
@@ -613,8 +621,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// service to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="stream">
 | 
			
		||||
    /// A <see cref="Stream"/> object from which contains the binary data to
 | 
			
		||||
    /// broadcast.
 | 
			
		||||
    /// A <see cref="Stream"/> from which contains the binary data to broadcast.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="length">
 | 
			
		||||
    /// An <see cref="int"/> that represents the number of bytes to broadcast.
 | 
			
		||||
@@ -643,7 +650,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// </returns>
 | 
			
		||||
    public Dictionary<string, Dictionary<string, bool>> Broadping ()
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted ();
 | 
			
		||||
      var msg = _state.CheckIfStart ();
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        return null;
 | 
			
		||||
@@ -671,8 +678,9 @@ namespace WebSocketSharp.Server
 | 
			
		||||
        return Broadping ();
 | 
			
		||||
 | 
			
		||||
      byte [] data = null;
 | 
			
		||||
      var msg = _state.CheckIfStarted () ??
 | 
			
		||||
                (data = Encoding.UTF8.GetBytes (message)).CheckIfValidControlData ("message");
 | 
			
		||||
      var msg = checkIfCanSend (
 | 
			
		||||
        () => (data = Encoding.UTF8.GetBytes (message))
 | 
			
		||||
              .CheckIfValidControlData ("message"));
 | 
			
		||||
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
@@ -851,19 +859,19 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> to the client associated with the
 | 
			
		||||
    /// specified <paramref name="servicePath"/> and <paramref name="id"/>.
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> to the client on the session with
 | 
			
		||||
    /// the specified <paramref name="id"/>, in the WebSocket service with the
 | 
			
		||||
    /// specified <paramref name="servicePath"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="servicePath">
 | 
			
		||||
    /// A <see cref="string"/> that represents the absolute path to the WebSocket
 | 
			
		||||
    /// service to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="id">
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to send the
 | 
			
		||||
    /// data to.
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to send.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void SendTo (string servicePath, string id, byte [] data)
 | 
			
		||||
    {
 | 
			
		||||
@@ -873,16 +881,16 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a text <paramref name="data"/> to the client associated with the
 | 
			
		||||
    /// specified <paramref name="servicePath"/> and <paramref name="id"/>.
 | 
			
		||||
    /// Sends a text <paramref name="data"/> to the client on the session with
 | 
			
		||||
    /// the specified <paramref name="id"/>, in the WebSocket service with the
 | 
			
		||||
    /// specified <paramref name="servicePath"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="servicePath">
 | 
			
		||||
    /// A <see cref="string"/> that represents the absolute path to the WebSocket
 | 
			
		||||
    /// service to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="id">
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to send the
 | 
			
		||||
    /// data to.
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// A <see cref="string"/> that represents the text data to send.
 | 
			
		||||
@@ -895,9 +903,9 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> asynchronously to the client
 | 
			
		||||
    /// associated with the specified <paramref name="servicePath"/> and
 | 
			
		||||
    /// <paramref name="id"/>.
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> asynchronously to the client on the
 | 
			
		||||
    /// session with the specified <paramref name="id"/>, in the WebSocket service
 | 
			
		||||
    /// with the specified <paramref name="servicePath"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
@@ -907,11 +915,10 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// service to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="id">
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to send the
 | 
			
		||||
    /// data to.
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to send.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="completed">
 | 
			
		||||
    /// An Action<bool> delegate that references the method(s) called when
 | 
			
		||||
@@ -928,9 +935,9 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a text <paramref name="data"/> asynchronously to the client
 | 
			
		||||
    /// associated with the specified <paramref name="servicePath"/> and
 | 
			
		||||
    /// <paramref name="id"/>.
 | 
			
		||||
    /// Sends a text <paramref name="data"/> asynchronously to the client on the
 | 
			
		||||
    /// session with the specified <paramref name="id"/>, in the WebSocket service
 | 
			
		||||
    /// with the specified <paramref name="servicePath"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
@@ -940,8 +947,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// service to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="id">
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to send the
 | 
			
		||||
    /// data to.
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// A <see cref="string"/> that represents the text data to send.
 | 
			
		||||
@@ -962,8 +968,8 @@ namespace WebSocketSharp.Server
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary data from the specified <see cref="Stream"/> asynchronously
 | 
			
		||||
    /// to the client associated with the specified <paramref name="servicePath"/>
 | 
			
		||||
    /// and <paramref name="id"/>.
 | 
			
		||||
    /// to the client on the session with the specified <paramref name="id"/>, in
 | 
			
		||||
    /// the WebSocket service with the specified <paramref name="servicePath"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
@@ -973,11 +979,10 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// service to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="id">
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to send the
 | 
			
		||||
    /// data to.
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="stream">
 | 
			
		||||
    /// A <see cref="Stream"/> object from which contains the binary data to send.
 | 
			
		||||
    /// A <see cref="Stream"/> from which contains the binary data to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="length">
 | 
			
		||||
    /// An <see cref="int"/> that represents the number of bytes to send.
 | 
			
		||||
@@ -1016,7 +1021,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    public bool TryGetServiceHost (
 | 
			
		||||
      string servicePath, out WebSocketServiceHost serviceHost)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted () ?? servicePath.CheckIfValidServicePath ();
 | 
			
		||||
      var msg = _state.CheckIfStart () ?? servicePath.CheckIfValidServicePath ();
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        serviceHost = null;
 | 
			
		||||
 
 | 
			
		||||
@@ -276,6 +276,11 @@ namespace WebSocketSharp.Server
 | 
			
		||||
        state => broadcast (opcode, stream, completed));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private string checkIfCanSend (Func<string> checkParams)
 | 
			
		||||
    {
 | 
			
		||||
      return _state.CheckIfStart () ?? checkParams ();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static string createID ()
 | 
			
		||||
    {
 | 
			
		||||
      return Guid.NewGuid ().ToString ("N");
 | 
			
		||||
@@ -398,15 +403,16 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    #region Public Methods
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Broadcasts a binary <paramref name="data"/> to all clients of the
 | 
			
		||||
    /// WebSocket service.
 | 
			
		||||
    /// Broadcasts a binary <paramref name="data"/> to all clients
 | 
			
		||||
    /// of the WebSocket service.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to broadcast.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data
 | 
			
		||||
    /// to broadcast.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void Broadcast (byte [] data)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
 | 
			
		||||
      var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        return;
 | 
			
		||||
@@ -419,15 +425,15 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Broadcasts a text <paramref name="data"/> to all clients of the WebSocket
 | 
			
		||||
    /// service.
 | 
			
		||||
    /// Broadcasts a text <paramref name="data"/> to all clients
 | 
			
		||||
    /// of the WebSocket service.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// A <see cref="string"/> that represents the text data to broadcast.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void Broadcast (string data)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
 | 
			
		||||
      var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        return;
 | 
			
		||||
@@ -448,7 +454,8 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// This method doesn't wait for the broadcast to be complete.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to broadcast.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data
 | 
			
		||||
    /// to broadcast.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="completed">
 | 
			
		||||
    /// A <see cref="Action"/> delegate that references the method(s) called when
 | 
			
		||||
@@ -456,7 +463,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void BroadcastAsync (byte [] data, Action completed)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
 | 
			
		||||
      var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        return;
 | 
			
		||||
@@ -469,8 +476,8 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Broadcasts a text <paramref name="data"/> asynchronously to all clients of
 | 
			
		||||
    /// the WebSocket service.
 | 
			
		||||
    /// Broadcasts a text <paramref name="data"/> asynchronously to all clients
 | 
			
		||||
    /// of the WebSocket service.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the broadcast to be complete.
 | 
			
		||||
@@ -484,7 +491,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void BroadcastAsync (string data, Action completed)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData ();
 | 
			
		||||
      var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        return;
 | 
			
		||||
@@ -505,8 +512,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// This method doesn't wait for the broadcast to be complete.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <param name="stream">
 | 
			
		||||
    /// A <see cref="Stream"/> object from which contains the binary data to
 | 
			
		||||
    /// broadcast.
 | 
			
		||||
    /// A <see cref="Stream"/> from which contains the binary data to broadcast.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="length">
 | 
			
		||||
    /// An <see cref="int"/> that represents the number of bytes to broadcast.
 | 
			
		||||
@@ -517,9 +523,9 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void BroadcastAsync (Stream stream, int length, Action completed)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted () ??
 | 
			
		||||
                stream.CheckIfCanRead () ??
 | 
			
		||||
                (length < 1 ? "'length' must be greater than 0." : null);
 | 
			
		||||
      var msg = checkIfCanSend (
 | 
			
		||||
        () => stream.CheckIfCanRead () ??
 | 
			
		||||
              (length < 1 ? "'length' must be greater than 0." : null));
 | 
			
		||||
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
@@ -560,7 +566,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// </returns>
 | 
			
		||||
    public Dictionary<string, bool> Broadping ()
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted ();
 | 
			
		||||
      var msg = _state.CheckIfStart ();
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        return null;
 | 
			
		||||
@@ -587,8 +593,9 @@ namespace WebSocketSharp.Server
 | 
			
		||||
        return Broadping ();
 | 
			
		||||
 | 
			
		||||
      byte [] data = null;
 | 
			
		||||
      var msg = _state.CheckIfStarted () ??
 | 
			
		||||
                (data = Encoding.UTF8.GetBytes (message)).CheckIfValidControlData ("message");
 | 
			
		||||
      var msg = checkIfCanSend (
 | 
			
		||||
        () => (data = Encoding.UTF8.GetBytes (message))
 | 
			
		||||
              .CheckIfValidControlData ("message"));
 | 
			
		||||
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
@@ -695,15 +702,14 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> to the client associated with the
 | 
			
		||||
    /// specified <paramref name="id"/>.
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> to the client on the session
 | 
			
		||||
    /// with the specified <paramref name="id"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="id">
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to send the
 | 
			
		||||
    /// data to.
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to send.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void SendTo (string id, byte [] data)
 | 
			
		||||
    {
 | 
			
		||||
@@ -713,11 +719,11 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a text <paramref name="data"/> to the client associated with the
 | 
			
		||||
    /// specified <paramref name="id"/>.
 | 
			
		||||
    /// Sends a text <paramref name="data"/> to the client on the session
 | 
			
		||||
    /// with the specified <paramref name="id"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="id">
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to send the
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to find.
 | 
			
		||||
    /// data to.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
@@ -732,17 +738,16 @@ namespace WebSocketSharp.Server
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> asynchronously to the client
 | 
			
		||||
    /// associated with the specified <paramref name="id"/>.
 | 
			
		||||
    /// on the session with the specified <paramref name="id"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <param name="id">
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to send the
 | 
			
		||||
    /// data to.
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to send.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="completed">
 | 
			
		||||
    /// An Action<bool> delegate that references the method(s) called when
 | 
			
		||||
@@ -759,14 +764,13 @@ namespace WebSocketSharp.Server
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a text <paramref name="data"/> asynchronously to the client
 | 
			
		||||
    /// associated with the specified <paramref name="id"/>.
 | 
			
		||||
    /// on the session with the specified <paramref name="id"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <param name="id">
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to send the
 | 
			
		||||
    /// data to.
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// A <see cref="string"/> that represents the text data to send.
 | 
			
		||||
@@ -786,17 +790,16 @@ namespace WebSocketSharp.Server
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary data from the specified <see cref="Stream"/> asynchronously
 | 
			
		||||
    /// to the client associated with the specified <paramref name="id"/>.
 | 
			
		||||
    /// to the client on the session with the specified <paramref name="id"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <param name="id">
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to send the
 | 
			
		||||
    /// data to.
 | 
			
		||||
    /// A <see cref="string"/> that represents the ID of the session to find.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="stream">
 | 
			
		||||
    /// A <see cref="Stream"/> object from which contains the binary data to send.
 | 
			
		||||
    /// A <see cref="Stream"/> from which contains the binary data to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="length">
 | 
			
		||||
    /// An <see cref="int"/> that represents the number of bytes to send.
 | 
			
		||||
@@ -864,7 +867,7 @@ namespace WebSocketSharp.Server
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public bool TryGetSession (string id, out IWebSocketSession session)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _state.CheckIfStarted () ?? id.CheckIfValidSessionID ();
 | 
			
		||||
      var msg = _state.CheckIfStart () ?? id.CheckIfValidSessionID ();
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        session = null;
 | 
			
		||||
 
 | 
			
		||||
@@ -650,6 +650,11 @@ namespace WebSocketSharp
 | 
			
		||||
             : _readyState.CheckIfConnectable ();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private string checkIfCanSend (Func<string> checkParams)
 | 
			
		||||
    {
 | 
			
		||||
      return _readyState.CheckIfOpen () ?? checkParams ();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // As server
 | 
			
		||||
    private string checkIfValidHandshakeRequest (WebSocketContext context)
 | 
			
		||||
    {
 | 
			
		||||
@@ -1054,7 +1059,7 @@ namespace WebSocketSharp
 | 
			
		||||
      return res;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private bool send (byte [] frameAsBytes)
 | 
			
		||||
    private bool send (byte [] frame)
 | 
			
		||||
    {
 | 
			
		||||
      lock (_forConn) {
 | 
			
		||||
        if (_readyState != WebSocketState.OPEN) {
 | 
			
		||||
@@ -1065,7 +1070,7 @@ namespace WebSocketSharp
 | 
			
		||||
          return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return _stream.Write (frameAsBytes);
 | 
			
		||||
        return _stream.Write (frame);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -1860,11 +1865,11 @@ namespace WebSocketSharp
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> using the WebSocket connection.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to send.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void Send (byte [] data)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData ();
 | 
			
		||||
      var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        error (msg);
 | 
			
		||||
@@ -1884,17 +1889,15 @@ namespace WebSocketSharp
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary data from the specified <see cref="FileInfo"/> using the
 | 
			
		||||
    /// WebSocket connection.
 | 
			
		||||
    /// Sends the specified <paramref name="file"/> as a binary data
 | 
			
		||||
    /// using the WebSocket connection.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="file">
 | 
			
		||||
    /// A <see cref="FileInfo"/> from which contains the binary data to send.
 | 
			
		||||
    /// A <see cref="FileInfo"/> that represents the file to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void Send (FileInfo file)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _readyState.CheckIfOpen () ??
 | 
			
		||||
                (file == null ? "'file' must not be null." : null);
 | 
			
		||||
 | 
			
		||||
      var msg = checkIfCanSend (() => file.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        error (msg);
 | 
			
		||||
@@ -1913,7 +1916,7 @@ namespace WebSocketSharp
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void Send (string data)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData ();
 | 
			
		||||
      var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        error (msg);
 | 
			
		||||
@@ -1929,24 +1932,23 @@ namespace WebSocketSharp
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> asynchronously using the WebSocket
 | 
			
		||||
    /// connection.
 | 
			
		||||
    /// Sends a binary <paramref name="data"/> asynchronously
 | 
			
		||||
    /// using the WebSocket connection.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <param name="data">
 | 
			
		||||
    /// An array of <see cref="byte"/> that contains the binary data to send.
 | 
			
		||||
    /// An array of <see cref="byte"/> that represents the binary data to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="completed">
 | 
			
		||||
    /// An Action<bool> delegate that references the method(s) called when
 | 
			
		||||
    /// the send is complete.
 | 
			
		||||
    /// A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
 | 
			
		||||
    /// complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// the send is complete. A <see cref="bool"/> passed to this delegate is
 | 
			
		||||
    /// <c>true</c> if the send is complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void SendAsync (byte [] data, Action<bool> completed)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData ();
 | 
			
		||||
      var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        error (msg);
 | 
			
		||||
@@ -1967,26 +1969,23 @@ namespace WebSocketSharp
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary data from the specified <see cref="FileInfo"/>
 | 
			
		||||
    /// Sends the specified <paramref name="file"/> as a binary data
 | 
			
		||||
    /// asynchronously using the WebSocket connection.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <param name="file">
 | 
			
		||||
    /// A <see cref="FileInfo"/> from which contains the binary data to send.
 | 
			
		||||
    /// A <see cref="FileInfo"/> that represents the file to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="completed">
 | 
			
		||||
    /// An Action<bool> delegate that references the method(s) called when
 | 
			
		||||
    /// the send is complete.
 | 
			
		||||
    /// A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
 | 
			
		||||
    /// complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// the send is complete. A <see cref="bool"/> passed to this delegate is
 | 
			
		||||
    /// <c>true</c> if the send is complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void SendAsync (FileInfo file, Action<bool> completed)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _readyState.CheckIfOpen () ??
 | 
			
		||||
                (file == null ? "'file' must not be null." : null);
 | 
			
		||||
 | 
			
		||||
      var msg = checkIfCanSend (() => file.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        error (msg);
 | 
			
		||||
@@ -1998,8 +1997,8 @@ namespace WebSocketSharp
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a text <paramref name="data"/> asynchronously using the WebSocket
 | 
			
		||||
    /// connection.
 | 
			
		||||
    /// Sends a text <paramref name="data"/> asynchronously
 | 
			
		||||
    /// using the WebSocket connection.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
@@ -2009,13 +2008,12 @@ namespace WebSocketSharp
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="completed">
 | 
			
		||||
    /// An Action<bool> delegate that references the method(s) called when
 | 
			
		||||
    /// the send is complete.
 | 
			
		||||
    /// A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
 | 
			
		||||
    /// complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// the send is complete. A <see cref="bool"/> passed to this delegate is
 | 
			
		||||
    /// <c>true</c> if the send is complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void SendAsync (string data, Action<bool> completed)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData ();
 | 
			
		||||
      var msg = checkIfCanSend (() => data.CheckIfValidSendData ());
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
        error (msg);
 | 
			
		||||
@@ -2031,29 +2029,28 @@ namespace WebSocketSharp
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Sends a binary data from the specified <see cref="Stream"/> asynchronously
 | 
			
		||||
    /// using the WebSocket connection.
 | 
			
		||||
    /// Sends a binary data from the specified <see cref="Stream"/>
 | 
			
		||||
    /// asynchronously using the WebSocket connection.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <remarks>
 | 
			
		||||
    /// This method doesn't wait for the send to be complete.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <param name="stream">
 | 
			
		||||
    /// A <see cref="Stream"/> object from which contains the binary data to send.
 | 
			
		||||
    /// A <see cref="Stream"/> from which contains the binary data to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="length">
 | 
			
		||||
    /// An <see cref="int"/> that represents the number of bytes to send.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    /// <param name="completed">
 | 
			
		||||
    /// An Action<bool> delegate that references the method(s) called when
 | 
			
		||||
    /// the send is complete.
 | 
			
		||||
    /// A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
 | 
			
		||||
    /// complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// the send is complete. A <see cref="bool"/> passed to this delegate is
 | 
			
		||||
    /// <c>true</c> if the send is complete successfully; otherwise, <c>false</c>.
 | 
			
		||||
    /// </param>
 | 
			
		||||
    public void SendAsync (Stream stream, int length, Action<bool> completed)
 | 
			
		||||
    {
 | 
			
		||||
      var msg = _readyState.CheckIfOpen () ??
 | 
			
		||||
                stream.CheckIfCanRead () ??
 | 
			
		||||
                (length < 1 ? "'length' must be greater than 0." : null);
 | 
			
		||||
      var msg = checkIfCanSend (
 | 
			
		||||
        () => stream.CheckIfCanRead () ??
 | 
			
		||||
              (length < 1 ? "'length' must be greater than 0." : null));
 | 
			
		||||
 | 
			
		||||
      if (msg != null) {
 | 
			
		||||
        _logger.Error (msg);
 | 
			
		||||
@@ -2067,9 +2064,9 @@ namespace WebSocketSharp
 | 
			
		||||
        data => {
 | 
			
		||||
          var len = data.Length;
 | 
			
		||||
          if (len == 0) {
 | 
			
		||||
            var err = "A data cannot be read from 'stream'.";
 | 
			
		||||
            _logger.Error (err);
 | 
			
		||||
            error (err);
 | 
			
		||||
            msg = "A data cannot be read from 'stream'.";
 | 
			
		||||
            _logger.Error (msg);
 | 
			
		||||
            error (msg);
 | 
			
		||||
 | 
			
		||||
            return;
 | 
			
		||||
          }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user