Beispiel #1
0
        /// <summary>
        /// Connect to the XMPP server.
        /// This establishes the connection to the server, including TLS, authentication, resource binding and
        /// compression.
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="AuthenticationException">Thrown when the authentication fails.</exception>
        /// <exception cref="BindException">Thrown when resource binding fails.</exception>
        /// <exception cref="StreamErrorException">Throws a StreamErrorException when the server returns a stream error.</exception>
        /// <exception cref="CompressionException">Throws a CompressionException when establishing stream compression fails.</exception>
        /// <exception cref="RegisterException">Throws aRegisterException when new account registration fails.</exception>
        public async Task <IChannel> ConnectAsync(CancellationToken cancellationToken)
        {
            var iChannel = await Bootstrap.ConnectAsync(XmppDomain, Port);

            SessionState = SessionState.Connected;

            if (HostnameResolver.Implements <IDirectTls>() &&
                HostnameResolver.Cast <IDirectTls>().DirectTls == true)
            {
                await DoSslAsync(cancellationToken);
            }

            var feat = await SendStreamHeaderAsync(cancellationToken);

            var streamFeatures = await HandleStreamFeaturesAsync(feat, cancellationToken);

            var open = new Open()
            {
                From    = Pipeline.Get <StreamPropsCaptureHandler>().From,
                Id      = Pipeline.Get <StreamPropsCaptureHandler>().Id,
                Version = Pipeline.Get <StreamPropsCaptureHandler>().Version,
            };

            await WebSocket.SendText(open.ToString(false));

            // lets add the forwarding handler now
            this.Pipeline.AddBefore <CatchAllXmppStanzaHandler>(new ForwardHandler(this.WebSocket));
            await WebSocket.SendText(streamFeatures.ToString(false));

            return(iChannel);
        }
Beispiel #2
0
        /// <summary>
        /// Connect to the XMPP server.
        /// This establishes the connection to the server, including TLS, authentication, resource binding and
        /// compression.
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="AuthenticationException">Thrown when the authentication fails.</exception>
        /// <exception cref="BindException">Thrown when resource binding fails.</exception>
        /// <exception cref="StreamErrorException">Throws a StreamErrorException when the server returns a stream error.</exception>
        /// <exception cref="CompressionException">Throws a CompressionException when establishing stream compression fails.</exception>
        /// <exception cref="RegisterException">Throws aRegisterException when new account registration fails.</exception>
        public override async Task <IChannel> ConnectAsync(CancellationToken cancellationToken)
        {
            var iChannel = await Bootstrap.ConnectAsync(XmppDomain, Port);

            XmppSessionState.Value = SessionState.Connected;

            if (HostnameResolver.Implements <IDirectTls>() &&
                HostnameResolver.Cast <IDirectTls>().DirectTls == true)
            {
                await DoSslAsync(cancellationToken);
            }

            var feat = await SendStreamHeaderAsync(cancellationToken);

            await HandleStreamFeaturesAsync(feat, cancellationToken);

            return(iChannel);
        }