Create an endpoint from a socket address in CSharp

Description

The following code shows how to create an endpoint from a socket address.

Example


using System;// w w w  . j av  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();


        IPEndPoint endpoint = new IPEndPoint(0,0);
        IPEndPoint clonedIPEndPoint = (IPEndPoint) endpoint.Create(socketAddress);
        Console.WriteLine("clonedIPEndPoint: " + clonedIPEndPoint.ToString());

   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Network »




IP
Web Client