// Public Methods (1) /// <summary> /// Retrieves an Ortc Server url from the Ortc Balancer /// </summary> /// <param name="balancerUrl">The Ortc Balancer url.</param> /// <param name="onClusterUrlResolved">Callback that is raised after an Ortc server url have been retrieved from the Ortc balancer.</param> /// <example> /// <code> /// String url = "http://ortc-developers.realtime.co/server/2.1/"; /// Balancer.GetServerFromBalancer(url, applicationKey, (server) => /// { /// //Do something with the returned server /// }); /// </code> /// </example> /// <remarks></remarks> public static void GetServerFromBalancerAsync(String balancerUrl, String applicationKey, OnBalancerUrlResolvedDelegate onClusterUrlResolved) { var parsedUrl = String.IsNullOrEmpty(applicationKey) ? balancerUrl : balancerUrl + "?appkey=" + applicationKey; var request = (HttpWebRequest)WebRequest.Create(new Uri(parsedUrl)); //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; request.Proxy = null; request.Timeout = 10000; request.ProtocolVersion = HttpVersion.Version11; request.Method = "GET"; request.BeginGetResponse(new AsyncCallback((asynchronousResult) => { var server = String.Empty; try { HttpWebRequest asyncRequest = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response = (HttpWebResponse)asyncRequest.EndGetResponse(asynchronousResult); Stream streamResponse = response.GetResponseStream(); StreamReader streamReader = new StreamReader(streamResponse); server = ParseBalancerResponse(streamReader); if (onClusterUrlResolved != null) { onClusterUrlResolved(server, null); } } catch (Exception ex) { onClusterUrlResolved(server, ex); } }), request); }
// Public Methods (1) /// <summary> /// Retrieves an Ortc Server url from the Ortc Balancer /// </summary> /// <param name="balancerUrl">The Ortc Balancer url.</param> /// <param name="onClusterUrlResolved">Callback that is raised after an Ortc server url have been retrieved from the Ortc balancer.</param> /// <example> /// <code> /// String url = "http://ortc-developers.realtime.co/server/2.1/"; /// Balancer.GetServerFromBalancer(url, applicationKey, (server) => /// { /// //Do something with the returned server /// }); /// </code> /// </example> /// <remarks></remarks> public static void GetServerFromBalancerAsync(String balancerUrl, String applicationKey, OnBalancerUrlResolvedDelegate onClusterUrlResolved) { var parsedUrl = String.IsNullOrEmpty(applicationKey) ? balancerUrl : balancerUrl + "?appkey=" + applicationKey; var request = (HttpWebRequest)WebRequest.Create(new Uri(parsedUrl)); //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; request.Proxy = null; request.Timeout = 10000; request.ProtocolVersion = HttpVersion.Version11; request.Method = "GET"; request.BeginGetResponse(new AsyncCallback((asynchronousResult) => { var server = String.Empty; try { HttpWebRequest asyncRequest = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response = (HttpWebResponse)asyncRequest.EndGetResponse(asynchronousResult); Stream streamResponse = response.GetResponseStream(); StreamReader streamReader = new StreamReader(streamResponse); server = ParseBalancerResponse(streamReader); if (!IsWellFormedBalancerUrl(server)) { throw new Exception("Balancer server url is not valid (" + server + ")"); } if (onClusterUrlResolved != null) { onClusterUrlResolved(server, null); } } catch (Exception ex) { if (onClusterUrlResolved != null) { onClusterUrlResolved(server, ex); } } }), request); }
// Public Methods (1) /// <summary> /// Retrieves an Ortc Server url from the Ortc Balancer /// </summary> /// <param name="balancerUrl">The Ortc Balancer url.</param> /// <param name="applicationKey">The application key.</param> /// <param name="onClusterUrlResolved">Callback that is raised after an Ortc server url have been retrieved from the Ortc balancer.</param> /// <example> /// <code> /// String url = "http://ortc-developers.realtime.co/server/2.1/"; /// Balancer.GetServerFromBalancer(url, applicationKey, (server) => /// { /// //Do something with the returned server /// }); /// </code> /// </example> /// <remarks></remarks> public async static void GetServerFromBalancerAsync(String balancerUrl, String applicationKey, OnBalancerUrlResolvedDelegate onClusterUrlResolved) { var parsedUrl = String.IsNullOrEmpty(applicationKey) ? balancerUrl : balancerUrl + "?appkey=" + applicationKey; var server = String.Empty; try { using (var client = new HttpClient(new HttpClientHandler())) { var response = await client.GetStreamAsync(new Uri(parsedUrl)); StreamReader streamReader = new StreamReader(response); server = ParseBalancerResponse(streamReader); if (onClusterUrlResolved != null) { onClusterUrlResolved(server, null); } } } catch (Exception ex) { onClusterUrlResolved(server, ex); } }