tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Elgs Chen <>
Subject Re: java-server-socket-binding-multiple-domain-host-names
Date Sat, 25 May 2013 18:52:08 GMT
Yes, .getLocalAddress().getHostName() is not reliable. I don't assume the connection to be
an HTTP connection. Probably I will set a new flag like allowPeep: true to request peeping
into the header information if the users know that they are using HTTP for this connection.
However, I'm afraid it's not possible to peep if the users are using HTTPS.

Thanks for the info, Enrico.

On May 26, 2013, at 2:43 AM, Enrico Olivelli <> wrote:

> 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:
>> I have a java nio server with ip address 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
>> 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);
>> 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:
>> For additional commands, e-mail:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message