同一网络上的2台计算机通过互联网相互连接 [英] 2 computers on same network connectnig to each other via internet

查看:143
本文介绍了同一网络上的2台计算机通过互联网相互连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个运行在一种点对点框架中的应用程序。服务器连接到主服务器,然后客户端查询以接收服务器列表。客户端选择服务器并直接连接到该服务器,服务器和客户端都切断与主服务器的连接。


问题:我在一个位置设置了主人,并且它不在路由器或防火墙之后或任何东西,只是直接连接到互联网。我在一个单独的位置(也是单独的互联网连接)在同一网络上的服务器和客户端计算机。两者都可以很好地连接到主人。与客户端保持TCP连接,而UDP数据包定期发送到客户端和服务器。 TCP连接很好,UDP数据包总是由同一台计算机接收,并且总是不被另一台计算机接收(无论哪一台是服务器,哪一台是客户机)。但是,当尝试客户端和服务器之间的直接(TCP)连接时,它不起作用:强制拒绝连接。错误信息。应用程序使用的标准端口在路由器上为TCP和UDP打开。我的想法是,虽然这些端口设置为转发到路由器设置中的两台计算机,但只有一台计算机接收由MS发出的UDP数据包,所以我想知道是否只有一台计算机正在接收必要的TCP数据包建立连接。


注意:如果我在路由器后面的网络上运行主服务器并尝试从直接连接到互联网的计算机连接到它(作为服务器或客户端)连接正常(我还没有测试过不同网络上的计算机的服务器 - 客户端连接)。当masterserver在与服务器和客户端相同的网络上运行并且本地地址(192.168.x.x)用于主服务器时,一切都运行良好。在使用非本地IP的情况下,计算机既不能作为服务器也不是客户端连接到主服务器。


我真的很感激这个问题的任何帮助,因为该应用程序旨在支持同一网络上的两台计算机通过外部主服务器相互连接。

问候,

AJ


PS如果有帮助,路由器是Open Networks。

I have written an application that runs in a kind of peer-to-peer framework. Servers connect to a masterserver, which a client then queries to receive a list of servers. The client selects a server and connects to that server directly and both the server and client sever their connections with the masterserver.

Problem: I have the masterserver set up at a location and it is not behind a router or firewall or anything, just directly connected to the internet. I have in a separate location (separate internet connection, too) a server and a client computer on the same network. Both can connect to the masterserver fine. A TCP connection is maintained with clients whilst UDP packets are sent out periodically to both clients and servers. The TCP connection is fine and the UDP packets are always received by the same computer, and always not received by the other one (regardless of which one is the server and which one is the client). When the direct (TCP) connection between the client and server is attempted, however, it doesn''t work: "Connection forcefully refused" error message. The standard ports that the application uses are opened for both TCP and UDP on the router. My thoughts are that whilst these ports are set to forward to both computers in the router setup, only one computer receives the UDP packets sent out by the MS and so I''m wondering if the perhaps only one computer is receiving the TCP packets necessary to establish a connection as well.

Notes: If I run the masterserver on the network behind the router and try to connect to it (as either server or client) from the computer directly connected to the internet the connection is fine (I haven''t tested the server-client connection from computers on different networks yet). When the masterserver is run on the same network as the server and client and a local address (192.168.x.x) is used for the masterserver everything works perfectly. In the same situation when a non-local IP is used neither computer can connect to the masterserver as either server or client.

I would really appreciate any help on this issue since the application is meant to support two computers on the same network connecting to each other via the external masterserver.

Regards,
AJ

P.S. The router is Open Networks in case that helps.

推荐答案

听起来其中一台机器无法访问(永远不会收到任何UDP数据包的机器)。 />

您可以共享三台计算机所在的子网。请包括实际的IP地址子网,以及在互联网上公开解决这些子网所需的子网。这是为了确定是否正在与其他机器(客户端/服务器等)共享正确的地址。


如果您对公开分享这些内容感到不舒服,请随时与我联系信息。
It sounds like one of the machines is not accessible (the one that never receives any UDP packets).

Can you share which subnets the three machines are on. Please include the actual IP address subnets, as well as those which are needed to address them publicly across the internet. This is for working out whether the correct addresses are being shared with the other machines (client/ server etc).

If you are uncomfortable sharing these publicly then please feel free to PM me with the information.


感谢你的建议NeoPa。


好​​的,问题的更新:

事实证明,你不能将同一个端口转发到多台计算机。

我通过允许用户指定他们的机器用于通信的哪个端口

解决了这个问题,然后转发

适当的端口。


所以现在所有情况下的所有计算机都可以通过TCP正确地与主服务器进行
和UDP通信。当客户端尝试连接到同一台路由器后面的服务器时(即使服务器是与客户端在同一台计算机上运行的
),我收到

强制拒绝连接信息。所以事情已经取得了进展,但还没有完成。


我调试了服务器应用程序并且可以确认它

从未收到来自客户端计算机的任何连接请求,

so我认为问题再次出现在路由器设置上。

另外,如果我运行netstat -a,我可以看到服务器在正确的端口上侦听

TCP连接。当路由器不是
时,一切都按预期工作。


另外,如果主服务器被移到路由器后面,那么同一路由器后面的计算机无法连接到它。有可能

计算机在同一个路由器后面无法使用外部IP建立连接到

吗?


谢谢再次对这个新问题的任何帮助,

AJ
Thanks for your suggestion NeoPa.

OK, an update on the problem:
It turns out that you can''t forward the same port to multiple computers.
I solved this problem by allowing the user to specify which port
their machine uses for communication and then forwarding the
appropriate ports.

So now all computers in all situations can communicate via TCP
and UDP correctly with the masterserver. When a client tries to
connect to a server behind the same router (even if the server is
running on the same computer as the client), however, I receive
the "Connection forcefully refused" message. So things have
progressed but are not quite there yet.

I have debugged the server application and can confirm that it
never receives any connection request from the client computer,
so I presume the problem is once again with the router setup.
Also, if I run "netstat -a" I can see the server listening for a
TCP connection on the correct port. When the router is not
present everything works as intended.

Also, if the masterserver is moved behind the router, computers
behind the same router cannot connect to it. Is it possible that
computers behind the same router cannot establish a connection to
each other using the external IP?

Thanks again for any help with this new issue,
AJ


让我们确定它是否都发生在防火墙(路由器)中,正如我所怀疑的那样。


尝试全部设置,然后关闭通常报告连接强制关闭的机器(我的意思是你的客户端PC正试图连接)。


如果在机器电源关闭时收到相同的消息,那么您可以相当确定错误消息来自防火墙。
Let''s determine if it is all happening in the firewall (router), as I suspect.

Try setting it all up, then turning off the machine that normally reports the connection is forcefully closed (I mean one your client PC is trying to connect to).

If you get the same message when the machine is powered off, then you can be fairly sure the error message is originating from the firewall.


这篇关于同一网络上的2台计算机通过互联网相互连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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