| Visual Basic (Declaration) | |
|---|---|
<DescriptionAttribute("Local IP EndPoint when the socket is connected")> <BrowsableAttribute(False)> Public ReadOnly Property LocalEndPoint As IPEndPoint | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As Tcp Dim value As IPEndPoint value = instance.LocalEndPoint | |
| C# | |
|---|---|
[DescriptionAttribute("Local IP EndPoint when the socket is connected")] [BrowsableAttribute(false)] public IPEndPoint LocalEndPoint {get;} | |
| Managed Extensions for C++ | |
|---|---|
[DescriptionAttribute("Local IP EndPoint when the socket is connected")] [BrowsableAttribute(false)] public: __property IPEndPoint* get_LocalEndPoint(); | |
| C++/CLI | |
|---|---|
[DescriptionAttribute("Local IP EndPoint when the socket is connected")] [BrowsableAttribute(false)] public: property IPEndPoint^ LocalEndPoint { IPEndPoint^ get(); } | |
Property Value
The local IPEndPoint that the Tcp object is using for communications.The following example demonstrates using the ConnectedChanged event to notify the user of the status of the connection.
| Visual Basic | Copy Code |
|---|---|
Private Sub Tcp1_ConnectedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tcp1.ConnectedChanged ' Get current state of connection If Tcp1.Connected Then Debug.WriteLine("Connection made") ' Display info about the local/remote endpoints Debug.WriteLine("Local endpoint: " + Tcp1.LocalEndPoint.ToString()) Debug.WriteLine("Remote endpoint: " + Tcp1.RemoteEndPoint.ToString()) Else Debug.WriteLine("Connection closed") End If End Sub | |
| C# | Copy Code |
|---|---|
private void tcp1_ConnectedChanged(object sender, System.EventArgs e) { // Get current state of connection if(tcp1.Connected) { Debug.WriteLine("Connection made"); // Display info about the local/remote endpoints Debug.WriteLine("Local endpoint: " + tcp1.LocalEndPoint.ToString()); Debug.WriteLine("Remote endpoint: " + tcp1.RemoteEndPoint.ToString()); } else Debug.WriteLine("Connection closed"); } | |
null is returned when the Tcp.Connected property is false. When the Tcp.Connected property is true this property returns the IPEndPoint instance representing the local address and port. If a local interface was specified using the Tcp.Connect or Tcp.BeginConnect to connect to the host, this property should reflect that interface. Otherwise this property will reflect the default interface.
To retrieve the local IP address, access Tcp.LocalEndPoint.Address. To retrieve the local port, access Tcp.LocalEndPoint.Port. As a shortcut, use the Tcp.LocalEndPoint.ToString method to return the IP address and port in address:port notation.
Target Platforms: Microsoft .NET Framework 2.0
Copy Code