This documentation is archived and is not being maintained.

SocketType Enumeration

Specifies the type of socket that an instance of the Socket class represents.

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

Public Enumeration SocketType
Dim instance As SocketType

public enum SocketType
public enum SocketType

 Member nameDescription
Supported by the .NET Compact FrameworkDgramSupports datagrams, which are connectionless, unreliable messages of a fixed (typically small) maximum length. Messages might be lost or duplicated and might arrive out of order. A Socket of type Dgram requires no connection prior to sending and receiving data, and can communicate with multiple peers. Dgram uses the Datagram Protocol (Udp) and the InterNetworkAddressFamily
Supported by the .NET Compact FrameworkRawSupports access to the underlying transport protocol. Using the SocketTypeRaw, you can communicate using protocols like Internet Control Message Protocol (Icmp) and Internet Group Management Protocol (Igmp). Your application must provide a complete IP header when sending. Received datagrams return with the IP header and options intact. 
Supported by the .NET Compact FrameworkRdmSupports connectionless, message-oriented, reliably delivered messages, and preserves message boundaries in data. Rdm (Reliably Delivered Messages) messages arrive unduplicated and in order. Furthermore, the sender is notified if messages are lost. If you initialize a Socket using Rdm, you do not require a remote host connection before sending and receiving data. With Rdm, you can communicate with multiple peers. 
Supported by the .NET Compact FrameworkSeqpacketProvides connection-oriented and reliable two-way transfer of ordered byte streams across a network. Seqpacket does not duplicate data, and it preserves boundaries within the data stream. A Socket of type Seqpacket communicates with a single peer and requires a remote host connection before communication can begin. 
Supported by the .NET Compact FrameworkStreamSupports reliable, two-way, connection-based byte streams without the duplication of data and without preservation of boundaries. A Socket of this type communicates with a single peer and requires a remote host connection before communication can begin. Stream uses the Transmission Control Protocol (Tcp) ProtocolType and the InterNetworkAddressFamily
Supported by the .NET Compact FrameworkUnknownSpecifies an unknown Socket type. 

Before a Socket can send and receive data, it must first be created using an AddressFamily, a SocketType, and a ProtocolType. The SocketType enumeration provides several options for defining the type of Socket that you intend to open.


SocketType will sometimes implicitly indicate which ProtocolType will be used within an AddressFamily. For example when the SocketType is Dgram, the ProtocolType is always Udp.When the SocketType is Stream, the ProtocolType is always Tcp. If you try to create a Socket with an incompatible combination, Socket will throw a SocketException.

The following example uses the Stream enumerated member as a parameter to the Socket constructor.

'Creates the Socket for sending data over TCP.
Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

' Connects to host using IPEndPoint.
If Not s.Connected Then
   strRetPage = "Unable to connect to host"
End If
' Use the SelectWrite enumeration to obtain Socket status.
If s.Poll(- 1, SelectMode.SelectWrite) Then
   Console.WriteLine("This Socket is writable.")
   If s.Poll(- 1, SelectMode.SelectRead) Then
      Console.WriteLine(("This Socket is readable. "))
      If s.Poll(- 1, SelectMode.SelectError) Then
         Console.WriteLine("This Socket has an error.")
      End If
   End If 

//Creates the Socket for sending data over TCP.
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, 
// Connects to host using IPEndPoint.
if (!(s.get_Connected())) {
    strRetPage = "Unable to connect to host";
// Use the SelectWrite enumeration to obtain Socket status.
if (s.Poll(-1, SelectMode.SelectWrite)) {
    Console.WriteLine("This Socket is writable.");
else {
    if (s.Poll(-1, SelectMode.SelectRead)) {
        Console.WriteLine("This should not print."
            + "Because this is not a listening Socket,"
            + " no incoming connecton requests are expected. ");
    else {
        if (s.Poll(-1, SelectMode.SelectError)) {
            Console.WriteLine("This Socket has an error.");

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

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0