0
我正在使用TcpListener編寫一個簡單的FTP服務,並想知道來電正在使用的主機名(具有多個子域的域)。無法檢索調用我的TCPListener服務的主機名
這可能嗎?
//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;
任何指針非常讚賞。
那麼關於主機名的信息在途中會丟失? –
@ThomasC:在步驟1中丟失了「將主機名解析爲地址」,步驟2是「連接到地址」。因此,在* TCP *級別,信息消失了。我相信一些FTP服務器支持一個非標準的「主機」頭文件,所以你可以在服務器代碼中做*,但它不是'TcpClient'的一部分。它在更高級別的協議中。 –
解決方案是使用Socket而不是TCP嗎? –