Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Socket Class
Socket Methods
 Shutdown Method
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Socket..::.Shutdown Method

Updated: November 2007

Disables sends and receives on a Socket.

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

Visual Basic (Declaration)
Public Sub Shutdown ( _
    how As SocketShutdown _
)
Visual Basic (Usage)
Dim instance As Socket
Dim how As SocketShutdown

instance.Shutdown(how)
C#
public void Shutdown(
    SocketShutdown how
)
Visual C++
public:
void Shutdown(
    SocketShutdown how
)
J#
public void Shutdown(
    SocketShutdown how
)
JScript
public function Shutdown(
    how : SocketShutdown
)

Parameters

how
Type: System.Net.Sockets..::.SocketShutdown

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

ExceptionCondition
SocketException

An error occurred when attempting to access the socket. See the Remarks section for more information.

ObjectDisposedException

The Socket has been closed.

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

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

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

Value

Description

Send

Disable sending on this Socket.

Receive

Disable receiving on this Socket.

Both

Disable both sending and receiving on this Socket.

Setting how to Send specifies that subsequent calls to Send are not allowed. If you are using a connectionless Socket, specifying Send will have no effect.

Setting how to Receive specifies that subsequent calls to Receive 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 Shutdown :

  • 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 Shutdown on a connectionless Socket is not recommended.

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

Note:

If you receive a SocketException when calling the Shutdown 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.

Note:

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing.

The following code example uses Shutdown to disable the Socket.

Visual Basic
    aSocket.Shutdown(SocketShutdown.Both)
    aSocket.Close()

End Sub 'SocketClose

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

Visual C++
aSocket->Shutdown( SocketShutdown::Both );
aSocket->Close();
if ( aSocket->Connected )
{
   Console::WriteLine( "Winsock error: {0}", Convert::ToString(
      System::Runtime::InteropServices::Marshal::GetLastWin32Error() ) );
}

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker