From 2e4db7554041ecf481d3a38656fccc309e13eb5b Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Sat, 23 Feb 2013 17:31:51 -0500 Subject: extracted http server, web socket server and udp server dependancies --- MediaBrowser.Common/Net/AlchemyWebSocket.cs | 132 ------ MediaBrowser.Common/Net/HttpServer.cs | 489 --------------------- MediaBrowser.Common/Net/IHttpServer.cs | 44 ++ MediaBrowser.Common/Net/IUdpServer.cs | 43 +- MediaBrowser.Common/Net/IWebSocketServer.cs | 26 ++ .../Net/UdpMessageReceivedEventArgs.cs | 21 + MediaBrowser.Common/Net/UdpServer.cs | 142 ------ .../Net/WebSocketConnectEventArgs.cs | 22 + MediaBrowser.Common/Net/WebSocketConnection.cs | 6 +- 9 files changed, 157 insertions(+), 768 deletions(-) delete mode 100644 MediaBrowser.Common/Net/AlchemyWebSocket.cs delete mode 100644 MediaBrowser.Common/Net/HttpServer.cs create mode 100644 MediaBrowser.Common/Net/IHttpServer.cs create mode 100644 MediaBrowser.Common/Net/IWebSocketServer.cs create mode 100644 MediaBrowser.Common/Net/UdpMessageReceivedEventArgs.cs delete mode 100644 MediaBrowser.Common/Net/UdpServer.cs create mode 100644 MediaBrowser.Common/Net/WebSocketConnectEventArgs.cs (limited to 'MediaBrowser.Common/Net') diff --git a/MediaBrowser.Common/Net/AlchemyWebSocket.cs b/MediaBrowser.Common/Net/AlchemyWebSocket.cs deleted file mode 100644 index 584efa999..000000000 --- a/MediaBrowser.Common/Net/AlchemyWebSocket.cs +++ /dev/null @@ -1,132 +0,0 @@ -using Alchemy.Classes; -using MediaBrowser.Common.Serialization; -using MediaBrowser.Model.Logging; -using System; -using System.Net.WebSockets; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Net -{ - /// - /// Class AlchemyWebSocket - /// - public class AlchemyWebSocket : IWebSocket - { - /// - /// The logger - /// - private readonly ILogger _logger; - - /// - /// Gets or sets the web socket. - /// - /// The web socket. - private UserContext UserContext { get; set; } - - /// - /// Initializes a new instance of the class. - /// - /// The context. - /// The logger. - /// context - public AlchemyWebSocket(UserContext context, ILogger logger) - { - if (context == null) - { - throw new ArgumentNullException("context"); - } - - _logger = logger; - UserContext = context; - - context.SetOnDisconnect(OnDisconnected); - context.SetOnReceive(OnReceive); - - _logger.Info("Client connected from {0}", context.ClientAddress); - } - - /// - /// The _disconnected - /// - private bool _disconnected = false; - /// - /// Gets or sets the state. - /// - /// The state. - public WebSocketState State - { - get { return _disconnected ? WebSocketState.Closed : WebSocketState.Open; } - } - - /// - /// Called when [disconnected]. - /// - /// The context. - private void OnDisconnected(UserContext context) - { - _disconnected = true; - } - - /// - /// Called when [receive]. - /// - /// The context. - private void OnReceive(UserContext context) - { - if (OnReceiveDelegate != null) - { - var json = context.DataFrame.ToString(); - - if (!string.IsNullOrWhiteSpace(json)) - { - try - { - var messageResult = JsonSerializer.DeserializeFromString(json); - - OnReceiveDelegate(messageResult); - } - catch (Exception ex) - { - _logger.ErrorException("Error processing web socket message", ex); - } - } - } - } - - /// - /// Sends the async. - /// - /// The bytes. - /// The type. - /// if set to true [end of message]. - /// The cancellation token. - /// Task. - public Task SendAsync(byte[] bytes, WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken) - { - return Task.Run(() => UserContext.Send(bytes)); - } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - } - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool dispose) - { - } - - /// - /// Gets or sets the receive action. - /// - /// The receive action. - public Action OnReceiveDelegate { get; set; } - } -} diff --git a/MediaBrowser.Common/Net/HttpServer.cs b/MediaBrowser.Common/Net/HttpServer.cs deleted file mode 100644 index 20ee615ad..000000000 --- a/MediaBrowser.Common/Net/HttpServer.cs +++ /dev/null @@ -1,489 +0,0 @@ -using Funq; -using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.Kernel; -using MediaBrowser.Model.Logging; -using ServiceStack.Api.Swagger; -using ServiceStack.Common.Web; -using ServiceStack.Configuration; -using ServiceStack.Logging.NLogger; -using ServiceStack.ServiceHost; -using ServiceStack.ServiceInterface.Cors; -using ServiceStack.Text; -using ServiceStack.WebHost.Endpoints; -using ServiceStack.WebHost.Endpoints.Extensions; -using ServiceStack.WebHost.Endpoints.Support; -using System; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Net; -using System.Reactive.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Net -{ - /// - /// Class HttpServer - /// - public class HttpServer : HttpListenerBase - { - /// - /// The logger - /// - private readonly ILogger _logger; - - /// - /// Gets the URL prefix. - /// - /// The URL prefix. - public string UrlPrefix { get; private set; } - - /// - /// Gets or sets the kernel. - /// - /// The kernel. - private IKernel Kernel { get; set; } - - /// - /// Gets or sets the application host. - /// - /// The application host. - private IApplicationHost ApplicationHost { get; set; } - - /// - /// This subscribes to HttpListener requests and finds the appropriate BaseHandler to process it - /// - /// The HTTP listener. - private IDisposable HttpListener { get; set; } - - /// - /// Occurs when [web socket connected]. - /// - public event EventHandler WebSocketConnected; - - /// - /// Gets the default redirect path. - /// - /// The default redirect path. - public string DefaultRedirectPath { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - /// The URL. - /// Name of the product. - /// The application host. - /// The kernel. - /// The logger. - /// The default redirectpath. - /// urlPrefix - public HttpServer(string urlPrefix, string serverName, IApplicationHost applicationHost, IKernel kernel, ILogger logger, string defaultRedirectpath = null) - : base() - { - if (string.IsNullOrEmpty(urlPrefix)) - { - throw new ArgumentNullException("urlPrefix"); - } - if (kernel == null) - { - throw new ArgumentNullException("kernel"); - } - if (logger == null) - { - throw new ArgumentNullException("logger"); - } - if (applicationHost == null) - { - throw new ArgumentNullException("applicationHost"); - } - - DefaultRedirectPath = defaultRedirectpath; - _logger = logger; - ApplicationHost = applicationHost; - - EndpointHostConfig.Instance.ServiceStackHandlerFactoryPath = null; - EndpointHostConfig.Instance.MetadataRedirectPath = "metadata"; - - UrlPrefix = urlPrefix; - Kernel = kernel; - - EndpointHost.ConfigureHost(this, serverName, CreateServiceManager()); - - ContentTypeFilters.Register(ContentType.ProtoBuf, (reqCtx, res, stream) => Kernel.ProtobufSerializer.SerializeToStream(res, stream), (type, stream) => Kernel.ProtobufSerializer.DeserializeFromStream(stream, type)); - - Init(); - Start(urlPrefix); - } - - /// - /// Shut down the Web Service - /// - public override void Stop() - { - if (HttpListener != null) - { - HttpListener.Dispose(); - HttpListener = null; - } - - if (Listener != null) - { - Listener.Prefixes.Remove(UrlPrefix); - } - - base.Stop(); - } - - /// - /// Configures the specified container. - /// - /// The container. - public override void Configure(Container container) - { - if (!string.IsNullOrEmpty(DefaultRedirectPath)) - { - SetConfig(new EndpointHostConfig - { - DefaultRedirectPath = DefaultRedirectPath, - - // Tell SS to bubble exceptions up to here - WriteErrorsToResponse = false, - - DebugMode = true - }); - } - - container.Adapter = new ContainerAdapter(ApplicationHost); - - container.Register(Kernel); - container.Register(_logger); - container.Register(ApplicationHost); - - foreach (var service in Kernel.RestServices) - { - service.Configure(this); - } - - Plugins.Add(new SwaggerFeature()); - Plugins.Add(new CorsFeature()); - - Serialization.JsonSerializer.Configure(); - - ServiceStack.Logging.LogManager.LogFactory = new NLogFactory(); - } - - /// - /// Starts the Web Service - /// - /// A Uri that acts as the base that the server is listening on. - /// Format should be: http://127.0.0.1:8080/ or http://127.0.0.1:8080/somevirtual/ - /// Note: the trailing slash is required! For more info see the - /// HttpListener.Prefixes property on MSDN. - public override void Start(string urlBase) - { - // *** Already running - just leave it in place - if (IsStarted) - { - return; - } - - if (Listener == null) - { - Listener = new HttpListener(); - } - - EndpointHost.Config.ServiceStackHandlerFactoryPath = HttpListenerRequestWrapper.GetHandlerPathIfAny(urlBase); - - Listener.Prefixes.Add(urlBase); - - IsStarted = true; - Listener.Start(); - - HttpListener = CreateObservableStream().Subscribe(ProcessHttpRequestAsync); - } - - /// - /// Creates the observable stream. - /// - /// IObservable{HttpListenerContext}. - private IObservable CreateObservableStream() - { - return Observable.Create(obs => - Observable.FromAsync(() => Listener.GetContextAsync()) - .Subscribe(obs)) - .Repeat() - .Retry() - .Publish() - .RefCount(); - } - - /// - /// Processes incoming http requests by routing them to the appropiate handler - /// - /// The CTX. - private async void ProcessHttpRequestAsync(HttpListenerContext context) - { - LogHttpRequest(context); - - if (context.Request.IsWebSocketRequest) - { - await ProcessWebSocketRequest(context).ConfigureAwait(false); - return; - } - - - Task.Run(() => - { - RaiseReceiveWebRequest(context); - - try - { - ProcessRequest(context); - } - catch (InvalidOperationException ex) - { - HandleException(context.Response, ex, 422); - - throw; - } - catch (ResourceNotFoundException ex) - { - HandleException(context.Response, ex, 404); - - throw; - } - catch (FileNotFoundException ex) - { - HandleException(context.Response, ex, 404); - - throw; - } - catch (DirectoryNotFoundException ex) - { - HandleException(context.Response, ex, 404); - - throw; - } - catch (UnauthorizedAccessException ex) - { - HandleException(context.Response, ex, 401); - - throw; - } - catch (ArgumentException ex) - { - HandleException(context.Response, ex, 400); - - throw; - } - catch (Exception ex) - { - HandleException(context.Response, ex, 500); - - throw; - } - }); - } - - /// - /// Processes the web socket request. - /// - /// The CTX. - /// Task. - private async Task ProcessWebSocketRequest(HttpListenerContext ctx) - { - try - { - var webSocketContext = await ctx.AcceptWebSocketAsync(null).ConfigureAwait(false); - - if (WebSocketConnected != null) - { - WebSocketConnected(this, new WebSocketConnectEventArgs { WebSocket = new NativeWebSocket(webSocketContext.WebSocket, _logger), Endpoint = ctx.Request.RemoteEndPoint }); - } - } - catch (Exception ex) - { - _logger.ErrorException("AcceptWebSocketAsync error", ex); - - ctx.Response.StatusCode = 500; - ctx.Response.Close(); - } - } - - /// - /// Logs the HTTP request. - /// - /// The CTX. - private void LogHttpRequest(HttpListenerContext ctx) - { - var log = new StringBuilder(); - - log.AppendLine("Url: " + ctx.Request.Url); - log.AppendLine("Headers: " + string.Join(",", ctx.Request.Headers.AllKeys.Select(k => k + "=" + ctx.Request.Headers[k]))); - - var type = ctx.Request.IsWebSocketRequest ? "Web Socket" : "HTTP " + ctx.Request.HttpMethod; - - if (Kernel.Configuration.EnableHttpLevelLogging) - { - _logger.LogMultiline(type + " request received from " + ctx.Request.RemoteEndPoint, LogSeverity.Debug, log); - } - } - - /// - /// Appends the error message. - /// - /// The response. - /// The ex. - /// The status code. - private void HandleException(HttpListenerResponse response, Exception ex, int statusCode) - { - _logger.ErrorException("Error processing request", ex); - - response.StatusCode = statusCode; - - response.Headers.Add("Status", statusCode.ToString(new CultureInfo("en-US"))); - - response.Headers.Remove("Age"); - response.Headers.Remove("Expires"); - response.Headers.Remove("Cache-Control"); - response.Headers.Remove("Etag"); - response.Headers.Remove("Last-Modified"); - - response.ContentType = "text/plain"; - - if (!string.IsNullOrEmpty(ex.Message)) - { - response.AddHeader("X-Application-Error-Code", ex.Message); - } - - // This could fail, but try to add the stack trace as the body content - try - { - var sb = new StringBuilder(); - sb.AppendLine("{"); - sb.AppendLine("\"ResponseStatus\":{"); - sb.AppendFormat(" \"ErrorCode\":{0},\n", ex.GetType().Name.EncodeJson()); - sb.AppendFormat(" \"Message\":{0},\n", ex.Message.EncodeJson()); - sb.AppendFormat(" \"StackTrace\":{0}\n", ex.StackTrace.EncodeJson()); - sb.AppendLine("}"); - sb.AppendLine("}"); - - response.StatusCode = 500; - response.ContentType = ContentType.Json; - var sbBytes = sb.ToString().ToUtf8Bytes(); - response.OutputStream.Write(sbBytes, 0, sbBytes.Length); - response.Close(); - } - catch (Exception errorEx) - { - _logger.ErrorException("Error processing failed request", errorEx); - } - } - - - /// - /// Overridable method that can be used to implement a custom hnandler - /// - /// The context. - /// Cannot execute handler: + handler + at PathInfo: + httpReq.PathInfo - protected override void ProcessRequest(HttpListenerContext context) - { - if (string.IsNullOrEmpty(context.Request.RawUrl)) return; - - var operationName = context.Request.GetOperationName(); - - var httpReq = new HttpListenerRequestWrapper(operationName, context.Request); - var httpRes = new HttpListenerResponseWrapper(context.Response); - var handler = ServiceStackHttpHandlerFactory.GetHandler(httpReq); - - var serviceStackHandler = handler as IServiceStackHttpHandler; - - if (serviceStackHandler != null) - { - var restHandler = serviceStackHandler as RestHandler; - if (restHandler != null) - { - httpReq.OperationName = operationName = restHandler.RestPath.RequestType.Name; - } - serviceStackHandler.ProcessRequest(httpReq, httpRes, operationName); - LogResponse(context); - httpRes.Close(); - return; - } - - throw new NotImplementedException("Cannot execute handler: " + handler + " at PathInfo: " + httpReq.PathInfo); - } - - /// - /// Logs the response. - /// - /// The CTX. - private void LogResponse(HttpListenerContext ctx) - { - var statusode = ctx.Response.StatusCode; - - var log = new StringBuilder(); - - log.AppendLine(string.Format("Url: {0}", ctx.Request.Url)); - - log.AppendLine("Headers: " + string.Join(",", ctx.Response.Headers.AllKeys.Select(k => k + "=" + ctx.Response.Headers[k]))); - - var msg = "Http Response Sent (" + statusode + ") to " + ctx.Request.RemoteEndPoint; - - if (Kernel.Configuration.EnableHttpLevelLogging) - { - _logger.LogMultiline(msg, LogSeverity.Debug, log); - } - } - - /// - /// Creates the service manager. - /// - /// The assemblies with services. - /// ServiceManager. - protected override ServiceManager CreateServiceManager(params Assembly[] assembliesWithServices) - { - var types = Kernel.RestServices.Select(r => r.GetType()).ToArray(); - - return new ServiceManager(new Container(), new ServiceController(() => types)); - } - } - - /// - /// Class WebSocketConnectEventArgs - /// - public class WebSocketConnectEventArgs : EventArgs - { - /// - /// Gets or sets the web socket. - /// - /// The web socket. - public IWebSocket WebSocket { get; set; } - /// - /// Gets or sets the endpoint. - /// - /// The endpoint. - public IPEndPoint Endpoint { get; set; } - } - - class ContainerAdapter : IContainerAdapter - { - private readonly IApplicationHost _appHost; - - public ContainerAdapter(IApplicationHost appHost) - { - _appHost = appHost; - } - public T Resolve() - { - return _appHost.Resolve(); - } - - public T TryResolve() - { - return _appHost.TryResolve(); - } - } -} \ No newline at end of file diff --git a/MediaBrowser.Common/Net/IHttpServer.cs b/MediaBrowser.Common/Net/IHttpServer.cs new file mode 100644 index 000000000..a640fb262 --- /dev/null +++ b/MediaBrowser.Common/Net/IHttpServer.cs @@ -0,0 +1,44 @@ +using System; + +namespace MediaBrowser.Common.Net +{ + /// + /// Interface IHttpServer + /// + public interface IHttpServer : IDisposable + { + /// + /// Gets the URL prefix. + /// + /// The URL prefix. + string UrlPrefix { get; } + + /// + /// Starts the specified server name. + /// + /// The URL. + void Start(string urlPrefix); + + /// + /// Gets a value indicating whether [supports web sockets]. + /// + /// true if [supports web sockets]; otherwise, false. + bool SupportsWebSockets { get; } + + /// + /// Stops this instance. + /// + void Stop(); + + /// + /// Gets or sets a value indicating whether [enable HTTP request logging]. + /// + /// true if [enable HTTP request logging]; otherwise, false. + bool EnableHttpRequestLogging { get; set; } + + /// + /// Occurs when [web socket connected]. + /// + event EventHandler WebSocketConnected; + } +} \ No newline at end of file diff --git a/MediaBrowser.Common/Net/IUdpServer.cs b/MediaBrowser.Common/Net/IUdpServer.cs index 01a8ef021..036977eab 100644 --- a/MediaBrowser.Common/Net/IUdpServer.cs +++ b/MediaBrowser.Common/Net/IUdpServer.cs @@ -1,7 +1,46 @@ - +using System; +using System.Threading.Tasks; + namespace MediaBrowser.Common.Net { - public interface IUdpServer + /// + /// Interface IUdpServer + /// + public interface IUdpServer : IDisposable { + /// + /// Occurs when [message received]. + /// + event EventHandler MessageReceived; + + /// + /// Starts the specified port. + /// + /// The port. + void Start(int port); + + /// + /// Stops this instance. + /// + void Stop(); + + /// + /// Sends the async. + /// + /// The bytes. + /// The remote end point. + /// Task. + /// data + Task SendAsync(byte[] bytes, string remoteEndPoint); + + /// + /// Sends the async. + /// + /// The bytes. + /// The ip address. + /// The port. + /// Task. + /// bytes + Task SendAsync(byte[] bytes, string ipAddress, int port); } } diff --git a/MediaBrowser.Common/Net/IWebSocketServer.cs b/MediaBrowser.Common/Net/IWebSocketServer.cs new file mode 100644 index 000000000..5ce571fbb --- /dev/null +++ b/MediaBrowser.Common/Net/IWebSocketServer.cs @@ -0,0 +1,26 @@ +using System; + +namespace MediaBrowser.Common.Net +{ + /// + /// Interface IWebSocketServer + /// + public interface IWebSocketServer : IDisposable + { + /// + /// Starts the specified port number. + /// + /// The port number. + void Start(int portNumber); + + /// + /// Stops this instance. + /// + void Stop(); + + /// + /// Occurs when [web socket connected]. + /// + event EventHandler WebSocketConnected; + } +} diff --git a/MediaBrowser.Common/Net/UdpMessageReceivedEventArgs.cs b/MediaBrowser.Common/Net/UdpMessageReceivedEventArgs.cs new file mode 100644 index 000000000..bd5034c47 --- /dev/null +++ b/MediaBrowser.Common/Net/UdpMessageReceivedEventArgs.cs @@ -0,0 +1,21 @@ +using System; + +namespace MediaBrowser.Common.Net +{ + /// + /// Class UdpMessageReceivedEventArgs + /// + public class UdpMessageReceivedEventArgs : EventArgs + { + /// + /// Gets or sets the bytes. + /// + /// The bytes. + public byte[] Bytes { get; set; } + /// + /// Gets or sets the remote end point. + /// + /// The remote end point. + public string RemoteEndPoint { get; set; } + } +} diff --git a/MediaBrowser.Common/Net/UdpServer.cs b/MediaBrowser.Common/Net/UdpServer.cs deleted file mode 100644 index a3c6a8a78..000000000 --- a/MediaBrowser.Common/Net/UdpServer.cs +++ /dev/null @@ -1,142 +0,0 @@ -using System; -using System.Net; -using System.Net.Sockets; -using System.Reactive.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Net -{ - /// - /// Provides a Udp Server - /// - public class UdpServer : IObservable, IDisposable - { - /// - /// The _udp client - /// - private readonly UdpClient _udpClient; - /// - /// The _stream - /// - private readonly IObservable _stream; - - /// - /// Initializes a new instance of the class. - /// - /// The end point. - /// endPoint - public UdpServer(IPEndPoint endPoint) - { - if (endPoint == null) - { - throw new ArgumentNullException("endPoint"); - } - - _udpClient = new UdpClient(endPoint); - - _udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); - //_udpClient.ExclusiveAddressUse = false; - - _stream = CreateObservable(); - } - - /// - /// Creates the observable. - /// - /// IObservable{UdpReceiveResult}. - private IObservable CreateObservable() - { - return Observable.Create(obs => - Observable.FromAsync(() => _udpClient.ReceiveAsync()) - .Subscribe(obs)) - .Repeat() - .Retry() - .Publish() - .RefCount(); - } - - /// - /// Subscribes the specified observer. - /// - /// The observer. - /// IDisposable. - /// observer - public IDisposable Subscribe(IObserver observer) - { - if (observer == null) - { - throw new ArgumentNullException("observer"); - } - - return _stream.Subscribe(observer); - } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool dispose) - { - if (dispose) - { - _udpClient.Close(); - } - } - - /// - /// Sends the async. - /// - /// The data. - /// The end point. - /// Task{System.Int32}. - /// data - public async Task SendAsync(string data, IPEndPoint endPoint) - { - if (data == null) - { - throw new ArgumentNullException("data"); - } - - if (endPoint == null) - { - throw new ArgumentNullException("endPoint"); - } - - var bytes = Encoding.UTF8.GetBytes(data); - - return await _udpClient.SendAsync(bytes, bytes.Length, endPoint).ConfigureAwait(false); - } - - /// - /// Sends the async. - /// - /// The bytes. - /// The end point. - /// Task{System.Int32}. - /// bytes - public async Task SendAsync(byte[] bytes, IPEndPoint endPoint) - { - if (bytes == null) - { - throw new ArgumentNullException("bytes"); - } - - if (endPoint == null) - { - throw new ArgumentNullException("endPoint"); - } - - return await _udpClient.SendAsync(bytes, bytes.Length, endPoint).ConfigureAwait(false); - } - } -} diff --git a/MediaBrowser.Common/Net/WebSocketConnectEventArgs.cs b/MediaBrowser.Common/Net/WebSocketConnectEventArgs.cs new file mode 100644 index 000000000..711da7a50 --- /dev/null +++ b/MediaBrowser.Common/Net/WebSocketConnectEventArgs.cs @@ -0,0 +1,22 @@ +using System; +using System.Net; + +namespace MediaBrowser.Common.Net +{ + /// + /// Class WebSocketConnectEventArgs + /// + public class WebSocketConnectEventArgs : EventArgs + { + /// + /// Gets or sets the web socket. + /// + /// The web socket. + public IWebSocket WebSocket { get; set; } + /// + /// Gets or sets the endpoint. + /// + /// The endpoint. + public string Endpoint { get; set; } + } +} diff --git a/MediaBrowser.Common/Net/WebSocketConnection.cs b/MediaBrowser.Common/Net/WebSocketConnection.cs index d274d390d..ab691c823 100644 --- a/MediaBrowser.Common/Net/WebSocketConnection.cs +++ b/MediaBrowser.Common/Net/WebSocketConnection.cs @@ -21,7 +21,7 @@ namespace MediaBrowser.Common.Net /// /// The _remote end point /// - public readonly EndPoint RemoteEndPoint; + public readonly string RemoteEndPoint; /// /// The _cancellation token source @@ -45,13 +45,13 @@ namespace MediaBrowser.Common.Net /// The remote end point. /// The receive action. /// socket - public WebSocketConnection(IWebSocket socket, EndPoint remoteEndPoint, Action receiveAction, ILogger logger) + public WebSocketConnection(IWebSocket socket, string remoteEndPoint, Action receiveAction, ILogger logger) { if (socket == null) { throw new ArgumentNullException("socket"); } - if (remoteEndPoint == null) + if (string.IsNullOrEmpty(remoteEndPoint)) { throw new ArgumentNullException("remoteEndPoint"); } -- cgit v1.2.3