Example #1
0
        public void Connect(string hostname, int port, int connectionTimeout, string nickname, string username, string realname)
        {
            ConnectionFailure = null;
            if (IsConnected)
            {
                Disconnect();
            }

            Hostname          = hostname;
            Port              = port;
            ConnectionTimeout = connectionTimeout;
            Nickname          = nickname;
            Username          = username;
            Realname          = realname;

            thread = new Thread(() =>
            {
                try
                {
                    ConnectionState = IrcConnectionState.Connecting;
                    LocalUser       = new IrcClientUser(this);
                    connection      = new IrcConnection();
                    OnConnecting();
                    connection.Connect(hostname, port, connectionTimeout);
                    ConnectionState = IrcConnectionState.Connected;
                    OnConnect();
                    SetNickname(nickname);
                    SetUser(username, realname);
                    ProcessLines();
                }
                catch (Exception e)
                {
                    Log.Write("irc", e.ToString());
                    if (e is SocketException || e is IOException)
                    {
                        ConnectionFailure = e;
                    }
                }
                finally
                {
                    Disconnect();
                }
            })
            {
                IsBackground = true
            };
            thread.Start();
        }
Example #2
0
		public void Connect(string hostname, int port, int connectionTimeout, string nickname, string username, string realname)
		{
			ConnectionFailure = null;
			if (IsConnected)
				Disconnect();

			Hostname = hostname;
			Port = port;
			ConnectionTimeout = connectionTimeout;
			Nickname = nickname;
			Username = username;
			Realname = realname;

			thread = new Thread(() =>
			{
				try
				{
					ConnectionState = IrcConnectionState.Connecting;
					LocalUser = new IrcClientUser(this);
					connection = new IrcConnection();
					OnConnecting();
					connection.Connect(hostname, port, connectionTimeout);
					ConnectionState = IrcConnectionState.Connected;
					OnConnect();
					SetNickname(nickname);
					SetUser(username, realname);
					ProcessLines();
				}
				catch (Exception e)
				{
					Log.Write("irc", e.ToString());
					if (e is SocketException || e is IOException)
						ConnectionFailure = e;
				}
				finally
				{
					Disconnect();
				}
			}) { IsBackground = true };
			thread.Start();
		}