Specifies the protocol type used by the Socket class.

Members

Unknown (0)
The protocol type is unknown.
IP (1)
Internet Protocol version 4 (IPv4).
ICMP (2)
Internet Control Message Protocol (ICMP).
IGMP (3)
Internet Group Management Protocol (IGMP).
TCP (4)
Transmission Control Protocol (TCP).
UDP (5)
User Datagram Protocol (UDP).
Ipx (6)
Internetwork Packet Exchange (IPX).
Spx (7)
Sequenced Packet Exchange (SPX).
SpxII (8)
Sequenced Packet Exchange version 2 (SPX II).
IPv6 (17)
Internet Protocol version 6 (IPv6).
Icmpv6 (18)
Internet Control Message Protocol version 6 (ICMPv6).
RawSockets (255)
Raw sockets.

Remarks

The SocketProtocolType enumeration defines the protocol type that the Socket class uses to establish a connection. This enumeration is used by the Socket constructor to specify the protocol for the new socket.

Example Usage

The following example demonstrates how to create a TCP client socket using the SocketProtocolType.Tcp value:


using System;
using System.Net;
using System.Net.Sockets;

public class SocketExample
{
    public static void Main(string[] args)
    {
        try
        {
            // Create a TCP socket
            Socket socket = new Socket(
                AddressFamily.InterNetwork,
                SocketType.Stream,
                SocketProtocolType.Tcp
            );

            Console.WriteLine("TCP socket created successfully.");

            // You can now proceed to connect, bind, send, and receive data.
            // For demonstration purposes, we'll just close it.
            socket.Close();
            Console.WriteLine("Socket closed.");
        }
        catch (SocketException e)
        {
            Console.WriteLine($"SocketException: {e.Message}");
        }
        catch (Exception e)
        {
            Console.WriteLine($"An unexpected error occurred: {e.Message}");
        }
    }
}
                    

See Also