public boolean connect() throws IOException {
		
		if (socket!=null || ircWriter!=null || ircReader!=null) {
			disconnect();
		}
		
		String[] channels = getChannels();

		// The server to connect to and our details.
		String server = "irc.wikimedia.org";
		String nick = "academic_record"+(int)(Math.random()*1000);
		String login = "academic_study";

		// Connect directly to the IRC server.
		socket = new Socket(server, 6667);
		ircWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(),UTF8));
		ircReader = new BufferedReader(new InputStreamReader(socket.getInputStream(),UTF8));


		// Log on to the server.
		ircWriter.write("NICK " + nick + "\r\n");
		ircWriter.write("USER " + login
				+ " 8 * : Academic study of Wikipedia Changes\r\n");
		ircWriter.flush();

		// Read lines from the server until it tells us we have connected.
		String line = null;
		while ((line = ircReader.readLine()) != null) {
			if (line.indexOf("004") >= 0) {
				// We are now logged in.
				break;
			} else if (line.indexOf("433") >= 0) {
				System.err.println("Nickname " + nick +  " is already in use. Cannot connect.");
				return false;
			}
		}

		// Join the channels.
		for (String channel : channels) {
			ircWriter.write("JOIN " + channel + "\r\n");
		}
		ircWriter.flush();
		
		return true;
	}