title: Get a domain from Socket
body: <p>I am trying to get the domain a user is connection to (e.g. test.somesite.com) from a Socket, is this possible? The reason I would like this is to redirect users based on where they came from. I get the socket from running serverSocket.accept() in another thread</p>
  
  <p>I have tried:</p>
  
  <pre><code>clientSocket.getLocalAddress().getHostAddress();
  clientSocket.getHostAddress().toString();
  </code></pre>
  
  <p>They both just print my own local/internal IP address. How can I get the domain they came through from that?</p>
  
  <p>Edit: I think this could be possible because for example, in an Apache web server you can do this in your httpd.conf file:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
    ServerName something.something.com
    ProxyPass               /       http://localhost:8080/
    ProxyPassReverse        /       http://localhost:8080/
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>This will listen on port 80, check if the url they came from is something.something.com, and if it is it will redirect to port 80. Maybe I am completely wrong because I'm new to networking in Java but please let me know if you have any hints, even if I have to rewrite my code its fine.</p>
  
  <p>Edit 2: I found out this is impossible because the target application resolves the domain name to an IP address before it connects. Thanks for all your help though</p>
  
  <p>Keir</p>