void Connect(Action <TcpClient> connectTcpClientCallback, IrcClientConnectionOptions options) { var client = new TcpClient(); connectTcpClientCallback(client); try { Connect(client.GetStream(), options); } catch (Exception) { client.Close(); throw; } }
/// <summary> /// Connects to an IRC server specified by a stream. /// </summary> /// <param name="stream">The stream.</param> /// <param name="options">Options for the connection, if any, or <c>null</c>.</param> public void Connect(Stream stream, IrcClientConnectionOptions options = null) { Throw.If.Null(stream, "stream"); Close(); if (options == null) { options = new IrcClientConnectionOptions(); } if (options.Ssl) { if (options.SslHostname == null) { throw new ArgumentException("If Ssl is true, SslHostname must be set.", "options"); } var sslStream = new SslStream(stream, false, options.SslCertificateValidationCallback); sslStream.AuthenticateAsClient(options.SslHostname); stream = sslStream; } var context = new Context() { ReceiverThread = new Thread(ThreadReceiver) { Name = "IRC Receiver", }, StartEvent = new ManualResetEvent(false), Stream = stream, SynchronizationContext = options.SynchronizationContext }; _context = context; context.ReceiverThread.IsBackground = true; context.ReceiverThread.Start(context); try { IsConnected = true; OnConnected(); } finally { context.StartEvent.Set(); } }
/// <summary> /// Connects to an IRC server specified by an endpoint. /// </summary> /// <param name="endPoint">The IP endpoint to connect to.</param> /// <param name="options">Options for the connection, if any, or <c>null</c>.</param> public void Connect(IPEndPoint endPoint, IrcClientConnectionOptions options = null) { Throw.If.Null(endPoint, "endPoint"); Connect(client => client.Connect(endPoint), options); }
/// <summary> /// Connects to an IRC server. /// </summary> /// <param name="hostname">The server hostname.</param> /// <param name="port">The server port.</param> /// <param name="options">Options for the connection, if any, or <c>null</c>.</param> public void Connect(string hostname, int port = 6667, IrcClientConnectionOptions options = null) { Throw.If.Null(hostname, "hostname").Negative(port, "port"); Connect(client => client.Connect(hostname, port), options); }