From 6d250c4050ceb0bda33aad6a484fd05e508c4e27 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 4 Nov 2016 04:31:05 -0400 Subject: make dlna project portable --- MediaBrowser.Model/Net/ISocketFactory.cs | 26 ++++++++++++++++++++++++++ MediaBrowser.Model/Net/IUdpSocket.cs | 27 +++++++++++++++++++++++++++ MediaBrowser.Model/Net/IpEndPointInfo.cs | 18 ++++++++++++++++++ MediaBrowser.Model/Net/ReceivedUdpData.cs | 24 ++++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 MediaBrowser.Model/Net/ISocketFactory.cs create mode 100644 MediaBrowser.Model/Net/IUdpSocket.cs create mode 100644 MediaBrowser.Model/Net/IpEndPointInfo.cs create mode 100644 MediaBrowser.Model/Net/ReceivedUdpData.cs (limited to 'MediaBrowser.Model/Net') diff --git a/MediaBrowser.Model/Net/ISocketFactory.cs b/MediaBrowser.Model/Net/ISocketFactory.cs new file mode 100644 index 000000000..c0e0440c2 --- /dev/null +++ b/MediaBrowser.Model/Net/ISocketFactory.cs @@ -0,0 +1,26 @@ + +namespace MediaBrowser.Model.Net +{ + /// + /// Implemented by components that can create a platform specific UDP socket implementation, and wrap it in the cross platform interface. + /// + public interface ISocketFactory + { + + /// + /// Createa a new unicast socket using the specified local port number. + /// + /// The local port to bind to. + /// A implementation. + IUdpSocket CreateUdpSocket(int localPort); + + /// + /// Createa a new multicast socket using the specified multicast IP address, multicast time to live and local port. + /// + /// The multicast IP address to bind to. + /// The multicast time to live value. Actually a maximum number of network hops for UDP packets. + /// The local port to bind to. + /// A implementation. + IUdpSocket CreateUdpMulticastSocket(string ipAddress, int multicastTimeToLive, int localPort); + } +} diff --git a/MediaBrowser.Model/Net/IUdpSocket.cs b/MediaBrowser.Model/Net/IUdpSocket.cs new file mode 100644 index 000000000..cbeb8a995 --- /dev/null +++ b/MediaBrowser.Model/Net/IUdpSocket.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MediaBrowser.Model.Net +{ + /// + /// Provides a common interface across platforms for UDP sockets used by this SSDP implementation. + /// + public interface IUdpSocket : IDisposable + { + /// + /// Waits for and returns the next UDP message sent to this socket (uni or multicast). + /// + /// + Task ReceiveAsync(); + + /// + /// Sends a UDP message to a particular end point (uni or multicast). + /// + /// The data to send. + /// The providing the address and port to send to. + Task SendTo(byte[] messageData, IpEndPointInfo endPoint); + } +} \ No newline at end of file diff --git a/MediaBrowser.Model/Net/IpEndPointInfo.cs b/MediaBrowser.Model/Net/IpEndPointInfo.cs new file mode 100644 index 000000000..5fd331a16 --- /dev/null +++ b/MediaBrowser.Model/Net/IpEndPointInfo.cs @@ -0,0 +1,18 @@ +using System; + +namespace MediaBrowser.Model.Net +{ + public class IpEndPointInfo + { + public IpAddressInfo IpAddress { get; set; } + + public int Port { get; set; } + + public override string ToString() + { + var ipAddresString = IpAddress == null ? string.Empty : IpAddress.ToString(); + + return ipAddresString + ":" + this.Port.ToString(); + } + } +} diff --git a/MediaBrowser.Model/Net/ReceivedUdpData.cs b/MediaBrowser.Model/Net/ReceivedUdpData.cs new file mode 100644 index 000000000..1fdb22c93 --- /dev/null +++ b/MediaBrowser.Model/Net/ReceivedUdpData.cs @@ -0,0 +1,24 @@ + +namespace MediaBrowser.Model.Net +{ + /// + /// Used by the sockets wrapper to hold raw data received from a UDP socket. + /// + public sealed class ReceivedUdpData + { + /// + /// The buffer to place received data into. + /// + public byte[] Buffer { get; set; } + + /// + /// The number of bytes received. + /// + public int ReceivedBytes { get; set; } + + /// + /// The the data was received from. + /// + public IpEndPointInfo ReceivedFrom { get; set; } + } +} -- cgit v1.2.3