System.Net.Sockets.NetworkStream.Write Method

Writes data to the System.Net.Sockets.NetworkStream.

Syntax

public override void Write (byte[] buffer, int offset, int size)

Parameters

buffer
An array of type byte that contains the data to write to the System.Net.Sockets.NetworkStream.
offset
The location in buffer from which to start writing data.
size
The number of bytes to write to the System.Net.Sockets.NetworkStream.

Exceptions

TypeReason
ArgumentNullException buffer is null.
ArgumentOutOfRangeException

offset < 0.

-or-

offset > buffer.Length.

-or-

size < 0.

-or-

size > buffer.Length - offset.

System.IO.IOException
Note: This method catches all exceptions thrown by the Socket.Send(Byte[], int, SocketFlags) method.
ObjectDisposedExceptionThe current instance has been disposed.

Remarks

The NetworkStream.Write(Byte[], int, int) method starts at the specified offset and sends size bytes from the contents of buffer to the network. The NetworkStream.Write(Byte[], int, int) method blocks until the requested number of bytes is sent or a System.Net.Sockets.SocketException is thrown. If you receive a System.Net.Sockets.SocketException, use the SocketException.ErrorCode property to obtain the specific error code, and refer to the Windows Sockets version 2 API error code documentation in MSDN for a detailed description of the error.

Note:

Check to see if the System.Net.Sockets.NetworkStream is writable by accessing the NetworkStream.CanWrite property. If you attempt to write to a System.Net.Sockets.NetworkStream that is not writable, you will get an System.IO.IOException. If you receive an System.IO.IOException, check the Exception.InnerException property to determine if it was caused by a System.Net.Sockets.SocketException.

Requirements

Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0