NegotiateStream クラス

定義

クライアント サーバー通信で Negotiate セキュリティ プロトコルを使用してクライアントの認証と (オプションで) サーバーの認証を行うストリームを提供します。

public ref class NegotiateStream : System::Net::Security::AuthenticatedStream
public class NegotiateStream : System.Net.Security.AuthenticatedStream
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public class NegotiateStream : System.Net.Security.AuthenticatedStream
type NegotiateStream = class
    inherit AuthenticatedStream
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
type NegotiateStream = class
    inherit AuthenticatedStream
Public Class NegotiateStream
Inherits AuthenticatedStream
継承
継承
属性

次の例では、 を使用するクライアントとサーバーの接続のクライアント側を NegotiateStream示します。 クライアントは認証を行い、サーバーに非同期的にメッセージを送信します。

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Net::Security;
using namespace System::Net::Sockets;
using namespace System::Text;

// The following class displays the properties of an authenticatedStream.
public ref class AuthenticatedStreamReporter
{
public:
   static void DisplayProperties( AuthenticatedStream^ stream )
   {
      Console::WriteLine( L"IsAuthenticated: {0}", stream->IsAuthenticated );
      Console::WriteLine( L"IsMutuallyAuthenticated: {0}", stream->IsMutuallyAuthenticated );
      Console::WriteLine( L"IsEncrypted: {0}", stream->IsEncrypted );
      Console::WriteLine( L"IsSigned: {0}", stream->IsSigned );
      Console::WriteLine( L"IsServer: {0}", stream->IsServer );
   }

};


public ref class ASynchronousAuthenticatingTcpClient
{
private:
   static TcpClient^ client = nullptr;

public:
   void Main()
   {
      
      // Establish the remote endpoint for the socket.
      // For this example, use the local machine.
      IPHostEntry^ ipHostInfo = Dns::GetHostEntry( Dns::GetHostName() );
      IPAddress^ ipAddress = ipHostInfo->AddressList[ 0 ];
      
      // Client and server use port 11000. 
      IPEndPoint^ remoteEP = gcnew IPEndPoint( ipAddress,11000 );
      
      // Create a TCP/IP socket.
      client = gcnew TcpClient;
      
      // Connect the socket to the remote endpoint.
      client->Connect( remoteEP );
      Console::WriteLine( L"Client connected to {0}.", remoteEP );
      
      // Ensure the client does not close when there is 
      // still data to be sent to the server.
      client->LingerState = (gcnew LingerOption( true,0 ));
      
      // Request authentication.
      NetworkStream^ clientStream = client->GetStream();
      NegotiateStream^ authStream = gcnew NegotiateStream( clientStream,false );
      
      // Pass the NegotiateStream as the AsyncState object 
      // so that it is available to the callback delegate.
      IAsyncResult^ ar = authStream->BeginAuthenticateAsClient( gcnew AsyncCallback( EndAuthenticateCallback ), authStream );
      
      Console::WriteLine( L"Client waiting for authentication..." );
      
      // Wait until the result is available.
      ar->AsyncWaitHandle->WaitOne();
      
      // Display the properties of the authenticated stream.
      AuthenticatedStreamReporter::DisplayProperties( authStream );
      
      // Send a message to the server.
      // Encode the test data into a byte array.
      array<Byte>^message = Encoding::UTF8->GetBytes( L"Hello from the client." );
      ar = authStream->BeginWrite( message, 0, message->Length, gcnew AsyncCallback( EndWriteCallback ), authStream );
      
      ar->AsyncWaitHandle->WaitOne();
      Console::WriteLine( L"Sent {0} bytes.", message->Length );
      
      // Close the client connection.
      authStream->Close();
      Console::WriteLine( L"Client closed." );
   }


   // The following method is called when the authentication completes.
   static void EndAuthenticateCallback( IAsyncResult^ ar )
   {
      Console::WriteLine( L"Client ending authentication..." );
      NegotiateStream^ authStream = dynamic_cast<NegotiateStream^>(ar->AsyncState);
      
      // End the asynchronous operation.
      authStream->EndAuthenticateAsClient( ar );
      
      //         Console.WriteLine("AllowedImpersonation: {0}", authStream.AllowedImpersonation);
   }


   // The following method is called when the write operation completes.
   static void EndWriteCallback( IAsyncResult^ ar )
   {
      Console::WriteLine( L"Client ending write operation..." );
      NegotiateStream^ authStream = dynamic_cast<NegotiateStream^>(ar->AsyncState);
      
      // End the asynchronous operation.
      authStream->EndWrite( ar );
   }

};

void main()
{
   ASynchronousAuthenticatingTcpClient^ aatc = gcnew ASynchronousAuthenticatingTcpClient;
   aatc->Main();
}
using System;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Text;

namespace Examples.NegotiateStreamExample
{
    public class ASynchronousAuthenticatingTcpClient
    {
        static TcpClient client = null;

