SocketInformation Class
Summary
Represents information about a Socket that can be serialized and deserialized.
Fields
The public static members of this type are thread safe. Any other member is not guaranteed to be thread safe.
-
AddressFamily
Gets or sets the address family.
-
ProtocolType
Gets or sets the protocol type.
-
SocketType
Gets or sets the socket type.
-
Options
Gets or sets the socket options.
Properties
The public static members of this type are thread safe. Any other member is not guaranteed to be thread safe.
AddressFamily
Gets or sets the AddressFamily of the socket.
public AddressFamily AddressFamily { get; set; }
ProtocolType
Gets or sets the ProtocolType of the socket.
public ProtocolType ProtocolType { get; set; }
SocketType
Gets or sets the SocketType of the socket.
public SocketType SocketType { get; set; }
Options
Gets or sets a List<SocketOption> that contains the socket options.
public List<SocketOption> Options { get; set; }
Remarks
The SocketInformation class is used by the DuplicateAndClose method of the Socket class to return information about a socket.
Example
The following example shows how to duplicate a socket and retrieve its information.
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
public class Example
{
public static void Main()
{
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
socket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
socket.Listen(10);
SocketInformation socketInfo = socket.DuplicateAndClose(new IntPtr(0));
Console.WriteLine($"Address Family: {socketInfo.AddressFamily}");
Console.WriteLine($"Socket Type: {socketInfo.SocketType}");
Console.WriteLine($"Protocol Type: {socketInfo.ProtocolType}");
foreach (var option in socketInfo.Options)
{
Console.WriteLine($"Option: {option.Name}, Level: {option.Level}, Value: {option.Value}");
}
}
}
}