Cannot retrieve hostname calling my TCPListener Service

孤者浪人 提交于 2019-12-13 03:59:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!