tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Enrico Olivelli <eolive...@gmail.com>
Subject Re: java-server-socket-binding-multiple-domain-host-names
Date Sat, 25 May 2013 18:43:45 GMT
If you are using HTTP then clients will politely tell you which DNS name 
they are tryning to connect to using the "host:" header.
TCP does not give any info about "hostnames", but only about "IP Addresses"
I think .getLocalAddress().getHostName() will simply try to resolve back 
the IP address to  a DNS name

I hope that helps
Enrico

Il 25/05/2013 18:23, Elgs Chen ha scritto:
> Hi Mark,
>
> I'm very sorry I know this is not related to the Tomcat project. However, I cannot find
anyone who I think has more expertise in java networking programming than you.
>
> I have a java server socket problem and I have no way to find the answer. I'm really
hoping I can get some insights from you. Thanks in advance.
>
> And here's the URL to this question:
> http://stackoverflow.com/questions/16751062/java-server-socket-binding-multiple-domain-host-names
>
> I have a java nio server with ip address 192.168.0.1 listening on port 80. I configured
this server to bind to multiple domain/host names, let's say server1, server2, server3 are
all resolved as 192.168.0.1.
>
> Now I'm hoping if the client connects to server1, on the server side, I can recognize
that the client is connecting to server1 instead of other names or direct ip address, so that
I can do something special, and if the client is connecting to server2, I can recognize that
the client is requesting server2, so I can do something else special, and so on.
>
> Now the question is: seems on the server side, I cannot easily get the correct information
which server name my clients are connecting to.
>
> I have the follow code:
>
> ServerSocketChannel ssChannel = (ServerSocketChannel) selKey.channel();
> String boundHost = sChannel.socket().getLocalAddress().getHostName();
> But it does not work, the boundHost is always the server1 even if clients connect to
server2 or server3.
>
> Thanks,
> Elgs
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message