NegotiateStream.Read(Byte[], Int32, Int32) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Lê dados deste fluxo e armazena-os no array especificado.
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
- offset
- Int32
A contendo Int32 a localização baseada em zero em buffer onde começar a armazenar os dados lidos deste fluxo.
Devoluções
Um Int32 valor que especifica o número de bytes lidos do fluxo subjacente. Quando não há mais dados para ler, retorna 0.
Exceções
A operação de leitura falhou.
A autenticação não ocorreu.
Já está em curso uma Read(Byte[], Int32, Int32) operação.
Exemplos
O seguinte exemplo de código demonstra a leitura a partir de um 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();
}
Observações
O método lê um máximo de count bytes do fluxo atual e armazena-os buffer a partir de .offset
Não pode chamar este método até ter autenticado com sucesso. Para autenticar, chame um dos AuthenticateAsClient, AuthenticateAsClientAsync, BeginAuthenticateAsClient, AuthenticateAsServer, AuthenticateAsServerAsync, ou BeginAuthenticateAsServer métodos.
Para realizar esta operação de forma assíncrona, use o ReadAsync método.