Assembly: System (in system.dll)
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. Dim ipAddress As IPAddress = Dns.Resolve("www.contoso.com").AddressList(0) Dim ipLocalEndPoint As New IPEndPoint(ipAddress, 11000) 'Serializes the IPEndPoint. Dim socketAddress As SocketAddress = ipLocalEndPoint.Serialize() 'Verifies that ipLocalEndPoint is now serialized by printing its contents. Console.WriteLine(("Contents of socketAddress are: " + socketAddress.ToString())) 'Checks the Family property. Console.WriteLine(("The address family of socketAddress is: " + socketAddress.Family.ToString())) 'Checks the underlying buffer size. Console.WriteLine(("The size of the underlying buffer is: " + socketAddress.Size.ToString())) End Sub 'MySerializeIPEndPointClassMethod
//Creates an IpEndPoint. IPAddress ipAddress = (IPAddress)Dns.Resolve( "www.contoso.com").get_AddressList().get_Item(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.get_Family())); //Checks the underlying buffer size. Console.WriteLine(("The size of the underlying buffer is: " + socketAddress.get_Size()));
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.