        public static void Main(String[] args)
        {
            // Establish the remote endpoint for the socket.
            // For this example, use the local machine.
            IPHostEntry ipHostInfo = Dns.GetHostEntry("localhost");
            IPAddress ipAddress = ipHostInfo.AddressList[0];
            // Client and server use port 11000.
            IPEndPoint remoteEP = new IPEndPoint(ipAddress, 11000);
            // Create a TCP/IP socket.
            client = new TcpClient();
            // Connect the socket to the remote endpoint.
            client.Connect(remoteEP);
            Console.WriteLine("Client connected to {0}.", remoteEP.ToString());
            // Ensure the client does not close when there is
            // still data to be sent to the server.
            client.LingerState = new LingerOption(true, 0);
            // Request authentication.
            NetworkStream clientStream = client.GetStream();
            NegotiateStream authStream = new NegotiateStream(clientStream, false);
            // Pass the NegotiateStream as the AsyncState object
            // so that it is available to the callback delegate.
            Task authenticateTask = authStream
                .AuthenticateAsClientAsync()
                .ContinueWith(task =>
                {
                    Console.WriteLine("Client ending authentication...");
                    Console.WriteLine("ImpersonationLevel: {0}", authStream.ImpersonationLevel);
                });

            Console.WriteLine("Client waiting for authentication...");
            // Wait until the result is available.
            authenticateTask.Wait();
            // Display the properties of the authenticated stream.
            AuthenticatedStreamReporter.DisplayProperties(authStream);
            // Send a message to the server.
            // Encode the test data into a byte array.
            byte[] message = Encoding.UTF8.GetBytes("Hello from the client.");
            Task writeTask = authStream
                .WriteAsync(message, 0, message.Length)
                .ContinueWith(task =>
                {
                    Console.WriteLine("Client ending write operation...");
                });

            writeTask.Wait();
            Console.WriteLine("Sent {0} bytes.", message.Length);
            // Close the client connection.
            authStream.Close();
            Console.WriteLine("Client closed.");
        }
    }

    // The following class displays the properties of an authenticatedStream.
    public class AuthenticatedStreamReporter
    {
        public static void DisplayProperties(AuthenticatedStream stream)
        {
            Console.WriteLine("IsAuthenticated: {0}", stream.IsAuthenticated);
            Console.WriteLine("IsMutuallyAuthenticated: {0}", stream.IsMutuallyAuthenticated);
            Console.WriteLine("IsEncrypted: {0}", stream.IsEncrypted);
            Console.WriteLine("IsSigned: {0}", stream.IsSigned);
            Console.WriteLine("IsServer: {0}", stream.IsServer);
        }
    }
}
Imports System.Text
Imports System.Net.Sockets
Imports System.Net.Security
Imports System.Net

Namespace Examples.NegotiateStreamExample

    Public Class ASynchronousAuthenticatingTcpClient

        Shared client As TcpClient = Nothing

        Public Shared Sub Main(args As String())
            ' Establish the remote endpoint for the socket.
            ' For this example, use the local machine.
            Dim ipHostInfo = Dns.GetHostEntry("localhost")
            Dim ipAddress = ipHostInfo.AddressList(0)

            ' Client and server use port 11000. 
            Dim remoteEP As New IPEndPoint(ipAddress, 11000)

            ' Create a TCP/IP socket.
            client = New TcpClient()

            ' Connect the socket to the remote endpoint.
            client.Connect(remoteEP)
            Console.WriteLine("Client connected to {0}.", remoteEP.ToString())

            ' Ensure the client does not close when there is 
            ' still data to be sent to the server.
            client.LingerState = (New LingerOption(True, 0))

            ' Request authentication.
            Dim clientStream = client.GetStream()
            Dim authStream As New NegotiateStream(clientStream, False)

            ' Pass the NegotiateStream as the AsyncState object 
            ' so that it is available to the callback delegate.
            Dim ar = authStream.BeginAuthenticateAsClient(
                New AsyncCallback(AddressOf EndAuthenticateCallback), authStream)

            Console.WriteLine("Client waiting for authentication...")

            ' Wait until the result is available.
            ar.AsyncWaitHandle.WaitOne()

            ' Display the properties of the authenticated stream.
            AuthenticatedStreamReporter.DisplayProperties(authStream)

            ' Send a message to the server.
            ' Encode the test data into a byte array.
            Dim message = Encoding.UTF8.GetBytes("Hello from the client.")
            ar = authStream.BeginWrite(message, 0, message.Length, 
                New AsyncCallback(AddressOf EndWriteCallback), authStream)
            ar.AsyncWaitHandle.WaitOne()
            Console.WriteLine("Sent {0} bytes.", message.Length)

            ' Close the client connection.
            authStream.Close()
            Console.WriteLine("Client closed.")

        End Sub

        ' The following method is called when the authentication completes.
        Public Shared Sub EndAuthenticateCallback(ar As IAsyncResult)

            Console.WriteLine("Client ending authentication...")
            Dim authStream = CType(ar.AsyncState, NegotiateStream)
            Console.WriteLine("ImpersonationLevel: {0}", authStream.ImpersonationLevel)

            ' End the asynchronous operation.
            authStream.EndAuthenticateAsClient(ar)

        End Sub

        ' The following method is called when the write operation completes.
        Public Shared Sub EndWriteCallback(ar As IAsyncResult)

            Console.WriteLine("Client ending write operation...")
            Dim authStream = CType(ar.AsyncState, NegotiateStream)

            ' End the asynchronous operation.
            authStream.EndWrite(ar)

        End Sub
    End Class

    ' The following class displays the properties of an AuthenticatedStream.
    Public Class AuthenticatedStreamReporter
        Public Shared Sub DisplayProperties(stream As AuthenticatedStream)
            Console.WriteLine("IsAuthenticated: {0}", stream.IsAuthenticated)
            Console.WriteLine("IsMutuallyAuthenticated: {0}", stream.IsMutuallyAuthenticated)
            Console.WriteLine("IsEncrypted: {0}", stream.IsEncrypted)
            Console.WriteLine("IsSigned: {0}", stream.IsSigned)
            Console.WriteLine("IsServer: {0}", stream.IsServer)
        End Sub
    End Class
