public async Task ConnectAsync(string url) { Uri uri = new Uri(url); string query = uri.PathAndQuery; bool ssl = uri.Scheme.ToLower().StartsWith("wss"); int port = uri.Port > 0 ? uri.Port : (ssl ? 443 : 80); await client.ConnectAsync(uri.Host, port); ConnectionStream stream = new ConnectionStream(ref client, ssl); if (ssl) { await stream.Authenticate(ConnectionStream.AuthMode.Client, uri.Host); } if (!(await Handshake(stream, uri, port))) { state = WebsockState.Closed; throw new Exception("Failed connection at handshake"); } protocol = new WebsockProtocol(ref stream); state = WebsockState.Open; try { while (true) { await OnMessage(await protocol.GetMessage()); } } catch (WebsockCloseException ex) { await OnClose(ex.Code, ex.Reason); } finally { protocol.Dispose(); } }
public WebsockServerClient(WebsockServer server, ref ConnectionStream stream) { this.server = server; this.protocol = new WebsockProtocol(ref stream); }