无法检索调用我的TCPListener服务的主机名

时间:2012-10-03 10:48:29

标签: c# windows-services tcplistener

我正在使用TcpListener编写一个简单的FTP服务,并希望找出传入呼叫正在使用的主机名(具有多个子域的域)。

这可能吗?

//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;

任何指针都非常感激。

1 个答案:

答案 0 :(得分:3)

我认为TCP从根本上没有那些信息。这就是为什么HTTP具有“主机”标头,以便客户端可以指定它。

基本上,建立与主机名的TCP连接相当于将主机名解析为一个地址,然后使连接好像从来没有 一个名称。