NetworkStream.Write メソッド
定義
オーバーロード
Write(ReadOnlySpan<Byte>) |
読み取り専用のバイト スパンから NetworkStream にデータを書き込みます。Writes data to the NetworkStream from a read-only byte span. |
Write(Byte[], Int32, Int32) |
指定された範囲のバイト配列から NetworkStream にデータを書き込みます。Writes data to the NetworkStream from a specified range of a byte array. |
Write(ReadOnlySpan<Byte>)
読み取り専用のバイト スパンから NetworkStream にデータを書き込みます。Writes data to the NetworkStream from a read-only byte span.
public:
override void Write(ReadOnlySpan<System::Byte> buffer);
public override void Write (ReadOnlySpan<byte> buffer);
override this.Write : ReadOnlySpan<byte> -> unit
Public Overrides Sub Write (buffer As ReadOnlySpan(Of Byte))
パラメーター
- buffer
- ReadOnlySpan<Byte>
NetworkStream に書き込むデータ。The data to write to the NetworkStream.
例外
NetworkStream では、書き込みがサポートされません。The NetworkStream does not support writing.
ソケットへのアクセス中にエラーが発生しました。An error occurred when accessing the socket.
- または --or-
ネットワークへの書き込み中にエラーが発生しました。There was a failure while writing to the network.
NetworkStream が閉じています。The NetworkStream is closed.
注釈
このメソッドは、のすべてのバイト buffer
をネットワークに送信します。This method sends all bytes in buffer
to the network. メソッドは、要求された Write
バイト数が送信されるか、がスローされるまでブロックし SocketException ます。The Write
method blocks until the requested number of bytes is sent or a SocketException is thrown.
注意
NetworkStreamプロパティを呼び出して、が書き込み可能かどうかを確認し CanWrite ます。Check to see if the NetworkStream is writable by calling the CanWrite property. 書き込み可能でないに書き込もうとすると、が NetworkStream 取得され InvalidOperationException ます。If you attempt to write to a NetworkStream that is not writable, you will get an InvalidOperationException.
注意
を受け取った場合は、プロパティをチェックして、が IOException InnerException 原因であるかどうかを確認し SocketException ます。If you receive an IOException, check the InnerException property to determine if it was caused by a SocketException. その場合は、プロパティを使用して ErrorCode 特定のエラーコードを取得し、エラーの詳細な説明については、Windows Sockets version 2 API エラーコードのドキュメントを参照してください。If so, use the ErrorCode property to obtain the specific error code and refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.
適用対象
Write(Byte[], Int32, Int32)
指定された範囲のバイト配列から NetworkStream にデータを書き込みます。Writes data to the NetworkStream from a specified range of a byte array.
public:
override void Write(cli::array <System::Byte> ^ buffer, int offset, int size);
public override void Write (byte[] buffer, int offset, int size);
override this.Write : byte[] * int * int -> unit
Public Overrides Sub Write (buffer As Byte(), offset As Integer, size As Integer)
パラメーター
- buffer
- Byte[]
Byte に書き込むデータを格納する NetworkStream 型の配列。An array of type Byte that contains the data to write to the NetworkStream.
- offset
- Int32
データの書き込みを開始する buffer
内の場所。The location in buffer
from which to start writing data.
- size
- Int32
NetworkStream に書き込むバイト数。The number of bytes to write to the NetworkStream.
例外
buffer
パラメーターが null
です。The buffer
parameter is null
.
offset
パラメーターが 0 未満です。The offset
parameter is less than 0.
- または --or-
offset
パラメーターが buffer
の長さを超えています。The offset
parameter is greater than the length of buffer
.
- または --or-
size
パラメーターが 0 未満です。The size
parameter is less than 0.
- または --or-
size
パラメーターが、buffer
パラメーターの値を引いた offset
の長さを超えています。The size
parameter is greater than the length of buffer
minus the value of the offset
parameter.
NetworkStream では、書き込みがサポートされません。The NetworkStream does not support writing.
ソケットへのアクセス中にエラーが発生しました。An error occurred when accessing the socket.
- または --or-
ネットワークへの書き込み中にエラーが発生しました。There was a failure while writing to the network.
NetworkStream が閉じています。The NetworkStream is closed.
例
次のコード例では、が書き込み可能かどうかを確認し NetworkStream ます。The following code example checks to see whether the NetworkStream is writable. の場合は、を Write 使用して小さいメッセージを書き込みます。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 )
{
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." );
}
// 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 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
注釈
このメソッドは、指定されたから開始 offset
し、 size
の内容から buffer
ネットワークにバイトを送信します。This method starts at the specified offset
and sends size
bytes from the contents of buffer
to the network. メソッドは、要求された Write
バイト数が送信されるか、がスローされるまでブロックし SocketException ます。The Write
method blocks until the requested number of bytes is sent or a SocketException is thrown.
注意
NetworkStreamプロパティを呼び出して、が書き込み可能かどうかを確認し CanWrite ます。Check to see if the NetworkStream is writable by calling the CanWrite property. 書き込み可能でないに書き込もうとすると、が NetworkStream 取得され InvalidOperationException ます。If you attempt to write to a NetworkStream that is not writable, you will get an InvalidOperationException.
注意
を受け取った場合は、プロパティをチェックして、が IOException InnerException 原因であるかどうかを確認し SocketException ます。If you receive an IOException, check the InnerException property to determine if it was caused by a SocketException. その場合は、プロパティを使用して ErrorCode 特定のエラーコードを取得し、エラーの詳細な説明については、Windows Sockets version 2 API エラーコードのドキュメントを参照してください。If so, use the ErrorCode property to obtain the specific error code and refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.