在同一Intranet上区分两台计算机 [英] Differentiating Between Two Computers On The Same Intranet

查看:56
本文介绍了在同一Intranet上区分两台计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个套接字"Hello World"程序.

I am trying to create a Socket "Hello World" program.

理想情况下,我想创建两个可以对等交换简单文本的程序.

I would ideally like to create two programs who can exchange simple text, peer-to-peer.

我可以创建一个Web服务,对等方可以将其IP地址发布到该服务.

I can create a webservice that the peers can post their IP Address to.

然后,一个对等方可以选择另一个与之配对.

One peer can then select another to pair up with.

如果一个同龄人是我的台式计算机,另一个是我的笔记本电脑,我该如何区分这两个?

If one of the peers is my desktop computer, and the other is my laptop, how can I differentiate the two?

推荐答案

首先.如果所有这些都在您的本地网络上,而没有任何NAT网关或类似地址-没什么大不了的.您的服务器将看到具有不同IP地址的客户端,并且客户端可以直接彼此连接.

First of all. If all this is on your local network, without any NAT gateways or similar - it's no big deal. Your server will see your clients with different IP addresses, and the clients can connect directly to each other.

另一方面,如果您的服务器在可访问Internet的IP地址上运行,并且您的客户端从他们可以访问该服务器的任何地方进行连接,则您必须考虑本文的其余部分.

On the other hand, if your server runs on an internet reachable IP address, and your clients connect from wherever they can reach that server you will have to consider the rest of this post.

客户端A连接到您的服务器.现在之间存在联系: (ClientAIP:ClientAPort,ServerIP:ServerPort)

Client A connects to your server. There's now a connection between: (ClientAIP:ClientAPort,ServerIP:ServerPort)

客户端B连接到您的服务器.现在之间存在联系: (ClientBIP:ClientBPort,ServerIP:ServerPort)

Client B connects to to your server. There's now a connection between: (ClientBIP:ClientBPort,ServerIP:ServerPort)

如果两个客户都位于同一个 NAT 网关中,则服务器将看到ClientAIP == ClientBIP. 但是ClientAPort将不同于ClientBPort.这足以保持与服务器的两个连接.

If both your clients are behind the same NAT'ed gatway, the server will see ClientAIP == ClientBIP. But ClientAPort will be different from ClientBPort. And that's enough to to keeep up two connections to your server.

现在,如果您想将两个配对,麻烦就来了.让客户端向您发送其内部IP地址(也许也向其发送内部端口,以便将其用于额外的验证.)

Now the trouble comes if you want to pair two of them. Have the clients send you its internal IP address(And perhaps its internal port too so that could be used for extra verification.)

您现在知道客户端(外部)IP及其内部IP. 这些是方案:

You now know the clients (external) IP and their internal IP. These will be the scenarios:

  1. ClientAInternalIP == ClientAIP,ClientBinternalIP == ClientBIP.太好了,都不在NAT网关的后面-选择其中一个作为服务器,再选择另一个直接连接到服务器.

  1. ClientAInternalIP == ClientAIP, ClientBinternalIP == ClientBIP. Great neither are behind a NAT gateway - select one of them to be a server and the other one to connect directly to it.

ClientAInternalIP!= ClientAIP,ClientBinternalIP == ClientBIP. ClientA在NAT之后,ClientB在NAT之后.让ClientB成为服务器,让ClientA直接连接到ClientB

ClientAInternalIP != ClientAIP, ClientBinternalIP == ClientBIP. ClientA is behind NAT, ClientB is not. Have ClientB be a server and ClientA connect diectly to ClientB

ClientAInternalIP == ClientAIP,ClientBinternalIP!= ClientBIP.相反的情况2).

ClientAInternalIP == ClientAIP, ClientBinternalIP != ClientBIP. Just the reverse case 2).

ClientAInternalIP!= ClientAIP,ClientBinternalIP!= ClientBIP,但是ClientAIP == ClientBIP.特殊情况-它们都在NAT网关后面,但是它们在同一个内部网络中.这与情况1)相同.除了客户可以在其内部网络而不是Internet上进行通信.

ClientAInternalIP != ClientAIP, ClientBinternalIP != ClientBIP, but ClientAIP == ClientBIP . Special case - they're both behind a NAT gateway but they're on the same internal network. This is the same as case 1). Except the clients can communicate on their internal network instead of the internet.

ClientAInternalIP!= ClientAIP,ClientBinternalIP!= ClientBIP.两者都在NAT网关后面. -您无法建立彼此的连接-至少要让某人在客户端的网关之一上设置端口转发.您必须通过服务器路由通信. (尽管有一些提供API的路由器/网关,您可能可以使用它们以编程方式从客户端站点打开端口转发.它并不广泛可用,而且无论如何都可能被锁定).

ClientAInternalIP != ClientAIP, ClientBinternalIP != ClientBIP. Both are behind NAT gatways. -You can't have the connect to eachother - atleast not without asking someone to set up port forwarding on one of the gateways at the client. You'll have to route the communication through your server. (Though there are routers/gateways providing APIs you might be able to use to programatically open port forwarding from a client site. It's not widely available and probably locked down anyways).

即使在上述情况下,也可能会设置防火墙,即使客户端的真实IP地址可以在Internet上路由,也无法直接对等访问-您可能仍然需要通过服务器进行路由.

And even with the above scenarios there might be firewalls set up so clients can't peer directly even if their real IP address is routable on the internet - you might need to fall back to routing through your server anyway.

这篇关于在同一Intranet上区分两台计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