Namespace:
System.Net.Sockets
Assembly:
System (in System.dll)
Visual Basic (Declaration)
Public Overrides Sub Write ( _
buffer As Byte(), _
offset As Integer, _
size As Integer _
)
Dim instance As NetworkStream
Dim buffer As Byte()
Dim offset As Integer
Dim size As Integer
instance.Write(buffer, offset, size)
public override void Write(
byte[] buffer,
int offset,
int size
)
public:
virtual void Write(
array<unsigned char>^ buffer,
int offset,
int size
) override
public override function Write(
buffer : byte[],
offset : int,
size : int
)
| Exception | Condition |
|---|
| ArgumentNullException | The buffer parameter is nullNothingnullptra null reference (Nothing in Visual Basic). |
| ArgumentOutOfRangeException | The offset parameter is less than 0. -or- The offset parameter is greater than the length of buffer. -or- The size parameter is less than 0. -or- The size parameter is greater than the length of buffer minus the value of the offset parameter. |
| IOException | There was a failure while writing to the network. -or- An error occurred when accessing the socket. See the Remarks section for more information. |
| ObjectDisposedException | The NetworkStream is closed. -or- There was a failure reading from the network. |
The Write method starts at the specified offset and sends size bytes from the contents of buffer to the network. The Write method blocks until the requested number of bytes is sent or a SocketException is thrown. If you receive a 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.
The following code example checks to see whether the NetworkStream is writable. If it is, then Write is used to write a small message.
' Examples for CanWrite, and CanWrite
' Check to see if this NetworkStream is writable.
If myNetworkStream.CanWrite Then
Dim myWriteBuffer As Byte() = Encoding.ASCII.GetBytes("Are you receiving this message?")
myNetworkStream.Write(myWriteBuffer, 0, myWriteBuffer.Length)
Else
Console.WriteLine("Sorry. You cannot write to this NetworkStream.")
End If
// Examples for CanWrite, and CanWrite
// Check to see if this NetworkStream is writable.
if (myNetworkStream.CanWrite){
byte[] myWriteBuffer = Encoding.ASCII.GetBytes("Are you receiving this message?");
myNetworkStream.Write(myWriteBuffer, 0, myWriteBuffer.Length);
}
else{
Console.WriteLine("Sorry. You cannot write to this NetworkStream.");
}
// Examples for CanWrite, and CanWrite
// Check to see if this NetworkStream is writable.
if ( myNetworkStream->CanWrite )
{
array<Byte>^ myWriteBuffer = Encoding::ASCII->GetBytes(
"Are you receiving this message?" );
myNetworkStream->Write( myWriteBuffer, 0, myWriteBuffer->Length );
}
else
{
Console::WriteLine( "Sorry. You cannot write to this NetworkStream." );
}
// Check to see if this NetworkStream is writable.
if (myNetworkStream->CanWrite) {
Byte myWriteBuffer[] = Encoding::ASCII->GetBytes(S"Are you receiving this message?");
myNetworkStream->Write(myWriteBuffer, 0, myWriteBuffer->Length);
} else {
Console::WriteLine(S"Sorry. You cannot write to this NetworkStream.");
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 3.5, 2.0, 1.0
Reference