End Namespace

次のコード例は、 を使用 NegotiateStream してクライアントを認証し、クライアントから送信されたメッセージを読み取るクライアントとサーバーの接続のサーバー側を示しています。

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Net::Security;
using namespace System::Net::Sockets;
using namespace System::Security::Authentication;
using namespace System::Security::Principal;
using namespace System::Text;
using namespace System::IO;
using namespace System::Threading;

// ClientState is the AsyncState object.
private ref class ClientState
{
private:
   AuthenticatedStream^ authStream;
   TcpClient^ client;
   array<Byte>^buffer;
   StringBuilder^ message;
   ManualResetEvent^ waiter;

internal:
   ClientState( AuthenticatedStream^ a, TcpClient^ theClient )
   {
      authStream = a;
      client = theClient;
      message = nullptr;
      buffer = gcnew array<Byte>(2048);
      waiter = gcnew ManualResetEvent( false );
   }

internal:
   property TcpClient^ Client 
   {
      TcpClient^ get()
      {
         return client;
      }
   }

   property AuthenticatedStream^ AuthStream 
   {
      AuthenticatedStream^ get()
      {
         return authStream;
      }
  }

   property array<Byte>^ Buffer 
   {
      array<Byte>^ get()
      {
         return buffer;
      }

   }

   property StringBuilder^ Message 
   {
      StringBuilder^ get()
      {
         if ( message == nullptr )
                  message = gcnew StringBuilder;

         return message;
      }

   }

   property ManualResetEvent^ Waiter 
   {
      ManualResetEvent^ get()
      {
         return waiter;
      }

   }

};

public ref class AsynchronousAuthenticatingTcpListener
{
public:
   int Main()
   {
      
      // Create an IPv4 TCP/IP socket. 
      TcpListener^ listener = gcnew TcpListener( IPAddress::Any,11000 );
      
      // Listen for incoming connections.
      listener->Start();
      while ( true )
      {
         TcpClient^ clientRequest = nullptr;
         
         // Application blocks while waiting for an incoming connection.
         // Type CNTL-C to terminate the server.
         clientRequest = listener->AcceptTcpClient();
         Console::WriteLine( L"Client connected." );
         
         // A client has connected. 
         try
         {
            AuthenticateClient( clientRequest );
         }
         catch ( Exception^ e ) 
         {
            Console::WriteLine( e );
            continue;
         }

      }
   }


   static void AuthenticateClient( TcpClient^ clientRequest )
   {
      NetworkStream^ stream = clientRequest->GetStream();
      
      // Create the NegotiateStream.
      NegotiateStream^ authStream = gcnew NegotiateStream( stream,false );
      
      // Save the current client and NegotiateStream instance 
      // in a ClientState object.
      ClientState^ cState = gcnew ClientState( authStream,clientRequest );
      
      // Listen for the client authentication request.
      authStream->BeginAuthenticateAsServer( gcnew AsyncCallback( EndAuthenticateCallback ), cState );
      
      // Wait until the authentication completes.
      cState->Waiter->WaitOne();
      cState->Waiter->Reset();
      authStream->BeginRead( cState->Buffer, 0, cState->Buffer->Length, gcnew AsyncCallback( EndReadCallback ), cState );
      cState->Waiter->WaitOne();
      
      // Finished with the current client.
      authStream->Close();
      clientRequest->Close();
   }


   // The following method is invoked by the
   // BeginServerAuthenticate callback delegate.
   static void EndAuthenticateCallback( IAsyncResult^ ar )
   {
      
      // Get the saved data.
      ClientState^ cState = dynamic_cast<ClientState^>(ar->AsyncState);
      TcpClient^ clientRequest = cState->Client;
      NegotiateStream^ authStream = dynamic_cast<NegotiateStream^>(cState->AuthStream);
      Console::WriteLine( L"Ending authentication." );
      
      // Any exceptions that occurred during authentication are
      // thrown by the EndServerAuthenticate method.
      try
      {
         
         // This call blocks until the authentication is complete.
         authStream->EndAuthenticateAsServer( ar );
      }
      catch ( AuthenticationException^ e ) 
      {
         Console::WriteLine( e );
         Console::WriteLine( L"Authentication failed - closing connection." );
         cState->Waiter->Set();
         return;
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( e );
         Console::WriteLine( L"Closing connection." );
         cState->Waiter->Set();
         return;
      }

      
      // Display properties of the authenticated client.
      IIdentity^ id = authStream->RemoteIdentity;
      Console::WriteLine( L"{0} was authenticated using {1}.", id->Name, id->AuthenticationType );
      cState->Waiter->Set();
   }


   static void EndReadCallback( IAsyncResult^ ar )
   {
      
      // Get the saved data.
      ClientState^ cState = dynamic_cast<ClientState^>(ar->AsyncState);
      TcpClient^ clientRequest = cState->Client;
      NegotiateStream^ authStream = dynamic_cast<NegotiateStream^>(cState->AuthStream);
      
      // Get the buffer that stores the message sent by the client.
      int bytes = -1;
      
      // Read the client message.
      try
      {
         bytes = authStream->EndRead( ar );
         cState->Message->Append( Encoding::UTF8->GetChars( cState->Buffer, 0, bytes ) );
         if ( bytes != 0 )
         {
            authStream->BeginRead( cState->Buffer, 0, cState->Buffer->Length, gcnew AsyncCallback( EndReadCallback ), cState );
            return;
         }
      }
      catch ( Exception^ e ) 
      {
         
         // A real application should do something
         // useful here, such as logging the failure.
         Console::WriteLine( L"Client message exception:" );
         Console::WriteLine( e );
         cState->Waiter->Set();
         return;
      }

      IIdentity^ id = authStream->RemoteIdentity;
      Console::WriteLine( L"{0} says {1}", id->Name, cState->Message );
      cState->Waiter->Set();
   }

};

