问题
I am writing a simple FTP service using TcpListener and would like to find out what hostname (domain with multiple subdomains) the incoming call is using.
Is this possible?
//Barebone TCPListener example
System.Net.Sockets.TcpListener listener;
listener = new TcpListener(IPAddress.Any, 21)
listener.Start();
TcpClient client = listener.AcceptTcpClient();
//Great, incoming... what domain are they using to call my service?
//This only gives me the local and remote IP..
//IPEndPoint LocalEndPoint = (IPEndPoint)client.Client.LocalEndPoint;
//IPEndPoint RemoteEndPoint = (IPEndPoint)client.Client.RemoteEndPoint;
Any pointers greatly appreciated.
回答1:
I don't think TCP fundamentally has that information. That's why HTTP has the "Host" header so clients can specify it.
Essentially, making a TCP connection to a host name is equivalent to resolving the host name into an address, then making the connection as if there'd never been a name.
来源:https://stackoverflow.com/questions/12706901/cannot-retrieve-hostname-calling-my-tcplistener-service