Export (0) Print
Expand All

SocketType Enumeration

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

[Visual Basic]
<Serializable>
Public Enum SocketType
[C#]
[Serializable]
public enum SocketType
[C++]
[Serializable]
__value public enum SocketType
[JScript]
public
   Serializable
enum SocketType

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

Members

Member name Description
Dgram

Supported by the .NET Compact Framework.

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 (Udp) and the InterNetwork AddressFamily.
Raw

Supported by the .NET Compact Framework.

Supports access to the underlying transport protocol. Using the SocketType Raw, you can communicate using protocols such as, 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.
Rdm

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

Specifies an unknown Socket type.

Example

[Visual Basic, C#, C++] The following example uses the Stream enumerated member as a parameter to the Socket constructor.

[Visual Basic] 
'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 should not print.  Because this is not a listening Socket," + " no incoming connecton requests are expected. "))
   Else
      If s.Poll(- 1, SelectMode.SelectError) Then
         Console.WriteLine("This Socket has an error.")
      End If
   End If 

[C#] 
//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 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.");
 }


[C++] 
//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 = S"Unable to connect to host";
}
// Use the SelectWrite enumeration to obtain Socket status.
if (s->Poll(-1, SelectMode::SelectWrite)) {
    Console::WriteLine(S"This Socket is writable.");
} else if (s->Poll(-1, SelectMode::SelectRead)) {
    Console::WriteLine(S"This should not print.  Because this is not a listening Socket, "
        S" no incoming connecton requests are expected.");
} else if (s->Poll(-1, SelectMode::SelectError)) {
    Console::WriteLine(S"This Socket has an error.");
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Net.Sockets

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System (in System.dll)

See Also

System.Net.Sockets Namespace | AddressFamily | ProtocolType | Socket

Show:
© 2014 Microsoft