@Override
	public void run() {
		ServerSocket socket;
		boolean isRefreshRequest = false;
		
		System.out.println("Webserver starting up on port "+ SERVER_PORT);
		System.out.println("(press ctrl-c to exit)");
		try {
			// create the main server socket
			socket = new ServerSocket(SERVER_PORT);
		} catch (Exception e) {
			System.out.println("Error: " + e);
			return;
		}

		System.out.println("Waiting for connection");
		while (!WebThread.interrupted()) {
			try {
				isRefreshRequest = false;
				// wait for a connection
				Socket remote = socket.accept();
				// remote is now the connected socket
				System.out.println("Connection, sending data.");
				BufferedReader in = new BufferedReader(new InputStreamReader(
						remote.getInputStream()));
				PrintWriter out = new PrintWriter(remote.getOutputStream());

				// read the data sent. We basically ignore it,
				// stop reading once a blank line is hit. This
				// blank line signals the end of the client HTTP
				// headers.
				String str = ".";
				while (!str.equals("")) {
					str = in.readLine();
					if (str.contains("/refresh")) {
						isRefreshRequest = true;
					} else if (str.contains("/restart")) {
						Main.restartGame();
					}
				}

				// Send the response
				// Send the headers
				out.println("HTTP/1.0 200 OK");
				if (isRefreshRequest) {
					out.println("Content-Type: text/json");
				} else {
					out.println("Content-Type: text/html");
				}
				// this blank line signals the end of the headers
				out.println("");
				// Send the HTML page

				String result;
				if (isRefreshRequest) {
					result = makeRefreshJson();
				} else {
					result = makeHtmlString();
				}

				out.println(result);
				out.flush();
				remote.close();
			} catch (Exception e) {
				System.out.println("Error: " + e);
			}
		}

		try {
			socket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}