NegotiateStream.Write(Byte[], Int32, Int32) Yöntem

Tanım

Belirtilen arabellek ve uzaklığı kullanarak temel alınan akışa belirtilen sayıda Bytes yazın.

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)

Parametreler

buffer
Byte[]

Byte Akışa yazılan baytları sağlayan bir dizi.

offset
Int32

Int32 Akışa yazılacak baytları okumaya başlanacak sıfır tabanlı konumu buffer içeren.

count
Int32

Int32'den bufferokunacak bayt sayısını içeren bir.

Özel durumlar

buffer, null değeridir.

offset is less than 0.

-veya-

offset uzunluğundan bufferbüyük.

-veya-

offset artı sayı, uzunluğundan bufferbüyüktür.

Yazma işlemi başarısız oldu.

-veya-

Şifreleme kullanılıyor, ancak veriler şifrelenemiyor.

Devam eden bir yazma işlemi zaten var.

Bu nesne kapatıldı.

Kimlik doğrulaması gerçekleşmedi.

Örnekler

Aşağıdaki kod örneğinde bir NegotiateStreamöğesine yazma gösterilmektedir.

int 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.
   TcpClient^ 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 );
   
   // Request authentication for the client only (no mutual authentication).
   // Authenicate using the client's default credetials.
   // Permit the server to impersonate the client to access resources on the server only.
   // Request that data be transmitted using encryption and data signing.
   authStream->AuthenticateAsClient( dynamic_cast<NetworkCredential^>(CredentialCache::DefaultCredentials), 
          L"", 
          ProtectionLevel::EncryptAndSign, 
          TokenImpersonationLevel::Impersonation );
   
   DisplayAuthenticationProperties( authStream );
   DisplayStreamProperties( authStream );
   if ( authStream->CanWrite )
   {
      
      // Encode the test data into a byte array.
      array<Byte>^message = System::Text::Encoding::UTF8->GetBytes( L"Hello from the client." );
      authStream->Write( message, 0, message->Length );
      authStream->Flush();
      Console::WriteLine( L"Sent {0} bytes.", message->Length );
   }

   
   // Close the client connection.
   authStream->Close();
   Console::WriteLine( L"Client closed." );
}

    public static void Main(String[] args)
    {
        // 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 = new IPEndPoint(ipAddress,11000);
        // Create a TCP/IP socket.
       TcpClient 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);
        // Request authentication for the client only (no mutual authentication).
        // Authenicate using the client's default credetials.
        // Permit the server to impersonate the client to access resources on the server only.
        // Request that data be transmitted using encryption and data signing.
        authStream.AuthenticateAsClient(
             (NetworkCredential) CredentialCache.DefaultCredentials,
             "",
             ProtectionLevel.EncryptAndSign,
             TokenImpersonationLevel.Impersonation);
        DisplayAuthenticationProperties(authStream);
        DisplayStreamProperties(authStream);
        if (authStream.CanWrite)
        {
             // Encode the test data into a byte array.
            byte[] message = System.Text.Encoding.UTF8.GetBytes("Hello from the client.");
            authStream.Write(message, 0, message.Length);
            authStream.Flush();
            Console.WriteLine("Sent {0} bytes.", message.Length);
        }
        // Close the client connection.
        authStream.Close();
        Console.WriteLine("Client closed.");
}

Açıklamalar

Şifreleme, imzalama veya şifreleme ve imzalama etkinleştirildiyse, bu yöntem verileri arabellekten okur, şifreler, işaretler veya şifreler ve imzalar ve temel akışı kullanarak iletir. Veri şifreleme veya imzalama gibi hiçbir güvenlik hizmeti kullanımda değilse, bu yöntem temel alınan akışta çağrılır Write .

Yazma işlemi tamamlarken bu yöntem engeller. İşlem tamamlarken engellemeyi önlemek için yöntemini kullanın WriteAsync .

Kimlik doğrulaması başarılı olana kadar bu yöntemi çağıramazsınız. Kimlik doğrulaması yapmak için , , AuthenticateAsClientAsync, BeginAuthenticateAsClient, AuthenticateAsServerAsyncAuthenticateAsServerveya BeginAuthenticateAsServer yöntemlerinden birini AuthenticateAsClientçağırın.

sınıfı NegotiateStream birden çok eşzamanlı yazma işlemini desteklemez. Aynı akışta başka bir yazma işlemi zaten yürütülürken bir yazma işlemi başlatmayı denerseniz, bir NotSupportedException özel durum oluşturulur.

Şunlara uygulanır