SocketType SocketType SocketType SocketType Enum

Definition

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

public enum class SocketType
public enum SocketType
type SocketType = 
Public Enum SocketType
Inheritance

Fields

Dgram Dgram Dgram Dgram 2

Supports 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 (ProtocolType.Udp) and the AddressFamily.InterNetwork address family.

Raw Raw Raw Raw 3

Supports access to the underlying transport protocol. Using Raw, you can communicate using protocols like Internet Control Message Protocol (ProtocolType.Icmp) and Internet Group Management Protocol (ProtocolType.Igmp). Your application must provide a complete IP header when sending. Received datagrams return with the IP header and options intact.

Rdm Rdm Rdm Rdm 4

Supports 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.

Seqpacket Seqpacket Seqpacket Seqpacket 5

Provides 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.

Stream Stream Stream Stream 1

Supports 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 (ProtocolType.Tcp) and the AddressFamily.InterNetwork address family.

Unknown Unknown Unknown Unknown -1

Specifies an unknown Socket type.

Examples

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

//Creates the Socket for sending data over TCP.
Socket^ s = gcnew Socket( AddressFamily::InterNetwork, SocketType::Stream,
   ProtocolType::Tcp );

// Connects to host using IPEndPoint.
s->Connect( EPhost );
if ( !s->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 Socket is readable." );
}
else if ( s->Poll(  -1, SelectMode::SelectError ) )
{
   Console::WriteLine( "This Socket has an error." );
}
//Creates the Socket for sending data over TCP.
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
   ProtocolType.Tcp );

// Connects to host using IPEndPoint.
s.Connect(EPhost);
if (!s.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 Socket is readable." );
 }
 else if (s.Poll(-1, SelectMode.SelectError)){
      Console.WriteLine("This Socket has an error.");
 }

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

' Connects to host using IPEndPoint.
s.Connect(EPhost)
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.")
Else
   If s.Poll(- 1, SelectMode.SelectRead) Then
      Console.WriteLine(("This Socket is readable. "))
   Else
      If s.Poll(- 1, SelectMode.SelectError) Then
         Console.WriteLine("This Socket has an error.")
      End If
   End If 
End If 

Remarks

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.

Note

SocketType sometimes implicitly indicates which ProtocolType is used within an AddressFamily. For example, when the System.Net.Sockets.SocketType is SocketType.Dgram, the System.Net.Sockets.ProtocolType is always ProtocolType.Udp. When the System.Net.Sockets.SocketType is SocketType.Stream, the System.Net.Sockets.ProtocolType is always ProtocolType.Tcp. If you try to create a Socket with an incompatible combination, Socket throws a SocketException.

Applies to

See Also