Socket.ReceiveFromAsync(SocketAsyncEventArgs) Método
Definição
Começa a receber dados de um dispositivo de rede especificado de maneira assíncrona.Begins to asynchronously receive data from a specified network device.
public:
bool ReceiveFromAsync(System::Net::Sockets::SocketAsyncEventArgs ^ e);
public bool ReceiveFromAsync (System.Net.Sockets.SocketAsyncEventArgs e);
member this.ReceiveFromAsync : System.Net.Sockets.SocketAsyncEventArgs -> bool
Public Function ReceiveFromAsync (e As SocketAsyncEventArgs) As Boolean
Parâmetros
O objeto SocketAsyncEventArgs a ser usado nessa operação de soquete assíncrono.The SocketAsyncEventArgs object to use for this asynchronous socket operation.
Retornos
true se a operação de E/S está pendente.true if the I/O operation is pending. O evento Completed no parâmetro e será acionado após a conclusão da operação.The Completed event on the e parameter will be raised upon completion of the operation.
false se a operação de E/S foi concluída de forma síncrona.false if the I/O operation completed synchronously. Nesse caso, o evento Completed no parâmetro e não será gerado e o objeto e passado como um parâmetro poderá ser examinado imediatamente depois que a chamada do método for retornada para recuperar o resultado da operação.In this case, The Completed event on the e parameter will not be raised and the e object passed as a parameter may be examined immediately after the method call returns to retrieve the result of the operation.
Exceções
O RemoteEndPoint não pode ser nulo.The RemoteEndPoint cannot be null.
Uma operação de soquete já estava em andamento com o objeto SocketAsyncEventArgs especificado no parâmetro e.A socket operation was already in progress using the SocketAsyncEventArgs object specified in the e parameter.
É necessário o Windows XP ou posterior para esse método.Windows XP or later is required for this method.
Ocorreu um erro ao tentar acessar o soquete.An error occurred when attempting to access the socket.
Comentários
O ReceiveFromAsync método é usado principalmente para receber dados em um soquete sem conexão.The ReceiveFromAsync method is used primarily to receive data on a connectionless socket. O endereço local do soquete deve ser conhecido.The socket's local address must be known.
O chamador deve definir a SocketAsyncEventArgs.RemoteEndPoint propriedade para o IPEndPoint do host remoto do qual os dados serão recebidos.The caller must set the SocketAsyncEventArgs.RemoteEndPoint property to the IPEndPoint of the remote host from which the data is to be received.
A SocketAsyncEventArgs.SocketFlags propriedade no e parâmetro fornece o provedor de serviços do Window Sockets com informações adicionais sobre a solicitação de leitura.The SocketAsyncEventArgs.SocketFlags property on the e parameter provides the Window Sockets service provider with additional information about the read request. Para obter mais informações sobre como usar esse parâmetro, consulte System.Net.Sockets.SocketFlags .For more information about how to use this parameter, see System.Net.Sockets.SocketFlags.
As seguintes propriedades e eventos no System.Net.Sockets.SocketAsyncEventArgs objeto são necessários para chamar esse método com êxito:The following properties and events on the System.Net.Sockets.SocketAsyncEventArgs object are required to successfully call this method:
O chamador pode definir a SocketAsyncEventArgs.UserToken propriedade para qualquer objeto de estado de usuário desejado antes de chamar o ReceiveFromAsync método, de modo que as informações serão recuperáveis no método de retorno de chamada.The caller may set the SocketAsyncEventArgs.UserToken property to any user state object desired before calling the ReceiveFromAsync method, so that the information will be retrievable in the callback method. Se o retorno de chamada precisar de mais informações do que um único objeto, uma classe pequena poderá ser criada para manter as outras informações de estado necessárias como membros.If the callback needs more information than a single object, a small class can be created to hold the other required state information as members.
Para soquetes orientados a mensagens, uma mensagem de entrada é colocada no buffer até o tamanho total do buffer.For message-oriented sockets, an incoming message is placed into the buffer up to the total size of the buffer. As SocketAsyncEventArgs.Count SocketAsyncEventArgs.Offset Propriedades e determinam onde os dados são colocados no buffer e a quantidade de dados.The SocketAsyncEventArgs.Count and SocketAsyncEventArgs.Offset properties determine where in the buffer the data is placed and the amount of data.
Para soquetes de estilo de fluxo de bytes, os dados de entrada são colocados no buffer até que o buffer seja preenchido, a conexão é fechada ou os dados armazenados em buffer internamente são esgotados.For byte stream-style sockets, incoming data is placed into the buffer until the buffer is filled, the connection is closed, or the internally buffered data is exhausted. As SocketAsyncEventArgs.Count SocketAsyncEventArgs.Offset Propriedades e determinam onde os dados são colocados no buffer e a quantidade de dados.The SocketAsyncEventArgs.Count and SocketAsyncEventArgs.Offset properties determine where in the buffer the data is placed and the amount of data.