public class SocketAddress
Object
SocketAddress
System
Networking
Provides a socket address stored in a Byte array.
At a minimum, a socket address consists of a member of the AddressFamily enumeration stored in the first two bytes of the array.
DefaultMemberAttribute("Item")
System.Net Namespace
SocketAddress Constructors
SocketAddress(System.Net.Sockets.AddressFamily) Constructor
SocketAddress(System.Net.Sockets.AddressFamily, int) Constructor
SocketAddress Methods
SocketAddress.Equals Method
SocketAddress.GetHashCode Method
SocketAddress.ToString Method
SocketAddress Properties
SocketAddress.Family Property
SocketAddress.Item Property
SocketAddress.Size Property
public SocketAddress(AddressFamily family);
Constructs and initializes a new instance of the SocketAddress class.
- family
- One of the values of the AddressFamily enumeration.
This method is equivalent to System.Net.SocketAddress.SocketAddress(family, 32).
System.Net.SocketAddress Class, System.Net Namespace
public SocketAddress(AddressFamily family, int size);
Constructs and initializes a new instance of the SocketAddress class.
- family
- One of the values of the AddressFamily enumeration.
- size
- A Int32 containing the number of bytes to allocate for the Byte array storing the socket address.
Exception Type Condition ArgumentOutOfRangeException size is less than 2.
The minimum value for size is 2 bytes.
System.Net.SocketAddress Class, System.Net Namespace
public override bool Equals(object comparand);
Determines whether the current instance and the specified Object represent the same socket address.
- comparand
- The Object to compare to the current instance.
A Boolean wheretrue
indicates comparand is an instance of the SocketAddress class and contains the same data as the current instance; otherwisefalse
.
[Note: This method overrides System.Object.Equals(System.Object).]
System.Net.SocketAddress Class, System.Net Namespace
public override int GetHashCode();
Generates a hash code for the current instance.
A Int32 containing the hash code for the current instance.
The algorithm used to generate the hash code is unspecified.[Note: This method overrides System.Object.GetHashCode.
]
System.Net.SocketAddress Class, System.Net Namespace
public override string ToString();
Returns a String representation of the value of the current instance.
A String representation of the current instance.
The returned string contains the string representation of the address family, the length of the array holding the socket address, and the contents of the array from the third to the maximum element, output in the following format:System.Net.SocketAddress.Family:System.Net.SocketAddress.Size:{array[2], array[3], ..., element[
Size
- 1]}[Note: This method overrides System.Object.ToString.
]
The following example writes a socket address to the console.
using System; using System.Net; using System.Net.Sockets; public class SocketAddressToString{ public static void Main() { Console.WriteLine("This is a minimal SocketAddress."); SocketAddress socketAddress = new SocketAddress(AddressFamily.InterNetwork); Console.WriteLine("{0}", socketAddress.ToString()); } }The output is
This is a minimal SocketAddress.
InterNetwork:32:{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
System.Net.SocketAddress Class, System.Net Namespace
public AddressFamily Family { get; }
Gets the address family which specifies the addressing scheme used to resolve an address.
One of the values defined in the AddressFamily enumeration.
This property is read-only.This property is set by the SocketAddress constructors and is stored in the first two bytes of the socket address array.
System.Net.SocketAddress Class, System.Net Namespace
public byte this[int offset] { get; set; }
Gets or sets the element at the specified index of the Byte array storing the socket address.
- offset
- A Int32 containing the zero-based index of the element to get or set.
A Byte containing the element at the specified index.
Exception Type Condition IndexOutOfRangeException offset is < 0. -or-
offset >= System.Net.SocketAddress.Size.
System.Net.SocketAddress Class, System.Net Namespace
public int Size { get; }
Gets the length of the socket address.
A Int32 containing the length of the Byte array storing the socket address.
This property is read-only.This property is set by the SocketAddress constructors.
System.Net.SocketAddress Class, System.Net Namespace