Export (0) Print
Expand All

SocketAddress Class

Stores serialized information from EndPoint derived classes.

System.Object
  System.Net.SocketAddress

Namespace:  System.Net
Assemblies:   System (in System.dll)
  System.Net.Primitives (in System.Net.Primitives.dll)

public class SocketAddress

The SocketAddress type exposes the following members.

  NameDescription
Public methodSocketAddress(AddressFamily)Creates a new instance of the SocketAddress class for the given address family.
Public methodSocketAddress(AddressFamily, Int32)Creates a new instance of the SocketAddress class using the specified address family and buffer size.
Top

  NameDescription
Public propertyFamilyGets the AddressFamily enumerated value of the current SocketAddress.
Public propertyItemGets or sets the specified index element in the underlying buffer.
Public propertySizeGets the underlying buffer size of the SocketAddress.
Top

  NameDescription
Public methodEqualsDetermines whether the specified Object is equal to the current SocketAddress instance. (Overrides Object.Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table. (Overrides Object.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns information about the socket address. (Overrides Object.ToString().)
Top

The first 2 bytes of the underlying buffer are reserved for the AddressFamily enumerated value. When the SocketAddress is used to store a serialized IPEndPoint, the third and fourth bytes are used to store port number information. The next bytes are used to store the IP address. You can access any information within this underlying byte buffer by referring to its index position; the byte buffer uses zero-based indexing. You can also use the Family and Size properties to get the AddressFamily value and the buffer size, respectively. To view any of this information as a string, use the ToString method.

The following example demonstrates how to use SocketAddress to serialize an instance of the EndPoint class. After serialization, the underlying byte buffer of the SocketAddress contains all of the IPEndPoint state information.


//Creates an IpEndPoint.
IPAddress ipAddress = Dns.Resolve("www.contoso.com").AddressList[0];
IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 11000);

//Serializes the IPEndPoint. 
SocketAddress socketAddress = ipLocalEndPoint.Serialize();

//Verifies that ipLocalEndPoint is now serialized by printing its contents.
Console.WriteLine("Contents of the socketAddress are: " + socketAddress.ToString());
//Checks the Family property.
Console.WriteLine("The address family of the socketAddress is: " + socketAddress.Family.ToString());
//Checks the underlying buffer size.
Console.WriteLine("The size of the underlying buffer is: " + socketAddress.Size.ToString());

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft