System.Net.Sockets.Socket.Shutdown Method

Disables sends and receives on a System.Net.Sockets.Socket.


public void Shutdown (SocketShutdown how)


One of the System.Net.Sockets.SocketShutdown values that specifies the operation that will no longer be allowed.


Note: For additional information on causes of the SocketException, see the System.Net.Sockets.SocketException class.
ObjectDisposedExceptionThe current instance has been disposed.


When using a connection-oriented System.Net.Sockets.Socket, always call the Socket.Shutdown(SocketShutdown) method before closing the System.Net.Sockets.Socket. This ensures that all data is sent and received on the connected socket before it is closed.

Call the Socket.Close method to free all managed and unmanaged resources associated with the System.Net.Sockets.Socket. Do not attempt to reuse the System.Net.Sockets.Socket after closing.

The following table shows the System.Net.Sockets.SocketShutdown enumeration values that are valid for the how parameter.


Disable sending on this System.Net.Sockets.Socket.


Disable receiving on this System.Net.Sockets.Socket.


Disable both sending and receiving on this System.Net.Sockets.Socket.

Setting how to SocketShutdown.Send specifies that subsequent calls to Socket.Send(Byte[], int, SocketFlags) are not allowed. If you are using a connectionless System.Net.Sockets.Socket, specifying SocketShutdown.Send will have no effect.

Setting how to SocketShutdown.Receive specifies that subsequent calls to Socket.Receive(Byte[], int, SocketFlags) are not allowed. This has no effect on lower protocol layers. If you are using a connection-oriented protocol, the connection is terminated if either of the following conditions exist after a call to Socket.Shutdown(SocketShutdown) :

  • Data is in the incoming network buffer waiting to be received.

  • More data has arrived.

If you are using a connectionless protocol, datagrams are accepted and queued. However, if no buffer space is available for additional incoming datagrams, they will be discarded and no error will be returned to the sender. Using Socket.Shutdown(SocketShutdown) on a connectionless System.Net.Sockets.Socket is not recommended.

Setting how to SocketShutdown.Both disables both sends and receives as described above.


If you receive a System.Net.Sockets.SocketException when calling the Socket.Shutdown(SocketShutdown) method, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.


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


Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0,,