SslStream.Write Metoda

Definicja

Zapisuje dane w tym strumieniu.

Przeciążenia

Nazwa Opis
Write(Byte[])

Zapisuje określone dane w tym strumieniu.

Write(ReadOnlySpan<Byte>)

Po zastąpieniu w klasie pochodnej zapisuje sekwencję bajtów do bieżącego strumienia i przechodzi bieżącą pozycję w tym strumieniu przez liczbę zapisanych bajtów.

Write(Byte[], Int32, Int32)

Zapisz określoną liczbę Bytes do bazowego strumienia przy użyciu określonego buforu i przesunięcia.

Write(Byte[])

Źródło:
SslStream.cs
Źródło:
SslStream.cs
Źródło:
SslStream.cs
Źródło:
SslStream.cs
Źródło:
SslStream.cs

Zapisuje określone dane w tym strumieniu.

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

Parametry

buffer
Byte[]

Tablica dostarczająca Byte bajty zapisywane do strumienia.

Wyjątki

Parametr buffer ma wartość null.

Operacja zapisu nie powiodła się.

Trwa już operacja zapisu.

Ten obiekt został zamknięty.

Uwierzytelnianie nie wystąpiło.

Przykłady

W poniższym przykładzie kodu pokazano pisanie do uwierzytelnionego SslStreamelementu .

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

Uwagi

Ta metoda blokuje ukończenie operacji. Aby zapobiec blokowaniu podczas wykonywania operacji, użyj BeginWrite metody .

Nie można wywołać tej metody do momentu pomyślnego uwierzytelnienia. Aby uwierzytelnić metodę AuthenticateAsClient, lub BeginAuthenticateAsClient, AuthenticateAsServerBeginAuthenticateAsServer należy uwierzytelnić.

Klasa SslStream nie obsługuje wielu równoczesnych operacji zapisu.

Dotyczy

Write(ReadOnlySpan<Byte>)

Źródło:
SslStream.cs
Źródło:
SslStream.cs
Źródło:
SslStream.cs

Po zastąpieniu w klasie pochodnej zapisuje sekwencję bajtów do bieżącego strumienia i przechodzi bieżącą pozycję w tym strumieniu przez liczbę zapisanych bajtów.

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))

Parametry

buffer
ReadOnlySpan<Byte>

Region pamięci. Ta metoda kopiuje zawartość tego regionu do bieżącego strumienia.

Dotyczy

Write(Byte[], Int32, Int32)

Źródło:
SslStream.cs
Źródło:
SslStream.cs
Źródło:
SslStream.cs
Źródło:
SslStream.cs
Źródło:
SslStream.cs

Zapisz określoną liczbę Bytes do bazowego strumienia przy użyciu określonego buforu i przesunięcia.

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)

Parametry

buffer
Byte[]

Tablica dostarczająca Byte bajty zapisywane do strumienia.

offset
Int32

Element Int32 zawierający lokalizację opartą na zerach, w buffer której należy rozpocząć odczytywanie bajtów, które mają być zapisywane w strumieniu.

count
Int32

Element Int32 zawierający liczbę bajtów do odczytania z elementu buffer.

Wyjątki

Parametr buffer ma wartość null.

Parametr offset ma wartość niższą niż zero.

— lub —

offsetwartość jest większa niż długość .buffer

— lub —

offset + liczba jest większa niż długość buffer.

Operacja zapisu nie powiodła się.

Trwa już operacja zapisu.

Ten obiekt został zamknięty.

Uwierzytelnianie nie wystąpiło.

Uwagi

Ta metoda blokuje ukończenie operacji. Aby zapobiec blokowaniu podczas wykonywania operacji zakończonej operacji, użyj BeginWrite metody .

Nie można wywołać tej metody do momentu pomyślnego uwierzytelnienia. Aby uwierzytelnić metodę AuthenticateAsClient, lub BeginAuthenticateAsClient, AuthenticateAsServerBeginAuthenticateAsServer należy uwierzytelnić.

Klasa SslStream nie obsługuje wielu równoczesnych operacji zapisu.

Dotyczy