SslStream.Write Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Scrive i dati in questo flusso.
Overload
| Nome | Descrizione |
|---|---|
| Write(Byte[]) |
Scrive i dati specificati in questo flusso. |
| Write(Byte[], Int32, Int32) |
Scrivere il numero specificato di Bytes nel flusso sottostante usando il buffer e l'offset specificati. |
Write(Byte[])
Scrive i dati specificati in questo flusso.
public:
void Write(cli::array <System::Byte> ^ buffer);
public void Write(byte[] buffer);
override this.Write : byte[] -> unit
Public Sub Write (buffer As Byte())
Parametri
Eccezioni
buffer è null.
Operazione di scrittura non riuscita.
È già in corso un'operazione di scrittura.
Questo oggetto è stato chiuso.
L'autenticazione non è stata eseguita.
Esempio
Nell'esempio di codice seguente viene illustrato come scrivere in un oggetto autenticato 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
Commenti
Questo metodo si blocca al termine dell'operazione. Per impedire il blocco al termine dell'operazione, utilizzare il BeginWrite metodo .
Non è possibile chiamare questo metodo fino a quando non è stata eseguita correttamente l'autenticazione. Per autenticare chiamare uno dei AuthenticateAsClientmetodi , o BeginAuthenticateAsClient, AuthenticateAsServer. BeginAuthenticateAsServer
La SslStream classe non supporta più operazioni di scrittura simultanee.
Si applica a
Write(Byte[], Int32, Int32)
Scrivere il numero specificato di Bytes nel flusso sottostante usando il buffer e l'offset specificati.
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)
Parametri
- offset
- Int32
Oggetto Int32 contenente la posizione in base zero in in buffer cui iniziare la lettura dei byte da scrivere nel flusso.
Eccezioni
buffer è null.
offset è minore di zero.
oppure
offset è maggiore della lunghezza di buffer.
oppure
offset + count è maggiore della lunghezza di buffer.
Operazione di scrittura non riuscita.
È già in corso un'operazione di scrittura.
Questo oggetto è stato chiuso.
L'autenticazione non è stata eseguita.
Commenti
Questo metodo si blocca al termine dell'operazione. Per impedire il blocco mentre l'operazione completa l'operazione, utilizzare il BeginWrite metodo .
Non è possibile chiamare questo metodo fino a quando non è stata eseguita correttamente l'autenticazione. Per autenticare chiamare uno dei AuthenticateAsClientmetodi , o BeginAuthenticateAsClient, AuthenticateAsServer. BeginAuthenticateAsServer
La SslStream classe non supporta più operazioni di scrittura simultanee.