You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Elgs Chen <el...@hotmail.com> on 2013/05/25 18:23:19 UTC

java-server-socket-binding-multiple-domain-host-names

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


Re: [OT] Re: java-server-socket-binding-multiple-domain-host-names

Posted by Elgs Qian Chen <el...@hotmail.com>.
Thanks Mark. Actually I have problem with Apache2 proxy module when the backend is a wesocket server. I have written my own TCP proxy/port mapper, however, it maps only one client to one server. 

Now I think maybe I have to hack into the http protocol by reading a little bit from a client request, and steal out the server address information. 

Yes, it's up to the DNS to translate the address, not the server itself. Thank you very much. Now I'm clear. 

Best regards,
Elgs

Sent from my iPhone

On May 26, 2013, at 12:33 AM, "Mark Thomas" <ma...@apache.org> wrote:

> On 25/05/2013 17:23, Elgs Chen wrote:
>> Hi Mark,
>> 
>> I'm very sorry I know this is not related to the Tomcat project.
> 
> Then mark the thread as off-topic and use the users mailing list.
> 
>> However, I cannot find anyone who I think has more expertise in java networking programming than you.
> 
> Then you need to get out more. Also, flattery will get you nowhere.
> 
>> 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
> 
> Try reading the perfectly good answer you have already received or,
> better yet, stop and think exactly what it is DNS does.
> 
> Mark
> 
> ---------------------------------------------------------------------
> 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


[OT] Re: java-server-socket-binding-multiple-domain-host-names

Posted by Mark Thomas <ma...@apache.org>.
On 25/05/2013 17:23, Elgs Chen wrote:
> Hi Mark,
> 
> I'm very sorry I know this is not related to the Tomcat project.

Then mark the thread as off-topic and use the users mailing list.

> However, I cannot find anyone who I think has more expertise in java networking programming than you.

Then you need to get out more. Also, flattery will get you nowhere.

> 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

Try reading the perfectly good answer you have already received or,
better yet, stop and think exactly what it is DNS does.

Mark

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


Re: java-server-socket-binding-multiple-domain-host-names

Posted by Elgs Chen <el...@hotmail.com>.
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.
Elgs

On May 26, 2013, at 2:43 AM, Enrico Olivelli <eo...@gmail.com> 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:
>> 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
> 
> 


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


Re: java-server-socket-binding-multiple-domain-host-names

Posted by Enrico Olivelli <eo...@gmail.com>.
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