无法检索调用我的 TCPListener 服务的主机名 [英] Cannot retrieve hostname calling my TCPListener Service
本文介绍了无法检索调用我的 TCPListener 服务的主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 TcpListener 编写一个简单的 FTP 服务,并想找出传入呼叫使用的主机名(具有多个子域的域).
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.
这可能吗?
//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;
非常感谢任何指点.
推荐答案
我认为 TCP 从根本上拥有这些信息.这就是 HTTP 具有Host"标头以便客户端可以指定它的原因.
I don't think TCP fundamentally has that information. That's why HTTP has the "Host" header so clients can specify it.
本质上,与主机名建立 TCP 连接等同于将主机名解析为地址,然后建立连接,就好像从来没有过名称一样.
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.
这篇关于无法检索调用我的 TCPListener 服务的主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文