Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Socket.Close Method (Int32)

Closes the Socket connection and releases all associated resources with a specified timeout to allow queued data to be sent.

Namespace:  System.Net.Sockets
Assembly:  System.Net (in System.Net.dll)

public void Close(
	int timeout
)

Parameters

timeout
Type: System.Int32
The maximum amount of time, in seconds, to wait in order to send any remaining data, and then close the Socket.

ExceptionCondition
ArgumentOutOfRangeException

The timeout is less than 0.

The Close method closes the remote host connection and releases all managed and unmanaged resources associated with the Socket. Upon closing, the Connected property is set to false.

For connection-oriented protocols, it is recommended that you call Shutdown before calling the Close method. This ensures that all data is sent and received on the connected socket before it is closed.

If you need to call Close without first calling Shutdown, you can ensure that data queued for outgoing transmission will be sent by calling the Close method and specifying a non-zero timeout interval. The Close method will then block until this data is sent or until the specified timeout expires.

A Socket instance cannot be reused.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2015 Microsoft