|
|
|
|
@ -202,7 +202,7 @@ namespace WebSocketSharp
|
|
|
|
|
/// <paramref name="url"/> is <see langword="null"/>.
|
|
|
|
|
/// </exception>
|
|
|
|
|
/// <exception cref="ArgumentException">
|
|
|
|
|
/// <paramref name="url"/> is not valid WebSocket URL.
|
|
|
|
|
/// <paramref name="url"/> is invalid.
|
|
|
|
|
/// </exception>
|
|
|
|
|
public WebSocket (
|
|
|
|
|
string url,
|
|
|
|
|
@ -1603,32 +1603,32 @@ namespace WebSocketSharp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sends a text <paramref name="data"/> using the WebSocket connection.
|
|
|
|
|
/// Sends a binary data from the specified <see cref="FileInfo"/>
|
|
|
|
|
/// using the WebSocket connection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method does not wait for the send to be complete.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="data">
|
|
|
|
|
/// A <see cref="string"/> that contains a text data to send.
|
|
|
|
|
/// <param name="file">
|
|
|
|
|
/// A <see cref="FileInfo"/> from which contains a binary data to send.
|
|
|
|
|
/// </param>
|
|
|
|
|
public void Send (string data)
|
|
|
|
|
public void Send (FileInfo file)
|
|
|
|
|
{
|
|
|
|
|
Send (data, null);
|
|
|
|
|
Send (file, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sends a binary data from the specified <see cref="FileInfo"/>
|
|
|
|
|
/// using the WebSocket connection.
|
|
|
|
|
/// Sends a text <paramref name="data"/> using the WebSocket connection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method does not wait for the send to be complete.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="file">
|
|
|
|
|
/// A <see cref="FileInfo"/> from which contains a binary data to send.
|
|
|
|
|
/// <param name="data">
|
|
|
|
|
/// A <see cref="string"/> that contains a text data to send.
|
|
|
|
|
/// </param>
|
|
|
|
|
public void Send (FileInfo file)
|
|
|
|
|
public void Send (string data)
|
|
|
|
|
{
|
|
|
|
|
Send (file, null);
|
|
|
|
|
Send (data, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
@ -1664,13 +1664,14 @@ namespace WebSocketSharp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sends a text <paramref name="data"/> using the WebSocket connection.
|
|
|
|
|
/// Sends a binary data from the specified <see cref="FileInfo"/>
|
|
|
|
|
/// using the WebSocket connection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method does not wait for the send to be complete.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="data">
|
|
|
|
|
/// A <see cref="string"/> that contains a text data to send.
|
|
|
|
|
/// <param name="file">
|
|
|
|
|
/// A <see cref="FileInfo"/> from which contains a binary data to send.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="completed">
|
|
|
|
|
/// An Action<bool> delegate that references the method(s) called when
|
|
|
|
|
@ -1678,9 +1679,11 @@ namespace WebSocketSharp
|
|
|
|
|
/// 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 Send (string data, Action<bool> completed)
|
|
|
|
|
public void Send (FileInfo file, Action<bool> completed)
|
|
|
|
|
{
|
|
|
|
|
var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData ();
|
|
|
|
|
var msg = _readyState.CheckIfOpen () ??
|
|
|
|
|
(file == null ? "'file' must not be null." : null);
|
|
|
|
|
|
|
|
|
|
if (msg != null)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
@ -1689,22 +1692,17 @@ namespace WebSocketSharp
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var rawData = Encoding.UTF8.GetBytes (data);
|
|
|
|
|
if (rawData.LongLength <= FragmentLength)
|
|
|
|
|
send (Opcode.TEXT, rawData, completed);
|
|
|
|
|
else
|
|
|
|
|
send (Opcode.TEXT, new MemoryStream (rawData), completed);
|
|
|
|
|
send (Opcode.BINARY, file.OpenRead (), completed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sends a binary data from the specified <see cref="FileInfo"/>
|
|
|
|
|
/// using the WebSocket connection.
|
|
|
|
|
/// Sends a text <paramref name="data"/> using the WebSocket connection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method does not wait for the send to be complete.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="file">
|
|
|
|
|
/// A <see cref="FileInfo"/> from which contains a binary data to send.
|
|
|
|
|
/// <param name="data">
|
|
|
|
|
/// A <see cref="string"/> that contains a text data to send.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="completed">
|
|
|
|
|
/// An Action<bool> delegate that references the method(s) called when
|
|
|
|
|
@ -1712,11 +1710,9 @@ namespace WebSocketSharp
|
|
|
|
|
/// 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 Send (FileInfo file, Action<bool> completed)
|
|
|
|
|
public void Send (string data, Action<bool> completed)
|
|
|
|
|
{
|
|
|
|
|
var msg = _readyState.CheckIfOpen () ??
|
|
|
|
|
(file == null ? "'file' must not be null." : null);
|
|
|
|
|
|
|
|
|
|
var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData ();
|
|
|
|
|
if (msg != null)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
@ -1725,7 +1721,11 @@ namespace WebSocketSharp
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
send (Opcode.BINARY, file.OpenRead (), completed);
|
|
|
|
|
var rawData = Encoding.UTF8.GetBytes (data);
|
|
|
|
|
if (rawData.LongLength <= FragmentLength)
|
|
|
|
|
send (Opcode.TEXT, rawData, completed);
|
|
|
|
|
else
|
|
|
|
|
send (Opcode.TEXT, new MemoryStream (rawData), completed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
@ -1741,13 +1741,9 @@ namespace WebSocketSharp
|
|
|
|
|
/// <param name="length">
|
|
|
|
|
/// An <see cref="int"/> that contains the number of bytes to send.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="dispose">
|
|
|
|
|
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data read;
|
|
|
|
|
/// otherwise, <c>false</c>.
|
|
|
|
|
/// </param>
|
|
|
|
|
public void Send (Stream stream, int length, bool dispose)
|
|
|
|
|
public void Send (Stream stream, int length)
|
|
|
|
|
{
|
|
|
|
|
Send (stream, length, dispose, null);
|
|
|
|
|
Send (stream, length, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
@ -1763,17 +1759,13 @@ namespace WebSocketSharp
|
|
|
|
|
/// <param name="length">
|
|
|
|
|
/// An <see cref="int"/> that contains the number of bytes to send.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="dispose">
|
|
|
|
|
/// <c>true</c> if <paramref name="stream"/> is disposed after a binary data read;
|
|
|
|
|
/// otherwise, <c>false</c>.
|
|
|
|
|
/// </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>.
|
|
|
|
|
/// 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 Send (Stream stream, int length, bool dispose, Action<bool> completed)
|
|
|
|
|
public void Send (Stream stream, int length, Action<bool> completed)
|
|
|
|
|
{
|
|
|
|
|
var msg = _readyState.CheckIfOpen () ??
|
|
|
|
|
stream.CheckIfCanRead () ??
|
|
|
|
|
@ -1787,42 +1779,38 @@ namespace WebSocketSharp
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Action<byte []> result = data =>
|
|
|
|
|
{
|
|
|
|
|
var readLen = data.Length;
|
|
|
|
|
if (readLen == 0)
|
|
|
|
|
stream.ReadBytesAsync (
|
|
|
|
|
length,
|
|
|
|
|
data =>
|
|
|
|
|
{
|
|
|
|
|
var err = "A data cannot be read from 'stream'.";
|
|
|
|
|
_logger.Error (err);
|
|
|
|
|
error (err);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (readLen != length)
|
|
|
|
|
_logger.Warn (String.Format (
|
|
|
|
|
"A data with 'length' cannot be read from 'stream'.\nexpected: {0} actual: {1}",
|
|
|
|
|
length,
|
|
|
|
|
readLen));
|
|
|
|
|
|
|
|
|
|
if (dispose)
|
|
|
|
|
stream.Dispose ();
|
|
|
|
|
var len = data.Length;
|
|
|
|
|
if (len == 0)
|
|
|
|
|
{
|
|
|
|
|
var err = "A data cannot be read from 'stream'.";
|
|
|
|
|
_logger.Error (err);
|
|
|
|
|
error (err);
|
|
|
|
|
|
|
|
|
|
var sent = readLen <= FragmentLength
|
|
|
|
|
? send (Opcode.BINARY, data)
|
|
|
|
|
: send (Opcode.BINARY, new MemoryStream (data));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (completed != null)
|
|
|
|
|
completed (sent);
|
|
|
|
|
};
|
|
|
|
|
if (len < length)
|
|
|
|
|
_logger.Warn (String.Format (
|
|
|
|
|
"A data with 'length' cannot be read from 'stream'.\nexpected: {0} actual: {1}",
|
|
|
|
|
length,
|
|
|
|
|
len));
|
|
|
|
|
|
|
|
|
|
Action<Exception> exception = ex =>
|
|
|
|
|
{
|
|
|
|
|
_logger.Fatal (ex.ToString ());
|
|
|
|
|
error ("An exception has occured.");
|
|
|
|
|
};
|
|
|
|
|
var sent = len <= FragmentLength
|
|
|
|
|
? send (Opcode.BINARY, data)
|
|
|
|
|
: send (Opcode.BINARY, new MemoryStream (data));
|
|
|
|
|
|
|
|
|
|
stream.ReadBytesAsync (length, result, exception);
|
|
|
|
|
if (completed != null)
|
|
|
|
|
completed (sent);
|
|
|
|
|
},
|
|
|
|
|
ex =>
|
|
|
|
|
{
|
|
|
|
|
_logger.Fatal (ex.ToString ());
|
|
|
|
|
error ("An exception has occured.");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|