Return-Path: X-Original-To: apmail-tomcat-dev-archive@www.apache.org Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 44D979133 for ; Sat, 25 May 2013 18:52:43 +0000 (UTC) Received: (qmail 94733 invoked by uid 500); 25 May 2013 18:52:42 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 94521 invoked by uid 500); 25 May 2013 18:52:41 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 94492 invoked by uid 99); 25 May 2013 18:52:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 May 2013 18:52:40 +0000 X-ASF-Spam-Status: No, hits=2.3 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,FSL_HELO_BARE_IP_2,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of elgs1980@hotmail.com designates 65.55.116.101 as permitted sender) Received: from [65.55.116.101] (HELO blu0-omc3-s26.blu0.hotmail.com) (65.55.116.101) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 May 2013 18:52:35 +0000 Received: from BLU0-SMTP330 ([65.55.116.73]) by blu0-omc3-s26.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Sat, 25 May 2013 11:52:14 -0700 X-EIP: [IReq57juLLal78FKEGLM6jwVkY1h/rZ5] X-Originating-Email: [elgs1980@hotmail.com] Message-ID: Received: from 19.36.68.68.client.dyn.strong-sf76.as22781.net ([68.68.36.19]) by BLU0-SMTP330.phx.gbl over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Sat, 25 May 2013 11:52:11 -0700 Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) Subject: Re: java-server-socket-binding-multiple-domain-host-names From: Elgs Chen In-Reply-To: <51A10661.7080407@gmail.com> Date: Sun, 26 May 2013 02:52:08 +0800 Content-Transfer-Encoding: quoted-printable References: <7030EE1367513401-support@support.perfectgonzo.com> <518299E9.8000106@ptc.com> <99C8B2929B39C24493377AC7A121E21FC4ACD59717@USEA-EXCH8.na.uis.unisys.com> <5182A4A4.1090407@apache.org> <51A10661.7080407@gmail.com> To: "Tomcat Developers List" X-Mailer: Apple Mail (2.1503) X-OriginalArrivalTime: 25 May 2013 18:52:11.0588 (UTC) FILETIME=[F709B840:01CE5978] X-Virus-Checked: Checked by ClamAV on apache.org 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 = 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 >=20 > I hope that helps > Enrico >=20 > Il 25/05/2013 18:23, Elgs Chen ha scritto: >> Hi Mark, >>=20 >> 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. >>=20 >> 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. >>=20 >> And here's the URL to this question: >> = http://stackoverflow.com/questions/16751062/java-server-socket-binding-mul= tiple-domain-host-names >>=20 >> 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. >>=20 >> 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. >>=20 >> Now the question is: seems on the server side, I cannot easily get = the correct information which server name my clients are connecting to. >>=20 >> I have the follow code: >>=20 >> ServerSocketChannel ssChannel =3D (ServerSocketChannel) = selKey.channel(); >> String boundHost =3D = sChannel.socket().getLocalAddress().getHostName(); >> But it does not work, the boundHost is always the server1 even if = clients connect to server2 or server3. >>=20 >> Thanks, >> Elgs >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org >> For additional commands, e-mail: dev-help@tomcat.apache.org >>=20 >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org > For additional commands, e-mail: dev-help@tomcat.apache.org >=20 >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org