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.