下面的示例检索并显示本地和远程终结点。[Visual Basic] 
s.Connect(lep)' Using the RemoteEndPoint property.
Console.WriteLine("I am connected to ")
Console.WriteLine(IPAddress.Parse(CType(s.RemoteEndPoint, IPEndPoint).Address.ToString()))
Console.WriteLine("on port number ")
Console.WriteLine(CType(s.RemoteEndPoint, IPEndPoint).Port.ToString())' Using the LocalEndPoint property.
Console.WriteLine("My local IpAddress is :")
Console.WriteLine(IPAddress.Parse(CType(s.LocalEndPoint, IPEndPoint).Address.ToString()))
Console.WriteLine("I am connected on port number ")
Console.WriteLine(CType(s.LocalEndPoint, IPEndPoint).Port.ToString())
[C#] 
s.Connect(lep);  // Using the RemoteEndPoint property.
  Console.WriteLine("I am connected to " + IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString()) +
                               "on port number " + ((IPEndPoint)s.RemoteEndPoint).Port.ToString()); // Using the LocalEndPoint property.
  Console.WriteLine("My local IpAddress is :" +  IPAddress.Parse(((IPEndPoint)s.LocalEndPoint).Address.ToString()) +
                                 "I am connected on port number " + 
                                 ((IPEndPoint)s.LocalEndPoint).Port.ToString());
[C++, JScript] 没有可用于 C++ 或 JScript 的示例。若要查看 Visual Basic 或 C# 示例,请单击页左上角的语言筛选器按钮 。框架中利用Socket来取LocalEndPoint,及RemoteEndPoint的IP的实例