NegotiateStream.Read(Byte[], Int32, Int32) Método

Definición

Lee los datos de esta secuencia y los almacena en la matriz especificada.

public:
 override int Read(cli::array <System::Byte> ^ buffer, int offset, int count);
public override int Read(byte[] buffer, int offset, int count);
override this.Read : byte[] * int * int -> int
Public Overrides Function Read (buffer As Byte(), offset As Integer, count As Integer) As Integer

Parámetros

buffer
Byte[]

Matriz Byte que recibe los bytes leídos de la secuencia.

offset
Int32

que Int32 contiene la ubicación de base cero en la buffer que se van a empezar a almacenar los datos leídos de esta secuencia.

count
Int32

que Int32 contiene el número máximo de bytes que se van a leer de la secuencia.

Devoluciones

Valor Int32 que especifica el número de bytes leídos de la secuencia subyacente. Cuando no hay más datos que leer, devuelve 0.

Excepciones

Error en la operación de lectura.

No se ha producido la autenticación.

Ya hay una Read(Byte[], Int32, Int32) operación en curso.

Ejemplos

En el ejemplo de código siguiente se muestra la lectura de un NegotiateStream.

public static void AuthenticateClient(TcpClient clientRequest)
{
    NetworkStream stream = clientRequest.GetStream();
    // Create the NegotiateStream.
    NegotiateStream authStream = new NegotiateStream(stream, false);
    // Perform the server side of the authentication.
    authStream.AuthenticateAsServer();
    // Display properties of the authenticated client.
    IIdentity id = authStream.RemoteIdentity;
    Console.WriteLine("{0} was authenticated using {1}.",
        id.Name,
        id.AuthenticationType
        );
    // Read a message from the client.
    byte [] buffer = new byte[2048];
    int charLength = authStream.Read(buffer, 0, buffer.Length);
    string messageData = new String(Encoding.UTF8.GetChars(buffer, 0, buffer.Length));

    Console.WriteLine("READ {0}", messageData);
    // Finished with the current client.
    authStream.Close();
    // Close the client connection.
    clientRequest.Close();
}

Comentarios

El método lee un máximo de count bytes de la secuencia actual y los almacena a partir de bufferoffset.

No puede llamar a este método hasta que se haya autenticado correctamente. Para autenticarse, llame a uno de los AuthenticateAsClientmétodos , AuthenticateAsClientAsync, BeginAuthenticateAsClient, AuthenticateAsServer, AuthenticateAsServerAsynco BeginAuthenticateAsServer .

Para realizar esta operación de forma asincrónica, use el ReadAsync método .

Se aplica a