Socket.SendAsync Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Overload
| Nome | Descrizione |
|---|---|
| SendAsync(ReadOnlyMemory<Byte>, CancellationToken) |
Invia dati su un socket connesso. |
| SendAsync(IList<ArraySegment<Byte>>, SocketFlags) |
Invia dati su un socket connesso. |
| SendAsync(ArraySegment<Byte>, SocketFlags) |
Invia dati su un socket connesso. |
| SendAsync(ReadOnlyMemory<Byte>, SocketFlags, CancellationToken) |
Invia dati su un socket connesso. |
| SendAsync(IList<ArraySegment<Byte>>) |
Invia dati su un socket connesso. |
| SendAsync(ArraySegment<Byte>) |
Invia dati su un socket connesso. |
| SendAsync(SocketAsyncEventArgs) |
Invia i dati in modo asincrono a un oggetto connesso Socket . |
SendAsync(ReadOnlyMemory<Byte>, CancellationToken)
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
Invia dati su un socket connesso.
public System.Threading.Tasks.ValueTask<int> SendAsync(ReadOnlyMemory<byte> buffer, System.Threading.CancellationToken cancellationToken = default);
member this.SendAsync : ReadOnlyMemory<byte> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<int>
Public Function SendAsync (buffer As ReadOnlyMemory(Of Byte), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Integer)
Parametri
- buffer
- ReadOnlyMemory<Byte>
Buffer per i dati da inviare.
- cancellationToken
- CancellationToken
Token di annullamento che può essere usato per annullare l'operazione asincrona.
Restituisce
Attività asincrona che viene completata con il numero di byte inviati.
Eccezioni
Il token di annullamento è stato annullato. Questa eccezione viene archiviata nell'attività restituita.
Si applica a
SendAsync(IList<ArraySegment<Byte>>, SocketFlags)
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
Invia dati su un socket connesso.
public:
System::Threading::Tasks::Task<int> ^ SendAsync(System::Collections::Generic::IList<ArraySegment<System::Byte>> ^ buffers, System::Net::Sockets::SocketFlags socketFlags);
public System.Threading.Tasks.Task<int> SendAsync(System.Collections.Generic.IList<ArraySegment<byte>> buffers, System.Net.Sockets.SocketFlags socketFlags);
member this.SendAsync : System.Collections.Generic.IList<ArraySegment<byte>> * System.Net.Sockets.SocketFlags -> System.Threading.Tasks.Task<int>
Public Function SendAsync (buffers As IList(Of ArraySegment(Of Byte)), socketFlags As SocketFlags) As Task(Of Integer)
Parametri
- buffers
- IList<ArraySegment<Byte>>
Elenco di buffer da inviare ai dati.
- socketFlags
- SocketFlags
Combinazione bit per bit dei valori SocketFlags che verranno usati durante l'invio dei dati.
Restituisce
Attività asincrona che viene completata con il numero di byte inviati.
Eccezioni
buffers è null.
Si è verificato un errore durante il tentativo di accesso al socket.
L'oggetto Socket è stato chiuso.
Commenti
Questo metodo archivia nell'attività che restituisce tutte le eccezioni non di utilizzo che la controparte sincrona del metodo può generare. Se un'eccezione viene archiviata nell'attività restituita, tale eccezione verrà generata quando l'attività è attesa. Le eccezioni di utilizzo, ad esempio ArgumentException, vengono comunque generate in modo sincrono. Per le eccezioni archiviate, vedere le eccezioni generate da Send(IList<ArraySegment<Byte>>, SocketFlags).
Si applica a
SendAsync(ArraySegment<Byte>, SocketFlags)
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
Invia dati su un socket connesso.
public:
System::Threading::Tasks::Task<int> ^ SendAsync(ArraySegment<System::Byte> buffer, System::Net::Sockets::SocketFlags socketFlags);
public System.Threading.Tasks.Task<int> SendAsync(ArraySegment<byte> buffer, System.Net.Sockets.SocketFlags socketFlags);
member this.SendAsync : ArraySegment<byte> * System.Net.Sockets.SocketFlags -> System.Threading.Tasks.Task<int>
Public Function SendAsync (buffer As ArraySegment(Of Byte), socketFlags As SocketFlags) As Task(Of Integer)
Parametri
- buffer
- ArraySegment<Byte>
Buffer per i dati da inviare.
- socketFlags
- SocketFlags
Combinazione bit per bit dei valori SocketFlags che verranno usati durante l'invio dei dati.
Restituisce
Attività asincrona che viene completata con il numero di byte inviati.
Eccezioni
Si è verificato un errore durante il tentativo di accesso al socket.
L'oggetto Socket è stato chiuso.
Si applica a
SendAsync(ReadOnlyMemory<Byte>, SocketFlags, CancellationToken)
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
Invia dati su un socket connesso.
public System.Threading.Tasks.ValueTask<int> SendAsync(ReadOnlyMemory<byte> buffer, System.Net.Sockets.SocketFlags socketFlags, System.Threading.CancellationToken cancellationToken = default);
member this.SendAsync : ReadOnlyMemory<byte> * System.Net.Sockets.SocketFlags * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<int>
Public Function SendAsync (buffer As ReadOnlyMemory(Of Byte), socketFlags As SocketFlags, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Integer)
Parametri
- buffer
- ReadOnlyMemory<Byte>
Buffer per i dati da inviare.
- socketFlags
- SocketFlags
Combinazione bit per bit dei valori SocketFlags che verranno usati durante l'invio dei dati.
- cancellationToken
- CancellationToken
Token di annullamento che può essere usato per annullare l'operazione asincrona.
Restituisce
Attività asincrona che viene completata con il numero di byte inviati.
Eccezioni
Si è verificato un errore durante il tentativo di accesso al socket.
L'oggetto Socket è stato chiuso.
Il token di annullamento è stato annullato. Questa eccezione viene archiviata nell'attività restituita.
Si applica a
SendAsync(IList<ArraySegment<Byte>>)
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
Invia dati su un socket connesso.
public:
System::Threading::Tasks::Task<int> ^ SendAsync(System::Collections::Generic::IList<ArraySegment<System::Byte>> ^ buffers);
public System.Threading.Tasks.Task<int> SendAsync(System.Collections.Generic.IList<ArraySegment<byte>> buffers);
member this.SendAsync : System.Collections.Generic.IList<ArraySegment<byte>> -> System.Threading.Tasks.Task<int>
Public Function SendAsync (buffers As IList(Of ArraySegment(Of Byte))) As Task(Of Integer)
Parametri
- buffers
- IList<ArraySegment<Byte>>
Elenco di buffer da inviare ai dati.
Restituisce
Attività asincrona che viene completata con il numero di byte inviati.
Eccezioni
buffers è null.
Si è verificato un errore durante il tentativo di accesso al socket.
L'oggetto Socket è stato chiuso.
Commenti
Questo metodo archivia nell'attività che restituisce tutte le eccezioni non di utilizzo che la controparte sincrona del metodo può generare. Se un'eccezione viene archiviata nell'attività restituita, tale eccezione verrà generata quando l'attività è attesa. Le eccezioni di utilizzo, ad esempio ArgumentException, vengono comunque generate in modo sincrono. Per le eccezioni archiviate, vedere le eccezioni generate da Send(IList<ArraySegment<Byte>>).
Si applica a
SendAsync(ArraySegment<Byte>)
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
- Origine:
- Socket.Tasks.cs
Invia dati su un socket connesso.
public:
System::Threading::Tasks::Task<int> ^ SendAsync(ArraySegment<System::Byte> buffer);
public System.Threading.Tasks.Task<int> SendAsync(ArraySegment<byte> buffer);
member this.SendAsync : ArraySegment<byte> -> System.Threading.Tasks.Task<int>
Public Function SendAsync (buffer As ArraySegment(Of Byte)) As Task(Of Integer)
Parametri
- buffer
- ArraySegment<Byte>
Buffer per i dati da inviare.
Restituisce
Attività asincrona che viene completata con il numero di byte inviati.
Eccezioni
Si è verificato un errore durante il tentativo di accesso al socket.
L'oggetto Socket è stato chiuso.
Si applica a
SendAsync(SocketAsyncEventArgs)
- Origine:
- Socket.cs
- Origine:
- Socket.cs
- Origine:
- Socket.cs
- Origine:
- Socket.cs
- Origine:
- Socket.cs
Invia i dati in modo asincrono a un oggetto connesso Socket .
public:
bool SendAsync(System::Net::Sockets::SocketAsyncEventArgs ^ e);
public bool SendAsync(System.Net.Sockets.SocketAsyncEventArgs e);
member this.SendAsync : System.Net.Sockets.SocketAsyncEventArgs -> bool
Public Function SendAsync (e As SocketAsyncEventArgs) As Boolean
Parametri
Oggetto SocketAsyncEventArgs da utilizzare per questa operazione socket asincrona.
Restituisce
true se l'operazione di I/O è in sospeso. L'evento Completed sul e parametro verrà generato al termine dell'operazione.
false se l'operazione di I/O è stata completata in modo sincrono. In questo caso, l'evento Completed sul e parametro non verrà generato e l'oggetto e passato come parametro può essere esaminato immediatamente dopo il ritorno della chiamata al metodo per recuperare il risultato dell'operazione.
Eccezioni
Le Buffer proprietà o BufferList nel e parametro devono fare riferimento a buffer validi. Una o l'altra di queste proprietà possono essere impostate, ma non entrambe contemporaneamente.
Un'operazione socket era già in corso usando l'oggetto SocketAsyncEventArgs specificato nel e parametro .
L'oggetto Socket è stato chiuso.
L'oggetto Socket non è ancora connesso o non è stato ottenuto tramite un Accept()metodo , AcceptAsync(SocketAsyncEventArgs)o BeginAccept.
Commenti
Il SendAsync metodo viene usato per scrivere dati in uscita da uno o più buffer in un socket orientato alla connessione. Questo metodo può essere usato anche nei socket senza connessione che hanno specificato un host remoto in un'operazione di connessione.
Il SendAsync metodo avvia un'operazione di invio asincrona all'host remoto stabilito nel Acceptmetodo , AcceptAsyncBeginAccept, BeginConnect, Connect, o ConnectAsync .
Per chiamare correttamente questo metodo, sono necessari gli eventi e le proprietà seguenti sull'oggetto System.Net.Sockets.SocketAsyncEventArgs :
SocketAsyncEventArgs.Buffer oppure SocketAsyncEventArgs.BufferList
SocketAsyncEventArgs.Count se SocketAsyncEventArgs.Buffer è impostato
SocketAsyncEventArgs.Offset se SocketAsyncEventArgs.Buffer è impostato
Il chiamante può impostare la SocketAsyncEventArgs.UserToken proprietà su qualsiasi oggetto stato utente desiderato prima di chiamare il SendAsync metodo, in modo che le informazioni saranno recuperabili nel metodo di callback. Se il callback richiede più informazioni di un singolo oggetto, è possibile creare una classe di piccole dimensioni per contenere le altre informazioni sullo stato necessarie come membri.
Il SendAsync metodo genererà un'eccezione se non si chiama Acceptprima , AcceptAsyncBeginAcceptBeginConnect, Connect, o .ConnectAsync
La chiamata al SendAsync metodo consente di inviare dati all'interno di un thread di esecuzione separato.
Per i socket orientati ai messaggi, non superare le dimensioni massime del messaggio del provider di servizi Windows Sockets sottostante. Se i dati sono troppo lunghi per passare in modo atomico tramite il provider di servizi sottostante, non vengono trasmessi dati e il SendAsync metodo genera un SocketException oggetto con l'oggetto SocketAsyncEventArgs.SocketError impostato sul codice di errore WSAEMSGSIZE di Winsock nativo (10040).
Si noti che il completamento corretto del SendAsync metodo non indica che i dati sono stati recapitati correttamente.