Send() публичный Метод

Sends all data from the specified buffer to the remote host.
Send will block until all of the bytes in the buffer are sent. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.
/// The object was disposed. /// /// buffer is a null reference (Nothing in Visual Basic). /// /// An error occurred when attempting to access /// the socket which is used to complete the requested operation. ///
public Send ( byte buffer ) : int
buffer byte Data to send.
Результат int
Пример #1
0
 /// <summary>
 /// Writes data to the network stream.
 /// </summary>
 /// <param name="buffer">Data to write.</param>
 /// <param name="offset">The position in the data <i>buffer</i> from which to begin writing.</param>
 /// <param name="size">The number of bytes to write.</param>
 ///
 /// <exception cref="System.ObjectDisposedException">
 /// The <see cref="BytesRoad.Net.Sockets.NetworkStreamEx"/> object was disposed.
 /// </exception>
 ///
 /// <exception cref="System.ArgumentNullException">
 /// <i>buffer</i> is a null reference (<b>Nothing</b> in Visual Basic).
 /// </exception>
 ///
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// <i>offset</i> is less than 0.
 /// <para>-or-</para>
 /// <i>offset</i> is greater than the length of <i>buffer</i>.
 /// <para>-or-</para>
 /// <i>size</i> is less than 0.
 /// <para>-or-</para>
 /// <i>size</i> is greater than the length of <i>buffer</i> minus
 /// the value of the <i>offset</i> parameter.
 /// </exception>
 ///
 /// <exception cref="System.Net.Sockets.SocketException">
 /// An error occurred when attempting to access
 /// the socket which is used to complete the requested operation.
 /// </exception>
 ///
 /// <remarks>
 /// <b>Write</b> method will block until all data, specified by <i>size</i> parameter, are sent.
 ///
 /// <note>
 /// The <b>NetworkStreamEx</b> should have access right to write data to the network stream.
 /// You may use <see cref="BytesRoad.Net.Sockets.NetworkStreamEx.CanWrite"/> property to check this.
 /// </note>
 /// </remarks>
 public override void Write(byte[] buffer, int offset, int size)
 {
     CheckDisposed();
     _asyncCtx.SetProgress(true);
     try
     {
         int sent = 0;
         while (sent < size)
         {
             sent += _socket.Send(
                 buffer,
                 offset + sent,
                 size - sent);
         }
     }
     catch
     {
         CheckDisposed();
         throw;
     }
     finally
     {
         _asyncCtx.SetProgress(false);
     }
 }