void main()
{
   AsynchronousAuthenticatingTcpListener^ aatl = gcnew AsynchronousAuthenticatingTcpListener;
   aatl->Main();
}

using System;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Security.Principal;
using System.Text;
using System.IO;
using System.Threading;

namespace Examples.NegotiateStreamExample
{
    public class AsynchronousAuthenticatingTcpListener
    {
        public static void Main()
        {
            // Create an IPv4 TCP/IP socket.
            TcpListener listener = new TcpListener(IPAddress.Any, 11000);
            // Listen for incoming connections.
            listener.Start();
            while (true)
            {
                TcpClient clientRequest;
                // Application blocks while waiting for an incoming connection.
                // Type CNTL-C to terminate the server.
                clientRequest = listener.AcceptTcpClient();
                Console.WriteLine("Client connected.");
                // A client has connected.
                try
                {
                    AuthenticateClient(clientRequest);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }

        public static void AuthenticateClient(TcpClient clientRequest)
        {
            NetworkStream stream = clientRequest.GetStream();
            // Create the NegotiateStream.
            NegotiateStream authStream = new NegotiateStream(stream, false);
            // Save the current client and NegotiateStream instance
            // in a ClientState object.
            ClientState cState = new ClientState(authStream, clientRequest);
            // Listen for the client authentication request.
            Task authTask = authStream
                .AuthenticateAsServerAsync()
                .ContinueWith(task => { EndAuthenticateCallback(cState); });

            // Any exceptions that occurred during authentication are
            // thrown by the EndAuthenticateAsServer method.
            try
            {
                // This call blocks until the authentication is complete.
                authTask.Wait();
            }
            catch (AuthenticationException e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Authentication failed - closing connection.");
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Closing connection.");
                return;
            }

            Task<int> readTask = authStream
                .ReadAsync(cState.Buffer, 0, cState.Buffer.Length);

            readTask
                .ContinueWith((task) => { EndReadCallback(cState, task.Result); })
                .Wait();
            // Finished with the current client.
            authStream.Close();
            clientRequest.Close();
        }

        private static void EndAuthenticateCallback(ClientState cState)
        {
            // Get the saved data.
            NegotiateStream authStream = (NegotiateStream)cState.AuthenticatedStream;
            Console.WriteLine("Ending authentication.");

            // Display properties of the authenticated client.
            IIdentity id = authStream.RemoteIdentity;
            Console.WriteLine("{0} was authenticated using {1}.",
                id.Name,
                id.AuthenticationType
            );
        }

        private static void EndReadCallback(ClientState cState, int bytes)
        {
            NegotiateStream authStream = (NegotiateStream)cState.AuthenticatedStream;
            // Read the client message.
            try
            {
                cState.Message.Append(Encoding.UTF8.GetChars(cState.Buffer, 0, bytes));
                if (bytes != 0)
                {
                    Task<int> readTask = authStream.ReadAsync(cState.Buffer, 0, cState.Buffer.Length);
                    readTask
                        .ContinueWith(task => { EndReadCallback(cState, task.Result); })
                        .Wait();

                    return;
                }
            }
            catch (Exception e)
            {
                // A real application should do something
                // useful here, such as logging the failure.
                Console.WriteLine("Client message exception:");
                Console.WriteLine(e);
                return;
            }
            IIdentity id = authStream.RemoteIdentity;
            Console.WriteLine("{0} says {1}", id.Name, cState.Message.ToString());
        }
    }
    // ClientState is the AsyncState object.
    internal class ClientState
    {
        private StringBuilder _message = null;

        internal ClientState(AuthenticatedStream a, TcpClient theClient)
        {
            AuthenticatedStream = a;
            Client = theClient;
        }
        internal TcpClient Client { get; }

        internal AuthenticatedStream AuthenticatedStream { get; }

        internal byte[] Buffer { get; } = new byte[2048];

        internal StringBuilder Message
        {
            get { return _message ??= new StringBuilder(); }
        }
    }
}

注釈

認証に クラスを NegotiateStream 使用し、クライアントとサーバーの間で送信される情報をセキュリティで保護します。 を使用すると NegotiateStream、次のことができます。

