Java Server - Is it possible to get the hostname used by the Client to connect?

StackOverflow https://stackoverflow.com/questions/18942294

  •  29-06-2022
  •  | 
  •  

Вопрос

When a Client makes a connection to your Server, is it possible to determine the hostname they used to connect to it? For example, if both entry1.domain.com and entry2.domain.com point to the same IP (your server), and a Client uses one to connect to your server are you able to differentiate between which hostname was used to make the socket connection?

Это было полезно?

Решение

Normally the client sends the host name desired to the server. E.g. this is what HTTP does. You can send data you want over TCP. i.e. you can send the desired host name.

Another approach is to use multiple IP addresses for the same host and bind to different IP addresses in Java. This way you know which address was used assuming it is unique.

Другие советы

Not from a pure TCP connection. You can get the IP address, but you can't know what hostname the client used to get that IP address.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top