title: How to redirect to locally stored index.html file when localhost:<port> is called from a browser
body: <p>I am creating a socket server in android. I have a directory in my local storage in which there is index.html and all other resources needed. I want that when i start the socket server and then call localhost: from my mobile's browser then it redirects to the index.html.
  My socket is running. the logs are printing. the issue is i don't know how to redirect to index.html. 
  Thanks in advance.</p>
  
  <p>Below is my code:</p>
  
  <pre><code>public class Server {
  MainActivity activity;
  ServerSocket serverSocket;
  String message = "";
  static final int socketServerPORT = 8080;
  
  public Server(MainActivity activity) {
      this.activity = activity;
      Thread socketServerThread = new Thread(new SocketServerThread());
      socketServerThread.start();
  }
  
  public int getPort() {
      return socketServerPORT;
  }
  
  public void onDestroy() {
      if (serverSocket != null) {
          try {
              serverSocket.close();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  }
  
  private class SocketServerThread extends Thread {
  
      int count = 0;
  
      @Override
      public void run() {
          try {
              // create ServerSocket using specified port
              serverSocket = new ServerSocket(socketServerPORT);
  
              while (true) {
                  // block the call until connection is created and return
                  // Socket object
                  Socket socket = serverSocket.accept();
                  count++;
                  message += "#" + count + " from "
                          + socket.getInetAddress() + ":"
                          + socket.getPort() + "\n";
  
                  activity.runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                          System.out.println("SocketServerThread.run i am running");
                      }
                  });
  
                  SocketServerReplyThread socketServerReplyThread =
                          new SocketServerReplyThread(socket, count);
                  socketServerReplyThread.run();
  
              }
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  }
  
  private class SocketServerReplyThread extends Thread {
  
      private Socket hostThreadSocket;
      int cnt;
  
      SocketServerReplyThread(Socket socket, int c) {
          hostThreadSocket = socket;
          cnt = c;
      }
  
      @Override
      public void run() {
          OutputStream outputStream;
  
          String msgReply = "Hello from Server, you are #" + cnt;
            final String OUTPUT = "https://www.google.com";
            final String OUTPUT_HEADERS = "HTTP/1.1 200 OK\r\n" +
                  "Content-Type: text/html; charset=UTF-8\r\n" +
                    "date: Fri, 25 Oct 2019 04:58:29 GMT"+
                  "Content-Length: ";
               final String OUTPUT_END_OF_HEADERS = "\r\n\r\n";
          try {
              outputStream = hostThreadSocket.getOutputStream();
              BufferedWriter out = new BufferedWriter(
                      new OutputStreamWriter(
                              new BufferedOutputStream(outputStream),"UTF-8" ));
  
                      out.write(OUTPUT_HEADERS + OUTPUT.length() + OUTPUT_END_OF_HEADERS + OUTPUT);
  
              out.flush();
              out.close();
  
              return;
  
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              message += "Something wrong! " + e.toString() + "\n";
          }
          activity.runOnUiThread(new Runnable() {
  
              @Override
              public void run() {
                  System.out.println("Here is another message for you " + message);
              }
          });
      }
  }
  
  public String getIpAddress() {
      String ip = "";
      try {
          Enumeration&lt;NetworkInterface&gt; enumNetworkInterfaces = NetworkInterface
                  .getNetworkInterfaces();
          while (enumNetworkInterfaces.hasMoreElements()) {
              NetworkInterface networkInterface = enumNetworkInterfaces
                      .nextElement();
              Enumeration&lt;InetAddress&gt; enumInetAddress = networkInterface
                      .getInetAddresses();
              while (enumInetAddress.hasMoreElements()) {
                  InetAddress inetAddress = enumInetAddress
                          .nextElement();
  
                  if (inetAddress.isSiteLocalAddress()) {
                      ip += "Server running at : "
                              + inetAddress.getHostAddress();
                  }
              }
          }
  
      } catch (SocketException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          ip += "Something Wrong! " + e.toString() + "\n";
      }
      return ip;
  }
  }
  </code></pre>