Questo articolo è stato tradotto automaticamente. Per visualizzare l'articolo in inglese, selezionare la casella di controllo Inglese. È possibile anche visualizzare il testo inglese in una finestra popup posizionando il puntatore del mouse sopra il testo.
Traduzione
Inglese

Metodo Socket.Close (Int32)

 

Chiude la connessione Socket e rilascia tutte le risorse associate con un timeout specificato in modo da consentire l'invio dei dati in coda.

Spazio dei nomi:   System.Net.Sockets
Assembly:  System (in System.dll)

public void Close(
	int timeout
)

Parametri

timeout
Type: System.Int32

Attende fino a timeout secondi per inviare eventuali dati rimanenti, quindi chiude il socket.

The M:System.Net.Sockets.Socket.Close method closes the remote host connection and releases all managed and unmanaged resources associated with the T:System.Net.Sockets.Socket. Upon closing, the P:System.Net.Sockets.Socket.Connected property is set to false.

For connection-oriented protocols, it is recommended that you call M:System.Net.Sockets.Socket.Shutdown(System.Net.Sockets.SocketShutdown) before calling M:System.Net.Sockets.Socket.Close. This ensures that all data is sent and received on the connected socket before it is closed.

If you need to call M:System.Net.Sockets.Socket.Close without first calling M:System.Net.Sockets.Socket.Shutdown(System.Net.Sockets.SocketShutdown), you can ensure that data queued for outgoing transmission will be sent by setting the F:System.Net.Sockets.SocketOptionName.DontLinger option to false and specifying a non-zero time-out interval. M:System.Net.Sockets.Socket.Close will then block until this data is sent or until the specified time-out expires. If you set F:System.Net.Sockets.SocketOptionName.DontLinger to false and specify a zero time-out interval, M:System.Net.Sockets.Socket.Close releases the connection and automatically discards outgoing queued data.

System_CAPS_noteNota

To set the F:System.Net.Sockets.SocketOptionName.DontLinger socket option to false, create a T:System.Net.Sockets.LingerOption, set the enabled property to true, and set the P:System.Net.Sockets.LingerOption.LingerTime property to the desired time-out period. Use this T:System.Net.Sockets.LingerOption along with the F:System.Net.Sockets.SocketOptionName.DontLinger socket option to call the M:System.Net.Sockets.Socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,System.Int32) method.

System_CAPS_noteNota

This member outputs trace information when you enable network tracing in your application. For more information, see [<topic://conUsingNetworkTracing>].

The following code example demonstrates how to close a T:System.Net.Sockets.Socket.

aSocket.Shutdown(SocketShutdown.Both);
aSocket.Close();

.NET Framework
Disponibile da 2.0
Silverlight
Disponibile da 2.0
Windows Phone Silverlight
Disponibile da 7.1
Torna all'inizio
Mostra: