Skip to content

Commit

Permalink
get connected interface for TcpSocketClient
Browse files Browse the repository at this point in the history
  • Loading branch information
rdavisau committed Jan 10, 2016
2 parents 23ad4e8 + 8f45239 commit 4f42b17
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sockets/Sockets.Implementation.NET/TcpSocketClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
Expand Down Expand Up @@ -139,6 +140,17 @@ public Task DisconnectAsync()
});
}

/// <summary>
/// Gets the interface the connection is using.
/// </summary>
/// <returns>The <see cref="ICommsInterface"/> which represents the interface the connection is using.</returns>
public async Task<ICommsInterface> GetConnectedInterfaceAsync()
{
var ipEndpoint = (IPEndPoint)_backingTcpClient.Client.LocalEndPoint;
var interfaces = await CommsInterface.GetAllInterfacesAsync();
return interfaces.FirstOrDefault(x => x.NativeIpAddress.Equals(ipEndpoint.Address));
}

/// <summary>
/// A stream that can be used for receiving data from the remote endpoint.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions Sockets/Sockets.Implementation.WinRT/TcpSocketClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Threading;
using System.Linq;
using System.Threading.Tasks;
using Windows.Networking;
using Windows.Networking.Sockets;
Expand Down Expand Up @@ -93,6 +94,14 @@ public Task DisconnectAsync()
});
}

/// </summary>
/// <returns>The <see cref="ICommsInterface"/> which represents the interface the connection is using.</returns>
public async Task<ICommsInterface> GetConnectedInterfaceAsync()
{
var interfaces = await CommsInterface.GetAllInterfacesAsync();
return interfaces.FirstOrDefault(x => x.NativeHostName.IsEqual(_backingStreamSocket.Information.LocalAddress));
}

/// <summary>
/// A stream that can be used for receiving data from the remote endpoint.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions Sockets/Sockets.Plugin.Abstractions/ITcpSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public interface ITcpSocketClient : IDisposable
/// </summary>
Task DisconnectAsync();

/// <summary>
/// Gets the interface the connection is using.
/// </summary>
/// <returns>The <see cref="ICommsInterface"/> which represents the interface the connection is using.</returns>
Task<ICommsInterface> GetConnectedInterfaceAsync();

/// <summary>
/// A stream that can be used for receiving data from the remote endpoint.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions Sockets/Sockets.Plugin/TcpSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public Task DisconnectAsync()
throw new NotImplementedException(PCL.BaitWithoutSwitchMessage);
}

/// <summary>
/// Gets the interface the connection is using.
/// </summary>
/// <returns>The <see cref="ICommsInterface"/> which represents the interface the connection is using.</returns>
public Task<ICommsInterface> GetConnectedInterfaceAsync()
{
throw new NotImplementedException(PCL.BaitWithoutSwitchMessage);
}

/// <summary>
/// A stream that can be used for receiving data from the remote endpoint.
/// </summary>
Expand Down

0 comments on commit 4f42b17

Please sign in to comment.