SslStream.Write メソッド

定義

このストリームにデータを書き込みます。

オーバーロード

名前 説明
Write(Byte[])

指定したデータをこのストリームに書き込みます。

Write(ReadOnlySpan<Byte>)

派生クラスでオーバーライドされると、現在のストリームにバイト シーケンスを書き込み、書き込まれたバイト数だけこのストリーム内の現在の位置を進めます。

Write(Byte[], Int32, Int32)

指定したバッファーとオフセットを使用して、指定した数の Byteを基になるストリームに書き込みます。

Write(Byte[])

ソース:
SslStream.cs
ソース:
SslStream.cs
ソース:
SslStream.cs
ソース:
SslStream.cs
ソース:
SslStream.cs

指定したデータをこのストリームに書き込みます。

public:
 void Write(cli::array <System::Byte> ^ buffer);
public void Write(byte[] buffer);
override this.Write : byte[] -> unit
Public Sub Write (buffer As Byte())

パラメーター

buffer
Byte[]

ストリームに書き込まれたバイトを提供する Byte 配列。

例外

buffernullです。

書き込み操作に失敗しました。

書き込み操作は既に進行中です。

このオブジェクトは閉じられています。

認証が行われません。

次のコード例は、認証された SslStreamへの書き込みを示しています。

static void ProcessClient (TcpClient client)
{
    // A client has connected. Create the
    // SslStream using the client's network stream.
    SslStream sslStream = new SslStream(
        client.GetStream(), false);
    // Authenticate the server but don't require the client to authenticate.
    try
    {
        sslStream.AuthenticateAsServer(serverCertificate, clientCertificateRequired: false, checkCertificateRevocation: true);

        // Display the properties and settings for the authenticated stream.
        DisplaySecurityLevel(sslStream);
        DisplaySecurityServices(sslStream);
        DisplayCertificateInformation(sslStream);
        DisplayStreamProperties(sslStream);

        // Set timeouts for the read and write to 5 seconds.
        sslStream.ReadTimeout = 5000;
        sslStream.WriteTimeout = 5000;
        // Read a message from the client.
        Console.WriteLine("Waiting for client message...");
        string messageData = ReadMessage(sslStream);
        Console.WriteLine("Received: {0}", messageData);

        // Write a message to the client.
        byte[] message = Encoding.UTF8.GetBytes("Hello from the server.<EOF>");
        Console.WriteLine("Sending hello message.");
        sslStream.Write(message);
    }
    catch (AuthenticationException e)
    {
        Console.WriteLine("Exception: {0}", e.Message);
        if (e.InnerException != null)
        {
            Console.WriteLine("Inner exception: {0}", e.InnerException.Message);
        }
        Console.WriteLine ("Authentication failed - closing the connection.");
        sslStream.Close();
        client.Close();
        return;
    }
    finally
    {
        // The client stream will be closed with the sslStream
        // because we specified this behavior when creating
        // the sslStream.
        sslStream.Close();
        client.Close();
    }
}
Private Shared Sub ProcessClient(client As TcpClient)
    ' A client has connected. Create the 
    ' SslStream using the client's network stream.
    Dim sslStream = New SslStream(client.GetStream(), False)

    Try

        sslStream.AuthenticateAsServer(serverCertificate, clientCertificateRequired:=False, checkCertificateRevocation:=True)
        ' Display the properties And settings for the authenticated stream.
        DisplaySecurityLevel(sslStream)
        DisplaySecurityServices(sslStream)
        DisplayCertificateInformation(sslStream)
        DisplayStreamProperties(sslStream)

        ' Set timeouts for the read and write to 5 seconds.
        sslStream.ReadTimeout = 5000
        sslStream.WriteTimeout = 5000

        ' Read a message from the client.   
        Console.WriteLine("Waiting for client message...")
        Dim messageData As String = ReadMessage(sslStream)
        Console.WriteLine("Received: {0}", messageData)

        ' Write a message to the client.
        Dim message As Byte() = Encoding.UTF8.GetBytes("Hello from the server.<EOF>")
        Console.WriteLine("Sending hello message.")
        sslStream.Write(message)
    Catch e As AuthenticationException
        Console.WriteLine("Exception: {0}", e.Message)

        If e.InnerException IsNot Nothing Then
            Console.WriteLine("Inner exception: {0}", e.InnerException.Message)
        End If

        Console.WriteLine("Authentication failed - closing the connection.")
        sslStream.Close()
        client.Close()
        Return
    Finally
        ' The client stream will be closed with the sslStream
        ' because we specified this behavior when creating
        ' the sslStream.
        sslStream.Close()
        client.Close()
    End Try
End Sub

注釈

このメソッドは、操作の完了中にブロックします。 操作の完了中にブロックされないようにするには、 BeginWrite メソッドを使用します。

正常に認証されるまで、このメソッドを呼び出すことはできません。 認証するには、 AuthenticateAsClientBeginAuthenticateAsClientAuthenticateAsServerBeginAuthenticateAsServer のいずれかのメソッドを呼び出します。

SslStream クラスは、複数の同時書き込み操作をサポートしていません。

適用対象

Write(ReadOnlySpan<Byte>)

ソース:
SslStream.cs
ソース:
SslStream.cs
ソース:
SslStream.cs

派生クラスでオーバーライドされると、現在のストリームにバイト シーケンスを書き込み、書き込まれたバイト数だけこのストリーム内の現在の位置を進めます。

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>

メモリの領域。 このメソッドは、この領域の内容を現在のストリームにコピーします。

適用対象

Write(Byte[], Int32, Int32)

ソース:
SslStream.cs
ソース:
SslStream.cs
ソース:
SslStream.cs
ソース:
SslStream.cs
ソース:
SslStream.cs

指定したバッファーとオフセットを使用して、指定した数の Byteを基になるストリームに書き込みます。

public:
 override void Write(cli::array <System::Byte> ^ buffer, int offset, int count);
public override void Write(byte[] buffer, int offset, int count);
override this.Write : byte[] * int * int -> unit
Public Overrides Sub Write (buffer As Byte(), offset As Integer, count As Integer)

パラメーター

buffer
Byte[]

ストリームに書き込まれたバイトを提供する Byte 配列。

offset
Int32

ストリームに書き込まれるバイトの読み取りを開始するInt32の 0 から始まる位置を含むbuffer

count
Int32

Int32から読み取るバイト数を含むbuffer

例外

buffernullです。

offset が 0 未満です。

-又は-

offsetbufferの長さを超えています。

-又は-

offset + count が bufferの長さを超えています。

書き込み操作に失敗しました。

書き込み操作は既に進行中です。

このオブジェクトは閉じられています。

認証が行われません。

注釈

このメソッドは、操作の完了中にブロックします。 操作の完了中にブロックされないようにするには、 BeginWrite メソッドを使用します。

正常に認証されるまで、このメソッドを呼び出すことはできません。 認証するには、 AuthenticateAsClientBeginAuthenticateAsClientAuthenticateAsServerBeginAuthenticateAsServer のいずれかのメソッドを呼び出します。

SslStream クラスは、複数の同時書き込み操作をサポートしていません。

適用対象