System.Net.Sockets

SocketProtocolType Enum

System.Net.Sockets

Specifies the protocol type used by the Socket.

Summary

The SocketProtocolType enumeration defines various protocols that can be used with the Socket class. These protocols are typically used at the transport layer of the network stack.

Members

Members

  • Unknown = 0
  • IP = 1
  • ICMP = 1
  • IGMP = 2
  • GGP = 3
  • TCP = 6
  • UDP = 17
  • ND = 18
  • Raw = 255
  • Ipx = 1025
  • Spx = 1026
  • SpxII = 1027
  • IPv6 = 41
  • IPv6HopByHop = 0
  • IPv6Fragment = 44
  • IPv6RoutingHeader = 43
  • IPv6ExtenstionHeader = 60
  • IPv6Options = 60
  • IPv6ICMP = 58
  • IPv6UDP = 17
  • UDPSpan = 1028
  • UDPLite = 136
  • ST = 97
  • Max = 256

Remarks

When creating a Socket, you specify the protocol type using this enumeration. For example, to create a TCP socket, you would use SocketProtocolType.Tcp.

Example

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

// Create a TCP socket
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

// Create a UDP socket
Socket udpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

// Remember to close the sockets when done
// socket.Close();
// udpSocket.Close();

See Also