Serialize endpoint information into a SocketAddress instance in CSharp

Description

The following code shows how to serialize endpoint information into a SocketAddress instance.

Example


using System;//from   ww  w . j  a v  a 2  s  .  c om
using System.Net;
using System.Net.Sockets;

public class Example
{
    public static void Main()
    {
        IPEndPoint hostIPEndPoint = new IPEndPoint(IPAddress.Parse("192.1.1.1"), 80);
        SocketAddress socketAddress = hostIPEndPoint.Serialize();

        Console.WriteLine("Endpoint.Serialize() : " + socketAddress.ToString());

        Console.WriteLine("Socket.Family : " + socketAddress.Family);
        Console.WriteLine("Socket.Size : " + socketAddress.Size);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Network »




IP
Web Client