|
|
|
@ -1028,65 +1028,72 @@ namespace WebSocketSharp
|
|
|
|
return _stream.Write (frame.ToByteArray ());
|
|
|
|
return _stream.Write (frame.ToByteArray ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void send (Opcode opcode, byte [] data)
|
|
|
|
private bool send (Opcode opcode, byte [] data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock (_forSend)
|
|
|
|
lock (_forSend)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var sent = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
var comped = false;
|
|
|
|
var compressed = false;
|
|
|
|
if (_compression != CompressionMethod.NONE)
|
|
|
|
if (_compression != CompressionMethod.NONE)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
data = data.Compress (_compression);
|
|
|
|
data = data.Compress (_compression);
|
|
|
|
comped = true;
|
|
|
|
compressed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
send (WsFrame.CreateFrame (
|
|
|
|
sent = send (WsFrame.CreateFrame (
|
|
|
|
Fin.FINAL, opcode, _client ? Mask.MASK : Mask.UNMASK, data, comped));
|
|
|
|
Fin.FINAL, opcode, _client ? Mask.MASK : Mask.UNMASK, data, compressed));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
catch (Exception ex) {
|
|
|
|
_logger.Fatal (ex.ToString ());
|
|
|
|
_logger.Fatal (ex.ToString ());
|
|
|
|
error ("An exception has occured.");
|
|
|
|
error ("An exception has occured.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void send (Opcode opcode, Stream stream)
|
|
|
|
private bool send (Opcode opcode, Stream stream)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock (_forSend)
|
|
|
|
lock (_forSend)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var comp = stream;
|
|
|
|
var sent = false;
|
|
|
|
var comped = false;
|
|
|
|
|
|
|
|
|
|
|
|
var src = stream;
|
|
|
|
|
|
|
|
var compressed = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (_compression != CompressionMethod.NONE)
|
|
|
|
if (_compression != CompressionMethod.NONE)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
comp = stream.Compress (_compression);
|
|
|
|
stream = stream.Compress (_compression);
|
|
|
|
comped = true;
|
|
|
|
compressed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sendFragmented (opcode, comp, _client ? Mask.MASK : Mask.UNMASK, comped);
|
|
|
|
sent = sendFragmented (opcode, stream, _client ? Mask.MASK : Mask.UNMASK, compressed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
catch (Exception ex) {
|
|
|
|
_logger.Fatal (ex.ToString ());
|
|
|
|
_logger.Fatal (ex.ToString ());
|
|
|
|
error ("An exception has occured.");
|
|
|
|
error ("An exception has occured.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
finally {
|
|
|
|
if (comped)
|
|
|
|
if (compressed)
|
|
|
|
comp.Dispose ();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stream.Dispose ();
|
|
|
|
stream.Dispose ();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src.Dispose ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void sendAsync (Opcode opcode, byte [] data, Action completed)
|
|
|
|
private void send (Opcode opcode, byte [] data, Action<bool> completed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Action<Opcode, byte []> sender = send;
|
|
|
|
Func<Opcode, byte [], bool> sender = send;
|
|
|
|
AsyncCallback callback = ar =>
|
|
|
|
AsyncCallback callback = ar =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
sender.EndInvoke (ar);
|
|
|
|
var sent = sender.EndInvoke (ar);
|
|
|
|
if (completed != null)
|
|
|
|
if (completed != null)
|
|
|
|
completed ();
|
|
|
|
completed (sent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -1098,15 +1105,15 @@ namespace WebSocketSharp
|
|
|
|
sender.BeginInvoke (opcode, data, callback, null);
|
|
|
|
sender.BeginInvoke (opcode, data, callback, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void sendAsync (Opcode opcode, Stream stream, Action completed)
|
|
|
|
private void send (Opcode opcode, Stream stream, Action<bool> completed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Action<Opcode, Stream> sender = send;
|
|
|
|
Func<Opcode, Stream, bool> sender = send;
|
|
|
|
AsyncCallback callback = ar =>
|
|
|
|
AsyncCallback callback = ar =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
sender.EndInvoke (ar);
|
|
|
|
var sent = sender.EndInvoke (ar);
|
|
|
|
if (completed != null)
|
|
|
|
if (completed != null)
|
|
|
|
completed ();
|
|
|
|
completed (sent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -1585,127 +1592,62 @@ namespace WebSocketSharp
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Sends a binary <paramref name="data"/> using the WebSocket connection.
|
|
|
|
/// Sends a binary <paramref name="data"/> using the WebSocket connection.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// This method does not wait for the send to be complete.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
/// <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>
|
|
|
|
public void Send (byte[] data)
|
|
|
|
public void Send (byte[] data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData ();
|
|
|
|
Send (data, null);
|
|
|
|
if (msg != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
|
|
|
error (msg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (data.LongLength <= FragmentLength)
|
|
|
|
|
|
|
|
send (Opcode.BINARY, data);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
send (Opcode.BINARY, new MemoryStream (data));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Sends a text <paramref name="data"/> using the WebSocket connection.
|
|
|
|
/// Sends a text <paramref name="data"/> using the WebSocket connection.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// This method does not wait for the send to be complete.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
/// <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>
|
|
|
|
public void Send (string data)
|
|
|
|
public void Send (string data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData ();
|
|
|
|
Send (data, null);
|
|
|
|
if (msg != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
|
|
|
error (msg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rawData = Encoding.UTF8.GetBytes (data);
|
|
|
|
|
|
|
|
if (rawData.LongLength <= FragmentLength)
|
|
|
|
|
|
|
|
send (Opcode.TEXT, rawData);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
send (Opcode.TEXT, new MemoryStream (rawData));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Sends a binary data using the WebSocket connection.
|
|
|
|
/// Sends a binary data from the specified <see cref="FileInfo"/>
|
|
|
|
|
|
|
|
/// using the WebSocket connection.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// This method does not wait for the send to be complete.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
/// <param name="file">
|
|
|
|
/// <param name="file">
|
|
|
|
/// A <see cref="FileInfo"/> that contains a binary data to send.
|
|
|
|
/// A <see cref="FileInfo"/> from which contains a binary data to send.
|
|
|
|
/// </param>
|
|
|
|
/// </param>
|
|
|
|
public void Send (FileInfo file)
|
|
|
|
public void Send (FileInfo file)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var msg = _readyState.CheckIfOpen () ??
|
|
|
|
Send (file, null);
|
|
|
|
(file == null ? "'file' must not be null." : null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (msg != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
|
|
|
error (msg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
send (Opcode.BINARY, file.OpenRead ());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Sends a binary data from the specified <see cref="Stream"/> using the WebSocket connection.
|
|
|
|
/// Sends a binary <paramref name="data"/> using the WebSocket connection.
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="stream">
|
|
|
|
|
|
|
|
/// A <see cref="Stream"/> object from which contains a binary data to send.
|
|
|
|
|
|
|
|
/// </param>
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
byte [] data = null;
|
|
|
|
|
|
|
|
int readLen = 0;
|
|
|
|
|
|
|
|
var msg = _readyState.CheckIfOpen () ??
|
|
|
|
|
|
|
|
stream.CheckIfCanRead () ??
|
|
|
|
|
|
|
|
(length < 1 ? "'length' must be greater than 0." : null) ??
|
|
|
|
|
|
|
|
((readLen = (data = stream.ReadBytes (length)).Length) == 0
|
|
|
|
|
|
|
|
? "A data cannot be read from 'stream'." : null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (msg != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
|
|
|
error (msg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 ();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (readLen <= FragmentLength)
|
|
|
|
|
|
|
|
send (Opcode.BINARY, data);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
send (Opcode.BINARY, new MemoryStream (data));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Sends a binary <paramref name="data"/> asynchronously using the WebSocket connection.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// This method does not wait for the send to be complete.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
/// <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="completed">
|
|
|
|
/// <param name="completed">
|
|
|
|
/// An <see cref="Action"/> delegate that references the method(s) called when
|
|
|
|
/// An Action<bool> delegate that references the method(s) called when
|
|
|
|
/// the asynchronous operation completes.
|
|
|
|
/// 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>
|
|
|
|
/// </param>
|
|
|
|
public void SendAsync (byte [] data, Action completed)
|
|
|
|
public void Send (byte [] data, Action<bool> completed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData ();
|
|
|
|
var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData ();
|
|
|
|
if (msg != null)
|
|
|
|
if (msg != null)
|
|
|
|
@ -1717,22 +1659,27 @@ namespace WebSocketSharp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (data.LongLength <= FragmentLength)
|
|
|
|
if (data.LongLength <= FragmentLength)
|
|
|
|
sendAsync (Opcode.BINARY, data, completed);
|
|
|
|
send (Opcode.BINARY, data, completed);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
sendAsync (Opcode.BINARY, new MemoryStream (data), completed);
|
|
|
|
send (Opcode.BINARY, new MemoryStream (data), completed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Sends a text <paramref name="data"/> asynchronously using the WebSocket connection.
|
|
|
|
/// Sends a text <paramref name="data"/> using the WebSocket connection.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// This method does not wait for the send to be complete.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
/// <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="completed">
|
|
|
|
/// <param name="completed">
|
|
|
|
/// An <see cref="Action"/> delegate that references the method(s) called when
|
|
|
|
/// An Action<bool> delegate that references the method(s) called when
|
|
|
|
/// the asynchronous operation completes.
|
|
|
|
/// 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>
|
|
|
|
/// </param>
|
|
|
|
public void SendAsync (string data, Action completed)
|
|
|
|
public void Send (string data, Action<bool> completed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData ();
|
|
|
|
var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData ();
|
|
|
|
if (msg != null)
|
|
|
|
if (msg != null)
|
|
|
|
@ -1745,22 +1692,28 @@ namespace WebSocketSharp
|
|
|
|
|
|
|
|
|
|
|
|
var rawData = Encoding.UTF8.GetBytes (data);
|
|
|
|
var rawData = Encoding.UTF8.GetBytes (data);
|
|
|
|
if (rawData.LongLength <= FragmentLength)
|
|
|
|
if (rawData.LongLength <= FragmentLength)
|
|
|
|
sendAsync (Opcode.TEXT, rawData, completed);
|
|
|
|
send (Opcode.TEXT, rawData, completed);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
sendAsync (Opcode.TEXT, new MemoryStream (rawData), completed);
|
|
|
|
send (Opcode.TEXT, new MemoryStream (rawData), completed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Sends a binary data asynchronously using the WebSocket connection.
|
|
|
|
/// Sends a binary data from the specified <see cref="FileInfo"/>
|
|
|
|
|
|
|
|
/// using the WebSocket connection.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// This method does not wait for the send to be complete.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
/// <param name="file">
|
|
|
|
/// <param name="file">
|
|
|
|
/// A <see cref="FileInfo"/> that contains a binary data to send.
|
|
|
|
/// A <see cref="FileInfo"/> from which contains a binary data to send.
|
|
|
|
/// </param>
|
|
|
|
/// </param>
|
|
|
|
/// <param name="completed">
|
|
|
|
/// <param name="completed">
|
|
|
|
/// An <see cref="Action"/> delegate that references the method(s) called when
|
|
|
|
/// An Action<bool> delegate that references the method(s) called when
|
|
|
|
/// the asynchronous operation completes.
|
|
|
|
/// 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>
|
|
|
|
/// </param>
|
|
|
|
public void SendAsync (FileInfo file, Action completed)
|
|
|
|
public void Send (FileInfo file, Action<bool> completed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var msg = _readyState.CheckIfOpen () ??
|
|
|
|
var msg = _readyState.CheckIfOpen () ??
|
|
|
|
(file == null ? "'file' must not be null." : null);
|
|
|
|
(file == null ? "'file' must not be null." : null);
|
|
|
|
@ -1773,13 +1726,38 @@ namespace WebSocketSharp
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sendAsync (Opcode.BINARY, file.OpenRead (), completed);
|
|
|
|
send (Opcode.BINARY, file.OpenRead (), completed);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Sends a binary data from the specified <see cref="Stream"/>
|
|
|
|
|
|
|
|
/// using the WebSocket connection.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// This method does not wait for the send to be complete.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
/// <param name="stream">
|
|
|
|
|
|
|
|
/// A <see cref="Stream"/> object from which contains a binary data to send.
|
|
|
|
|
|
|
|
/// </param>
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Send (stream, length, dispose, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Sends a binary data asynchronously from the specified <see cref="Stream"/>
|
|
|
|
/// Sends a binary data from the specified <see cref="Stream"/>
|
|
|
|
/// using the WebSocket connection.
|
|
|
|
/// using the WebSocket connection.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// This method does not wait for the send to be complete.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
/// <param name="stream">
|
|
|
|
/// <param name="stream">
|
|
|
|
/// A <see cref="Stream"/> object from which contains a binary data to send.
|
|
|
|
/// A <see cref="Stream"/> object from which contains a binary data to send.
|
|
|
|
/// </param>
|
|
|
|
/// </param>
|
|
|
|
@ -1791,10 +1769,12 @@ namespace WebSocketSharp
|
|
|
|
/// otherwise, <c>false</c>.
|
|
|
|
/// otherwise, <c>false</c>.
|
|
|
|
/// </param>
|
|
|
|
/// </param>
|
|
|
|
/// <param name="completed">
|
|
|
|
/// <param name="completed">
|
|
|
|
/// An <see cref="Action"/> delegate that references the method(s) called when
|
|
|
|
/// An Action<bool> delegate that references the method(s) called when
|
|
|
|
/// the asynchronous operation completes.
|
|
|
|
/// 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>
|
|
|
|
/// </param>
|
|
|
|
public void SendAsync (Stream stream, int length, bool dispose, Action completed)
|
|
|
|
public void Send (Stream stream, int length, bool dispose, Action<bool> completed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var msg = _readyState.CheckIfOpen () ??
|
|
|
|
var msg = _readyState.CheckIfOpen () ??
|
|
|
|
stream.CheckIfCanRead () ??
|
|
|
|
stream.CheckIfCanRead () ??
|
|
|
|
@ -1829,10 +1809,12 @@ namespace WebSocketSharp
|
|
|
|
if (dispose)
|
|
|
|
if (dispose)
|
|
|
|
stream.Dispose ();
|
|
|
|
stream.Dispose ();
|
|
|
|
|
|
|
|
|
|
|
|
if (readLen <= FragmentLength)
|
|
|
|
var sent = readLen <= FragmentLength
|
|
|
|
sendAsync (Opcode.BINARY, data, completed);
|
|
|
|
? send (Opcode.BINARY, data)
|
|
|
|
else
|
|
|
|
: send (Opcode.BINARY, new MemoryStream (data));
|
|
|
|
sendAsync (Opcode.BINARY, new MemoryStream (data), completed);
|
|
|
|
|
|
|
|
|
|
|
|
if (completed != null)
|
|
|
|
|
|
|
|
completed (sent);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Action<Exception> exception = ex =>
|
|
|
|
Action<Exception> exception = ex =>
|
|
|
|
|