/// <inheritdoc cref="Connect(string, int, bool, IrcRegistrationInfo)"/>
        /// <summary>
        /// Connects to a server using the specified URL and user information.
        /// </summary>
        public void Connect(Uri url, IrcRegistrationInfo registrationInfo)
        {
            CheckDisposed();

            if (registrationInfo == null)
            {
                throw new ArgumentNullException("registrationInfo");
            }

            // Check URL scheme and decide whether to use SSL.
            bool useSsl;

            if (url.Scheme == "irc")
            {
                useSsl = false;
            }
            else if (url.Scheme == "ircs")
            {
                useSsl = true;
            }
            else
            {
                throw new ArgumentException(string.Format(Resources.MessageInvalidUrlScheme,
                                                          url.Scheme), "url");
            }

            Connect(url.Host, url.Port == -1 ? DefaultPort : url.Port, useSsl, registrationInfo);
        }
        protected override void HandleClientConnected(IrcRegistrationInfo regInfo)
        {
            DebugUtilities.WriteEvent(string.Format("Connected to server at '{0}'.",
                                                    ((IPEndPoint)this.socket.RemoteEndPoint).Address));

            base.HandleClientConnected(regInfo);
        }
        /// <summary>
        /// Connects asynchronously to the specified server.
        /// </summary>
        /// <param name="remoteEndPoint">The network endpoint (IP address and port) of the server to which to connect.
        /// </param>
        /// <param name="useSsl"><see langword="true"/> to connect to the server via SSL; <see langword="false"/>,
        /// otherwise</param>
        /// <param name="registrationInfo">The information used for registering the client.
        /// The type of the object may be either <see cref="IrcUserRegistrationInfo"/> or
        /// <see cref="IrcServiceRegistrationInfo"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="registrationInfo"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="registrationInfo"/> does not specify valid registration
        /// information.</exception>
        /// <exception cref="ObjectDisposedException">The current instance has already been disposed.</exception>
        public void Connect(EndPoint remoteEndPoint, bool useSsl, IrcRegistrationInfo registrationInfo)
        {
            Connect(registrationInfo);
            // Connect socket to remote host.
            ConnectAsync(remoteEndPoint, Tuple.Create(useSsl, string.Empty, registrationInfo));

            HandleClientConnecting();
        }
        /// <inheritdoc cref="Connect(EndPoint, bool, IrcRegistrationInfo)"/>
        /// <param name="address">An IP addresses that designates the remote host.</param>
        /// <param name="port">The port number of the remote host.</param>
        public void Connect(IPAddress address, int port, bool useSsl, IrcRegistrationInfo registrationInfo)
        {
            CheckDisposed();

            if (registrationInfo == null)
            {
                throw new ArgumentNullException("registrationInfo");
            }

            Connect(new IPEndPoint(address, port), useSsl, registrationInfo);
        }
        /// <inheritdoc cref="Connect(IPAddress, int, bool, IrcRegistrationInfo)"/>
        public void Connect(IPAddress address, bool useSsl, IrcRegistrationInfo registrationInfo)
        {
            CheckDisposed();

            if (registrationInfo == null)
            {
                throw new ArgumentNullException("registrationInfo");
            }

            Connect(address, DefaultPort, useSsl, registrationInfo);
        }
        /// <inheritdoc cref="Connect(EndPoint, bool, IrcRegistrationInfo)"/>
        /// <param name="hostName">The name of the remote host.</param>
        /// <param name="port">The port number of the remote host.</param>
        public void Connect(string hostName, int port, bool useSsl, IrcRegistrationInfo registrationInfo)
        {
            CheckDisposed();

            if (registrationInfo == null)
            {
                throw new ArgumentNullException("registrationInfo");
            }

            Connect(new DnsEndPoint(hostName, port), useSsl, registrationInfo);
        }
        /// <inheritdoc cref="Connect(string, int, bool, IrcRegistrationInfo)"/>
        public void Connect(string hostName, bool useSsl, IrcRegistrationInfo registrationInfo)
        {
            CheckDisposed();

            if (registrationInfo == null)
            {
                throw new ArgumentNullException("registrationInfo");
            }

            Connect(hostName, DefaultPort, useSsl, registrationInfo);
        }