/// <summary> /// Connects asynchronously to the specified WebSocket server /// </summary> /// <param name="url">The URI of the WebSocket server to connect to.</param> /// <param name="protocols"></param> /// public Task <PPError> ConnectAsync(Uri url, MessageLoop messageLoop, string[] protocols = null, MessageLoop connectLoop = null) { if (PPBWebSocket.IsWebSocket(this) != PPBool.True) { throw new PlatformNotSupportedException("Websocket not supported"); } if (url == null) { throw new ArgumentNullException(nameof(url)); } if (!url.IsAbsoluteUri) { throw new ArgumentException("Not Absolute URI", nameof(url)); } if (url.Scheme.ToLower() != UriSchemeWs && url.Scheme.ToLower() != UriSchemeWss) { throw new ArgumentException("Scheme invalid", nameof(url)); } return(ConnectAsyncCore(url, protocols, connectLoop)); }
/// <summary> /// Connects to the specified WebSocket server /// </summary> /// <param name="url">The URI of the WebSocket server to connect to.</param> /// <param name="protocols"></param> public void Connect(Uri url, string[] protocols = null) { if (PPBWebSocket.IsWebSocket(this) != PPBool.True) { throw new PlatformNotSupportedException("Websocket not supported"); } if (url == null) { throw new ArgumentNullException(nameof(url)); } if (!url.IsAbsoluteUri) { throw new ArgumentException("Not Absolute URI", nameof(url)); } if (url.Scheme.ToLower() != UriSchemeWs && url.Scheme.ToLower() != UriSchemeWss) { throw new ArgumentException("Scheme invalid", nameof(url)); } PPVar[] varProtocols = null; if (protocols != null) { varProtocols = new PPVar[protocols.Length]; for (int p = 0; p < protocols.Length; p++) { varProtocols[p] = new Var(protocols[p]); } } var connectResult = (PPError)PPBWebSocket.Connect(this, new Var(url.AbsoluteUri), varProtocols, varProtocols == null ? 0 : (uint)varProtocols.Length, new CompletionCallback(OnConnect) ); }