SslStream.Write 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이 스트림에 데이터를 씁니다.
오버로드
| Write(Byte[]) |
지정된 데이터를 이 스트림에 씁니다. |
| Write(Byte[], Int32, Int32) |
지정된 버퍼와 오프셋을 사용하여 지정된 수의 Byte를 기본 스트림에 씁니다. |
Write(Byte[])
- Source:
- SslStream.cs
- Source:
- SslStream.cs
- Source:
- 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이(가) null인 경우
쓰기 작업이 실패했습니다.
쓰기 작업을 진행 중인 경우
이 개체가 닫힌 경우.
인증이 수행되지 않은 경우.
예제
다음 코드 예제에서는 인증된 SslStream에 쓰는 방법을 보여 줍니다.
static void ProcessClient( TcpClient^ client )
{
// A client has connected. Create the
// SslStream using the client's network stream.
SslStream^ sslStream = gcnew SslStream( client->GetStream(),false );
// Authenticate the server but don't require the client to authenticate.
try
{
sslStream->AuthenticateAsServer( serverCertificate, false, true );
// false == no client cert required; true == check cert revocation.
// 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( L"Waiting for client message..." );
String^ messageData = ReadMessage( sslStream );
Console::WriteLine( L"Received: {0}", messageData );
// Write a message to the client.
array<Byte>^message = Encoding::UTF8->GetBytes( L"Hello from the server.<EOF>" );
Console::WriteLine( L"Sending hello message." );
sslStream->Write( message );
}
catch ( AuthenticationException^ e )
{
Console::WriteLine( L"Exception: {0}", e->Message );
if ( e->InnerException != nullptr )
{
Console::WriteLine( L"Inner exception: {0}", e->InnerException->Message );
}
Console::WriteLine( L"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();
}
}
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 사용합니다.
성공적으로 인증될 때까지 이 메서드를 호출할 수 없습니다. 인증하려면 , 또는 BeginAuthenticateAsClient, AuthenticateAsServerBeginAuthenticateAsServer 메서드 중 AuthenticateAsClient하나를 호출합니다.
클래스는 SslStream 여러 동시 쓰기 작업을 지원하지 않습니다.
적용 대상
Write(Byte[], Int32, Int32)
- Source:
- SslStream.cs
- Source:
- SslStream.cs
- Source:
- 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은 null입니다.
offset가 0보다 작은 경우
또는
offset이 buffer의 길이보다 큽니다.
또는
offset과 count의 합이 buffer 길이보다 큽니다.
쓰기 작업이 실패했습니다.
쓰기 작업을 진행 중인 경우
이 개체가 닫힌 경우.
인증이 수행되지 않은 경우.
설명
이 메서드는 작업이 완료되는 동안 차단됩니다. 작업이 완료되는 동안 차단을 방지하려면 메서드를 BeginWrite 사용합니다.
성공적으로 인증될 때까지 이 메서드를 호출할 수 없습니다. 인증하려면 , 또는 BeginAuthenticateAsClient, AuthenticateAsServerBeginAuthenticateAsServer 메서드 중 AuthenticateAsClient하나를 호출합니다.
클래스는 SslStream 여러 동시 쓰기 작업을 지원하지 않습니다.