public void run()
	{
		MyHTTPServer socket = null;

		try
		{
			for(;;)
			{
				CoffeeSaint.log.add("Waiting for connection");
				try
				{
					if (socket == null)
					{
						CoffeeSaint.log.add("Listening on " + config.getHTTPServerListenAdapter() + ":" + config.getHTTPServerListenPort());

						socket = new MyHTTPServer(config.getHTTPServerListenAdapter(), config.getHTTPServerListenPort());
					}

					List<HTTPRequestData> request = socket.acceptConnectionGetRequest();
					if (request.size() == 0)
						continue;
					System.out.println(" + request start");
					String requestType = request.get(0).getName();
					String url = request.get(0).getData().trim();
					int space = url.indexOf(" ");
					if (space != -1)
						url = url.substring(0, space);

					expireSessions(sessions);

					List<HTTPRequestData> getData = null;
					int questionMark = url.indexOf("?");
					if (questionMark != -1)
					{
						String parameters = "";
						if (questionMark < url.length() - 1)
							parameters = url.substring(questionMark + 1);
						url = url.substring(0, questionMark);
						getData = MyHTTPServer.splitHTTPLine(parameters);
					}

					InetSocketAddress remoteAddress = socket.getRemoteSocketAddress();
					logEntry(remoteAddress, requestType, url);

					String authCookie = null;
					HTTPRequestData cookieRD = MyHTTPServer.findRecord(request, "Cookie:");
					if (cookieRD != null)
					{
						// System.out.println("Cookie string: " + cookieRD.getData());
						authCookie = "auth=" + MyHTTPServer.getCookieData(cookieRD.getData(), "auth");
					}
					if (authCookie == null)
						authCookie = "auth=" + Math.abs(new Random(System.currentTimeMillis()).nextInt());

					if (!sessionValid(sessions, remoteAddress.getAddress().toString(), authCookie) && config.getAuthentication() == true && config.getWebUsername() != null && config.getWebPassword() != null && url.equals("/login.html") == false && url.equals("/cgi-bin/login-do.cgi") == false && mySubstring(url, 0, 8).equals("/images/") == false && url.equals("/design.css") == false)
					{
						sendReply_redirectTo(socket, "/login.html");
						continue;
					}

					boolean isHeadRequest = false;
					if (requestType.equals("HEAD"))
						isHeadRequest = true;

					if (url.charAt(0) != '/')
						url = "/" + url;

					if (url.equals("/") || url.equals("/index.html"))
						sendReply_root(socket, authCookie);
					else if (url.equals("/login.html"))
						sendReply_loginhtml(socket, authCookie);
					else if (url.equals("/cgi-bin/login-do.cgi"))
					{
						List<HTTPRequestData> requestData = socket.getRequestData(request);
						sendReply_cgibin_logindocgi(socket, requestData, remoteAddress.getAddress().toString(), authCookie);
					}
					else if (url.equals("/cgi-bin/force_reload.cgi"))
						sendReply_cgibin_forcereload_cgi(socket, authCookie);
					else if (url.equals("/cgi-bin/statistics.cgi"))
						sendReply_cgibin_statistics_cgi(socket, authCookie);
					else if (url.equals("/cgi-bin/nagios_status.cgi"))
						sendReply_cgibin_nagiosstatus_cgi(socket, authCookie);
					else if (url.equals("/image.jpg"))
						sendReply_imagejpg(socket, authCookie);
					else if (url.equals("/cgi-bin/config-menu.cgi"))
						sendReply_cgibin_configmenu_cgi(socket, authCookie);
					else if (url.equals("/cgi-bin/select_configfile.cgi"))
						sendReply_cgibin_select_configfile_cgi(socket, authCookie);
					else if (url.equals("/cgi-bin/jvm_stats.cgi"))
						sendReply_cgibin_system_info(socket, authCookie);
					else if (url.equals("/cgi-bin/select_configfile-do.cgi"))
					{
						List<HTTPRequestData> requestData = socket.getRequestData(request);
						sendReply_cgibin_select_configfile_do_cgi(socket, requestData, authCookie);
					}
					else if (url.equals("/cgi-bin/config-do.cgi"))
					{
						List<HTTPRequestData> requestData = socket.getRequestData(request);
						sendReply_cgibin_configdo_cgi(socket, requestData, authCookie);
						socket.closeServer();
						socket = null;
					}
					else if (url.equals("/cgi-bin/reload-config.cgi"))
						sendReply_cgibin_reloadconfig_cgi(socket, authCookie);
					else if (url.equals("/cgi-bin/write-config.cgi"))
						sendReply_cgibin_writeconfig_cgi(socket, authCookie);
					else if (url.equals("/cgi-bin/test-sound.cgi"))
						sendReply_cgibin_testsound_cgi(socket, authCookie);
					else if (url.equals("/cgi-bin/log.cgi"))
						sendReply_cgibin_log_cgi(socket, authCookie);
					else if (url.equals("/images/bg01.png"))
						sendReply_images_bg01_png(socket, isHeadRequest);
					else if (url.equals("/images/coffee.png"))
						sendReply_images_coffee_png(socket, isHeadRequest);
					else if (url.equals("/images/footer01.png"))
						sendReply_images_footer01_png(socket, isHeadRequest);
					else if (url.equals("/images/saint01.png"))
						sendReply_images_saint01_png(socket, isHeadRequest);
					else if (url.equals("/images/title01.png"))
						sendReply_images_title01_png(socket, isHeadRequest);
					else if (url.equals("/robots.txt"))
						sendReply_robots_txt(socket, isHeadRequest);
					else if (url.equals("/favicon.ico"))
						sendReply_favicon_ico(socket, isHeadRequest);
					else if (url.equals("/links.html"))
						sendReply_links_html(socket, authCookie);
					else if (url.equals("/help-escapes.html"))
						sendReply_helpescapes_html(socket, authCookie);
					else if (url.equals("/cgi-bin/list-all.cgi"))
						sendReply_cgibin_listall_cgi(socket, getData, authCookie);
					else if (url.equals("/cgi-bin/list-log.cgi"))
						sendReply_cgibin_listlog_cgi(socket, authCookie);
					else if (url.equals("/cgi-bin/performance-data.cgi"))
						sendReply_cgibin_performancedata_cgi(socket, getData, authCookie);
					else if (url.equals("/design.css"))
						sendReply_design_css(socket, isHeadRequest);
					else if (url.equals("/cgi-bin/sparkline.cgi"))
						sendReply_cgibin_sparkline_cgi(socket, getData, authCookie);
					else if (url.equals("/cgi-bin/graph-zoomin.cgi"))
						sendReply_cgibin_zoomin_cgi(socket, getData, authCookie);
					else if (url.equals("/cgi-bin/latency-graph.cgi"))
						sendReply_cgibin_latency_cgi(socket, getData, authCookie);
					else if (url.equals("/latency-graph.html"))
						sendReply_latencygraph_html(socket, authCookie);
					else if (url.equals("/CoffeeSaint.jar"))
						sendReply_CoffeeSaint_jar(socket);
					else if (url.equals("/applet.html"))
						sendReply_applet_html(socket);
					else
					{
						sendReply_404(socket, url);
						webServer404++;
					}
				}
				catch(SocketException se)
				{
					CoffeeSaint.log.add("Exception: " + se);
					try
					{
						socket.close();
					}
					catch(SocketException se2)
					{
						CoffeeSaint.log.add("Could not close socket after SocketException, continuing");
					}
				}
				catch(Exception e)
				{
					statistics.incExceptions();

					CoffeeSaint.log.add("Exception during command processing");
					CoffeeSaint.showException(e);
					if (socket != null)
					{
						socket.closeServer();
						socket = null;
					}
				}
				System.out.println(" + request end");
			}
		}
		catch(Exception e)
		{
			statistics.incExceptions();

			System.err.println("Cannot create listen socket: " + e);
			CoffeeSaint.showException(e);
			System.exit(127);
		}
	}