public ConnectAsync ( |
||
address | ||
return | Task |
public async Task ConnectAsync(Address address)
{
Uri uri = new UriBuilder()
{
Scheme = address.Scheme,
Port = GetDefaultPort(address.Scheme, address.Port),
Host = address.Host,
Path = address.Path
}.Uri;
ClientWebSocket cws = new ClientWebSocket();
cws.Options.AddSubProtocol(WebSocketSubProtocol);
await cws.ConnectAsync(uri, CancellationToken.None);
if (cws.SubProtocol != WebSocketSubProtocol)
{
cws.Abort();
throw new NotSupportedException(
string.Format(
CultureInfo.InvariantCulture,
"WebSocket SubProtocol used by the host is not the same that was requested: {0}",
cws.SubProtocol ?? "<null>"));
}
this.webSocket = cws;
}
/// <summary> /// Creates a WebSocket transport for the given address. /// </summary> /// <param name="address">The address to connect.</param> /// <returns>An IAsyncTransport object representing the transport.</returns> public override async Task <IAsyncTransport> CreateAsync(Address address) { var wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address, this.subprotocol, this.Options); return(wsTransport); }