  • 偽装または委任のために、クライアントの資格情報をサーバーに送信します。

  • サーバー認証を要求します。

  • データを送信する前に暗号化または署名します。

情報を送信する前に認証を実行する必要があります。 クライアントは、認証が完了するまでブロックする同期 AuthenticateAsClient メソッド、または認証が完了するまでブロックしない非同期 BeginAuthenticateAsClient メソッドを使用して認証を要求します。 サーバーは、同期 AuthenticateAsServer または非同期 BeginAuthenticateAsServer の方法を使用して認証を要求します。 クライアント (必要に応じてサーバー) は、ネゴシエート セキュリティ プロトコルを使用して認証されます。 Kerberos プロトコルは、クライアントとサーバーの両方でサポートされている場合に認証に使用されます。それ以外の場合は NTLM が使用されます。 クラスは NegotiateStream 、セキュリティ サポート プロバイダー インターフェイス (SSPI) を使用して認証を実行します。

認証が成功したら、 プロパティと IsSigned プロパティをIsEncrypted確認して、 によってNegotiateStream使用されるセキュリティ サービスを決定し、転送中にデータをセキュリティで保護する必要があります。 プロパティを IsMutuallyAuthenticated 調べて、相互認証が行われたかどうかを確認します。 リモート クライアントまたはサーバーに関する情報は、 プロパティを RemoteIdentity 使用して取得できます。

認証に失敗した場合は、 または をAuthenticationExceptionInvalidCredentialException受け取ります。 この場合は、別の資格情報を使用して認証を再試行できます。

同期 Write メソッドまたは非同期 BeginWrite メソッドまたは WriteAsync メソッドを使用してデータを送信します。 同期 Read メソッドまたは非同期 ReadAsync メソッドまたは BeginRead メソッドを使用してデータを受信します。 暗号化や署名などのセキュリティ サービスが有効になっている場合、これらは によって NegotiateStreamデータに自動的に適用されます。

NegotiateStream 、 の作成時に指定したストリームを使用してデータを送信します NegotiateStream。 この基になるストリームを指定する場合は、 を閉じて NegotiateStream も基になるストリームを閉じるかどうかを指定できます。

コンストラクター

NegotiateStream(Stream)

指定した Stream を使用して NegotiateStream クラスの新しいインスタンスを初期化します。

NegotiateStream(Stream, Boolean)

指定した Stream とストリームを閉じる動作を使用して、NegotiateStream クラスの新しいインスタンスを初期化します。

プロパティ

CanRead

基になるストリームが読み取り可能かどうかを示す Boolean 値を取得します。

CanSeek

基になるストリームがシークできるかどうかを示す Boolean 値を取得します。

CanTimeout

基になるストリームがタイムアウトをサポートしているかどうかを示す Boolean 値を取得します。

CanWrite

基になるストリームが書き込み可能かどうかを示す Boolean 値を取得します。

ImpersonationLevel

サーバーでクライアントの資格情報を使用する方法を示す値を取得します。

InnerStream

この AuthenticatedStream がデータの送受信に使用するストリームを取得します。

(継承元 AuthenticatedStream)
IsAuthenticated

認証が成功したかどうかを示す Boolean 値を取得します。

IsEncrypted

この NegotiateStream がデータの暗号化を使用するかどうかを示す Boolean 値を取得します。

IsMutuallyAuthenticated

サーバーとクライアントの両方が認証されているかどうかを示す Boolean 値を取得します。

IsServer

この NegotiateStream が使用する接続のローカル側がサーバーとして認証されたかどうかを示す Boolean 値を取得します。

IsSigned

このストリームを使用して送信されるデータに署名するかどうかを示す Boolean 値を取得します。

LeaveInnerStreamOpen

この AuthenticatedStream がデータの送受信に使用するストリームが、開いたままになっているかどうかを示す値を取得します。

(継承元 AuthenticatedStream)
Length

基になるストリームの長さを取得します。

Position

基になるストリーム内の現在位置を取得または設定します。

ReadTimeout

読み取り操作がブロックしてデータを待機する時間を取得または設定します。

RemoteIdentity

この認証されたストリームを共有するリモート側の ID に関する情報を取得します。

WriteTimeout

書き込み操作がブロックしてデータを待機する時間を取得または設定します。

メソッド

AuthenticateAsClient()

クライアントによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証します。

AuthenticateAsClient(NetworkCredential, ChannelBinding, String)

クライアントによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定したクライアントの資格情報およびチャネル バインディングが使用されます。

AuthenticateAsClient(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel)

クライアントによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定した資格情報、認証オプション、およびチャネル バインディングが使用されます。

AuthenticateAsClient(NetworkCredential, String)

クライアントによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定したクライアントの資格情報を使用します。

AuthenticateAsClient(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel)

クライアントによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定した資格情報と認証オプションを使用します。

AuthenticateAsClientAsync()

クライアントによって呼び出され、クライアントとサーバー間の接続で非同期操作としてクライアントと (オプションで) サーバーを認証します。

AuthenticateAsClientAsync(NetworkCredential, ChannelBinding, String)

クライアントによって呼び出され、クライアントとサーバー間の接続で非同期操作としてクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定したクライアントの資格情報およびチャネル バインディングが使用されます。

AuthenticateAsClientAsync(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel)

クライアントによって呼び出され、クライアントとサーバー間の接続で非同期操作としてクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定した資格情報、認証オプション、およびチャネル バインディングが使用されます。

AuthenticateAsClientAsync(NetworkCredential, String)

クライアントによって呼び出され、クライアントとサーバー間の接続で非同期操作としてクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定したクライアントの資格情報を使用します。

AuthenticateAsClientAsync(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel)

クライアントによって呼び出され、クライアントとサーバー間の接続で非同期操作としてクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定した資格情報と認証オプションを使用します。

AuthenticateAsServer()

サーバーによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証します。

AuthenticateAsServer(ExtendedProtectionPolicy)

サーバーによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定した拡張保護ポリシーが使用されます。

AuthenticateAsServer(NetworkCredential, ExtendedProtectionPolicy, ProtectionLevel, TokenImpersonationLevel)

サーバーによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定したサーバーの資格情報、認証オプション、および拡張保護ポリシーが使用されます。

AuthenticateAsServer(NetworkCredential, ProtectionLevel, TokenImpersonationLevel)

サーバーによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定したサーバーの資格情報と認証オプションを使用します。

AuthenticateAsServerAsync()

サーバーによって呼び出され、クライアントとサーバー間の接続で非同期操作としてクライアントと (オプションで) サーバーを認証します。

AuthenticateAsServerAsync(ExtendedProtectionPolicy)

サーバーによって呼び出され、クライアントとサーバー間の接続で非同期操作としてクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定した拡張保護ポリシーが使用されます。

AuthenticateAsServerAsync(NetworkCredential, ExtendedProtectionPolicy, ProtectionLevel, TokenImpersonationLevel)

サーバーによって呼び出され、クライアントとサーバー間の接続で非同期操作としてクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定したサーバーの資格情報、認証オプション、および拡張保護ポリシーが使用されます。

AuthenticateAsServerAsync(NetworkCredential, ProtectionLevel, TokenImpersonationLevel)

サーバーによって呼び出され、クライアントとサーバー間の接続で非同期操作としてクライアントと (オプションで) サーバーを認証します。 認証プロセスでは、指定したサーバーの資格情報と認証オプションを使用します。

BeginAuthenticateAsClient(AsyncCallback, Object)

クライアントによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証する非同期操作を開始します。 このメソッドはブロックしません。

BeginAuthenticateAsClient(NetworkCredential, ChannelBinding, String, AsyncCallback, Object)

クライアントによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証する非同期操作を開始します。 認証プロセスでは、指定した資格情報およびチャネル バインディングが使用されます。 このメソッドはブロックしません。

BeginAuthenticateAsClient(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

クライアントによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証する非同期操作を開始します。 認証プロセスでは、指定した資格情報、認証オプション、およびチャネル バインディングが使用されます。 このメソッドはブロックしません。

BeginAuthenticateAsClient(NetworkCredential, String, AsyncCallback, Object)

クライアントによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証する非同期操作を開始します。 認証プロセスでは、指定した資格情報を使用します。 このメソッドはブロックしません。

BeginAuthenticateAsClient(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

クライアントによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証する非同期操作を開始します。 認証プロセスでは、指定した資格情報と認証オプションを使用します。 このメソッドはブロックしません。

BeginAuthenticateAsServer(AsyncCallback, Object)

サーバーによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証する非同期操作を開始します。 このメソッドはブロックしません。

BeginAuthenticateAsServer(ExtendedProtectionPolicy, AsyncCallback, Object)

サーバーによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証する非同期操作を開始します。 認証プロセスでは、指定した拡張保護ポリシーが使用されます。 このメソッドはブロックしません。

BeginAuthenticateAsServer(NetworkCredential, ExtendedProtectionPolicy, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

サーバーによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証する非同期操作を開始します。 認証プロセスでは、指定したサーバーの資格情報、認証オプション、および拡張保護ポリシーが使用されます。 このメソッドはブロックしません。

BeginAuthenticateAsServer(NetworkCredential, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

サーバーによって呼び出され、クライアントとサーバー間の接続でクライアントと (オプションで) サーバーを認証する非同期操作を開始します。 認証プロセスでは、指定したサーバーの資格情報と認証オプションを使用します。 このメソッドはブロックしません。

BeginRead(Byte[], Int32, Int32, AsyncCallback, Object)

ストリームからデータを読み取り、指定した配列に格納する非同期読み取り操作を開始します。

BeginRead(Byte[], Int32, Int32, AsyncCallback, Object)

非同期の読み込み動作を開始します。 (代わりに、ReadAsync(Byte[], Int32, Int32) の使用を検討してください。)

(継承元 Stream)
BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object)

指定したバッファーからストリームに Byte を書き込む非同期書き込み操作を開始します。

BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object)

非同期の書き込み操作を開始します。 (代わりに、WriteAsync(Byte[], Int32, Int32) の使用を検討してください。)

(継承元 Stream)
Close()

現在のストリームを閉じ、現在のストリームに関連付けられているすべてのリソース (ソケット、ファイル ハンドルなど) を解放します。 このメソッドを呼び出す代わりに、ストリームが適切に破棄されていることを確認します。

(継承元 Stream)
CopyTo(Stream)

現在のストリームからバイトを読み取り、別のストリームに書き込みます。 どちらのストリーム位置も、コピーされたバイト数だけ進みます。

(継承元 Stream)
CopyTo(Stream, Int32)

指定されたバッファー サイズを使用して、現在のストリームからバイトを読み取り、別のストリームに書き込みます。 どちらのストリーム位置も、コピーされたバイト数だけ進みます。

(継承元 Stream)
CopyToAsync(Stream)

現在のストリームからすべてのバイトを非同期に読み取り、別のストリームに書き込みます。 どちらのストリーム位置も、コピーされたバイト数だけ進みます。

(継承元 Stream)
CopyToAsync(Stream, CancellationToken)

指定されたバッファー サイズを使用して、現在のストリームからバイトを非同期に読み取り、指定されたキャンセル トークンを使用して、別のストリームに書き込みます。 どちらのストリーム位置も、コピーされたバイト数だけ進みます。

(継承元 Stream)
CopyToAsync(Stream, Int32)

指定されたバッファー サイズを使用して、現在のストリームからバイトを非同期に読み取り、別のストリームに書き込みます。 どちらのストリーム位置も、コピーされたバイト数だけ進みます。

(継承元 Stream)
CopyToAsync(Stream, Int32, CancellationToken)

指定されたバッファー サイズを使用して、現在のストリームからバイトを非同期に読み取り、指定されたバッファー サイズとキャンセル トークンを使用して、別のストリームに書き込みます。 どちらのストリーム位置も、コピーされたバイト数だけ進みます。

(継承元 Stream)
CreateObjRef(Type)

リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。

(継承元 MarshalByRefObject)
CreateWaitHandle()
古い.
古い.
古い.

WaitHandle オブジェクトを割り当てます。

(継承元 Stream)
Dispose()

Stream によって使用されているすべてのリソースを解放します。

(継承元 Stream)
Dispose(Boolean)

NegotiateStream によって使用されているアンマネージド リソースを解放し、オプションでマネージド リソースも解放します。

Dispose(Boolean)

AuthenticatedStream によって使用されているアンマネージド リソースを解放し、オプションでマネージド リソースも解放します。

(継承元 AuthenticatedStream)
DisposeAsync()

NegotiateStream によって使用されているアンマネージドまたはマネージド リソースを非同期に解放します。

DisposeAsync()

AuthenticatedStream によって使用されているアンマネージドまたはマネージド リソースを非同期に解放します。

(継承元 AuthenticatedStream)
EndAuthenticateAsClient(IAsyncResult)

BeginAuthenticateAsClient の呼び出しで開始した保留中の非同期のクライアント認証操作を終了します。

EndAuthenticateAsServer(IAsyncResult)

BeginAuthenticateAsServer の呼び出しで開始した保留中の非同期のクライアント認証操作を終了します。

EndRead(IAsyncResult)

BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) の呼び出しで開始された、非同期の読み取り操作を終了します。

EndRead(IAsyncResult)

保留中の非同期読み取りが完了するまで待機します。 (代わりに、ReadAsync(Byte[], Int32, Int32) の使用を検討してください。)

(継承元 Stream)
EndWrite(IAsyncResult)

BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) の呼び出しで開始された、非同期の書き込み操作を終了します。

EndWrite(IAsyncResult)

非同期書き込み操作を終了します。 (代わりに、WriteAsync(Byte[], Int32, Int32) の使用を検討してください。)

(継承元 Stream)
Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
Flush()

バッファーに格納されたデータが基になるデバイスに書き込まれるようにします。

FlushAsync()

ストリームに対応するすべてのバッファーを非同期にクリアし、バッファー内のデータを基になるデバイスに書き込みます。

(継承元 Stream)
FlushAsync(CancellationToken)

バッファーされたデータを基になるデバイスに非同期的に書き込みます。

FlushAsync(CancellationToken)

ストリームに対応するすべてのバッファーを非同期にクリアし、バッファー内のデータを基になるデバイスに書き込み、キャンセル要求を監視します。

(継承元 Stream)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetLifetimeService()
古い.

対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
InitializeLifetimeService()
古い.

このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
MemberwiseClone(Boolean)

現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。

(継承元 MarshalByRefObject)
ObjectInvariant()
古い.

Contract のサポートを提供します。

(継承元 Stream)
Read(Byte[], Int32, Int32)

このストリームからデータを読み取り、指定した配列に格納します。

Read(Span<Byte>)

派生クラスによってオーバーライドされた場合は、現在のストリームからバイト シーケンスを読み取り、読み取ったバイト数の分だけストリームの位置を進めます。

(継承元 Stream)
ReadAsync(Byte[], Int32, Int32)

現在のストリームからバイト シーケンスを非同期に読み取り、読み取ったバイト数だけストリーム内の位置を進めます。

(継承元 Stream)
ReadAsync(Byte[], Int32, Int32, CancellationToken)

このストリームからデータを非同期に読み取り、指定された配列に格納します。

ReadAsync(Byte[], Int32, Int32, CancellationToken)

現在のストリームからバイト シーケンスを非同期に読み取り、読み取ったバイト数だけストリーム内の位置を進め、キャンセル要求を監視します。

(継承元 Stream)
ReadAsync(Memory<Byte>, CancellationToken)

NegotiateStream からデータを非同期に読み取り、非同期操作としてバイト メモリ範囲に格納します。

ReadAsync(Memory<Byte>, CancellationToken)

現在のストリームからバイト シーケンスを非同期に読み取り、読み取ったバイト数だけストリーム内の位置を進め、キャンセル要求を監視します。

(継承元 Stream)
ReadAtLeast(Span<Byte>, Int32, Boolean)

現在のストリームから少なくともバイト数を読み取り、ストリーム内の位置を読み取ったバイト数だけ進めます。

(継承元 Stream)
ReadAtLeastAsync(Memory<Byte>, Int32, Boolean, CancellationToken)

現在のストリームから少なくとも最小バイト数を非同期に読み取り、読み取ったバイト数だけストリーム内の位置を進め、キャンセル要求を監視します。

(継承元 Stream)
ReadByte()

ストリームから 1 バイトを読み取り、ストリーム内の位置を 1 バイト進めます。ストリームの末尾の場合は -1 を返します。

(継承元 Stream)
ReadExactly(Byte[], Int32, Int32)

現在のストリームからバイト数を読み取 count り、ストリーム内の位置を進めます。

(継承元 Stream)
ReadExactly(Span<Byte>)

現在のストリームからバイトを読み取り、 が塗りつぶされるまでストリーム内の位置を buffer 進めます。

(継承元 Stream)
ReadExactlyAsync(Byte[], Int32, Int32, CancellationToken)

現在のストリームからバイト数を非同期に読み取 count り、ストリーム内の位置を進め、取り消し要求を監視します。

(継承元 Stream)
ReadExactlyAsync(Memory<Byte>, CancellationToken)

現在のストリームからバイトを非同期に読み取り、 が満たされるまでストリーム内の位置を buffer 進め、取り消し要求を監視します。

(継承元 Stream)
Seek(Int64, SeekOrigin)

NotSupportedException をスローします。

SetLength(Int64)

基になるストリームの長さを設定します。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)
Write(Byte[], Int32, Int32)

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

Write(ReadOnlySpan<Byte>)

派生クラスによってオーバーライドされた場合は、現在のストリームにバイト シーケンスを書き込み、書き込んだバイト数の分だけストリームの現在位置を進めます。

(継承元 Stream)
WriteAsync(Byte[], Int32, Int32)

現在のストリームにバイト シーケンスを非同期に書き込み、書き込んだバイト数だけストリーム内の現在位置を進めます。

(継承元 Stream)
WriteAsync(Byte[], Int32, Int32, CancellationToken)

指定された数の Byte を基になるストリームに非同期に書き込みます。

WriteAsync(Byte[], Int32, Int32, CancellationToken)

現在のストリームにバイト シーケンスを非同期に書き込み、書き込んだバイト数だけストリーム内の現在位置を進め、キャンセル要求を監視します。

(継承元 Stream)
WriteAsync(ReadOnlyMemory<Byte>, CancellationToken)

指定された数の Byte を基になるストリームに非同期に書き込みます。

WriteAsync(ReadOnlyMemory<Byte>, CancellationToken)

現在のストリームにバイト シーケンスを非同期に書き込み、書き込んだバイト数だけストリーム内の現在位置を進め、キャンセル要求を監視します。

(継承元 Stream)
WriteByte(Byte)

ストリームの現在位置にバイトを書き込み、ストリームの位置を 1 バイトだけ進めます。

(継承元 Stream)

拡張メソッド

ConfigureAwait(IAsyncDisposable, Boolean)

非同期の破棄可能から返されるタスク上での待機がどのように実行されるかを構成します。

適用対象

こちらもご覧ください