简体   繁体   English

Ruby TCPSocket服务器-我可以告诉客户端连接的主机吗?

[英]Ruby TCPSocket Server - Can I tell to what host a client was connecting?

I have a ruby server based on TCPSocket (non-HTTP). 我有一个基于TCPSocket(非HTTP)的红宝石服务器。

I have 2 different domains, both pointing with an A-Record to my servers IP Address (the same one). 我有2个不同的域,都用A记录指向我的服务器IP地址(同一个)。 So, there are clients connecting to one of those domains. 因此,有些客户端连接到这些域之一。 Is it possible to tell which domain a client was connecting to? 是否可以判断客户端连接到哪个域?

I saw that this is possible in other protocols, but I'm not sure if this is based on manually added headers or really extracted from the basic tcp/ip connection. 我看到这在其他协议中是可行的,但是我不确定这是基于手动添加的标头还是真的从基本tcp / ip连接中提取的。 Eg in PHP there is $_SERVER["HTTP_HOST"] which shows to which domain a client was connecting. 例如在PHP中有$_SERVER["HTTP_HOST"] ,它显示客户$_SERVER["HTTP_HOST"]在连接到哪个域。

At the TCP socket level, the only things that are known are the source and destination IP addresses (and ports) of the connection. 在TCP套接字级别,唯一已知的是连接的源IP地址和目标IP地址(和端口)。 How the IP address was resolved via DNS is not possible to know at this layer. 在这一层无法得知如何通过DNS解析IP地址。 Even though HTTP works on top of TCP, HTTP servers have to look at the HTTP headers from the client to know which domain they are making a request to. 即使HTTP在TCP之上工作,HTTP服务器也必须查看客户端的HTTP标头,以了解它们向哪个域发出请求。 (That's how the HTTP_HOST value gets filled in.) (这就是HTTP_HOST值的填充方式。)

One possible solution is to configure your server to have an additional IP address. 一种可能的解决方案是将服务器配置为具有其他IP地址。 This can be by assigning an additional IP address to the NIC or adding an additional NIC. 这可以通过向NIC分配其他IP地址或添加其他NIC来实现。 Then have each domain use a different IP address. 然后让每个域使用不同的IP地址。 Otherwise, this is not possible and you may want to consider your application protocol on top of TCP to convey this information. 否则,这是不可能的,您可能希望在TCP之上考虑您的应用协议以传达此信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM