客户端-服务器 IM 应用程序中外部 IP 上的服务器没有响应

发布于 2024-08-03 12:10:15 字数 1125 浏览 3 评论 0原文

我正在关注教程@ http ://www.geekpedia.com/tutorial239_Csharp-Chat-Part-1---Building-the-Chat-Client.html 尝试收集网络基础知识。对于那些不想立即开始的人来说,这是一个快速演示,演示如何编写一个简单的客户端-服务器模型聊天应用程序。

当我尝试运行图特中的代码时,只要客户端和服务器都在同一网络上,它就可以正常工作,但第二次我尝试在外部执行此操作(让一个伙伴运行客户端应用程序,然后运行我这边的服务器应用程序),这一切都变得很糟糕。代码在同一网络中工作的事实使我相信这不是编码问题,而是我的网络设置方式的问题。

我试图在我的 IP 地址上的端口 21719 上运行服务器,我已打开该端口,但其他人仍然无法连接到我的服务器,根本无法获得任何形式的响应。

用于服务器侦听连接的代码(来自教程)是:

public void StartListening()
        {


            IPAddress ipaLocal = ipAddress; //ipAddress is parsed from txtIP


            tlsClient = new TcpListener(ipaLocal, 21719);


            tlsClient.Start();


            ServRunning = true; //for the running loop

            // Start the new tread that hosts the listener
            thrListener = new Thread(KeepListening);
            thrListener.Start();
        }

现在,教程实际上指出了 IP 地址 ipaLocal = ip 地址;

会导致某些配置出现问题,我开始担心我的配置可能会包含在其中。

那么,有人能为我提供解决方案吗?

谢谢, 山姆

I'm following a tutorial @ http://www.geekpedia.com/tutorial239_Csharp-Chat-Part-1---Building-the-Chat-Client.html to try and gather the basics of networking. For those not wanting to hit the jump, it's a quick tut demonstrating how to program a simple client-server-model chat application.

When I try and run the code in the tut, it works fine as long as both the client and the server are on the same network, but the second I try and do it externally (getting a mate to run the client app, and running the server app my side), it all goes to pot. The fact that the code works when in the same network leads me to believe that it's not a coding issue, but an issue with the way my network is set up.

I'm trying to run the server on my IP address at port 21719, which I have opened, but still other people can't connect to my server, not able to get any form of response at all.

The code (from the tut) that is being used for the server to listen to connections is:

public void StartListening()
        {


            IPAddress ipaLocal = ipAddress; //ipAddress is parsed from txtIP


            tlsClient = new TcpListener(ipaLocal, 21719);


            tlsClient.Start();


            ServRunning = true; //for the running loop

            // Start the new tread that hosts the listener
            thrListener = new Thread(KeepListening);
            thrListener.Start();
        }

Now, the tutorial does actually point out that
IPAddress ipaLocal = ipAddress;

Will cause issues on some configurations, and I'm beginning to fear that my configuration may be included in that.

So, does anyone have any solution for me?

Thanks,
Sam

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

愛放△進行李 2024-08-10 12:10:15

您使用的本地 IP 地址是什么? (ipAddress) 如果是 127.0.0.1,那就不正确(我也不知道它内部是如何工作的,但 Windows 似乎有时会使用魔法)。另外,如果您的本地计算机中有多个网卡,也许端口转发仅设置为转发到其中一个网卡,而您正在使用另一个网卡的 IP?

如果这不是问题,这里有一些通用建议:

  1. 获取 netcat 的副本。它是一个小型网络测试实用程序,其唯一的工作是形成一个简单的 TCP 连接。这将允许您消除代码作为所有这一切中的变量。如果 netcat 可以建立连接,那么您就知道问题出在您的代码上。如果没有,则您已确认这是您的路由器。

  2. 您可以使用 WireShark(或 TShark)来查找 ICMP 数据包。在远程计算机上捕获 ICMP 数据包。如果您从路由器收到“Destination Unreachable”,则您再次证明这是您的路由器。

正如 Spencer 所说,您需要确保在路由器上设置端口转发,以将端口 21719 上传入的所有数据包转发到您的内部计算机。至于具体如何做到这一点,在不知道路由器类型的情况下很难说。

What is the local IP address that you're using? (ipAddress) If it's 127.0.0.1, that's not correct (I don't know how it would work internally either, but Windows seems to use magic from time to time). Also, if you have multiple NICs in your local machine, maybe the port forwarding is only set up to forward to one of them, and you're using the IP of the other?

If that's not the problem, here are a few generic suggestions:

  1. Grab a copy of netcat. It's a small network testing util whose only job is to form a simple TCP connection. That will allow you to eliminate your code as a variable in all this. If netcat can form a connection, then you know the problem is your code. If not, you've confirmed that it's your router.

  2. You can use WireShark (or TShark) to look for ICMP packets. Capture ICMP packets on the remote machine. If you get "Destination Unreachable" from the router, you've again proved that it's your router.

As Spencer said you need to make sure Port Forwarding is setup on your router, to forward all packets that come in on port 21719 to your internal machine. As for exactly how to do that, it's hard to say without knowing what type of router.

走野 2024-08-10 12:10:15

您是否让人使用您的外部(互联网)IP 地址? (请参阅此处。)
您是否对路由器进行了针孔处理,以将所有通信从端口 21719 转发到您的服务器?

Are you having people use your external (internet) IP address? (See yours here.)
Have you pinholed your router to forward all communications from port 21719 to your server?

烧了回忆取暖 2024-08-10 12:10:15

一些提示:

  1. 您使用什么类型的操作系统?请检查防火墙规则的范围和/或配置文件(在“高级”选项卡下)。
  2. 当您的朋友尝试 telnet 到端口(连接到 IM 服务器)时,使用 Wireshark 监视流量或网络监视器 (Wireshark 在 Vista 和 Win 7 上有问题)。如果您没有看到任何东西影响您的计算机,则问题可能出在路由器端。仔细检查设置 - 您说您设置了转发规则(NAT),但它是否也在路由器的防火墙上设置了规则?

Some tips:

  1. What kind of operating system are you using? Please check the Scope and/or Profiles (under Advanced tab) of your firewall rule.
  2. While your friend is trying to telnet to the port (connect to the im server) monitor the traffic using Wireshark or Network Monitor (Wireshark have problems with Vista and Win 7). If you don't see anything hitting your machine the problem is probably on the router side. Double check the settings - you said you set the forward rule (NAT) but did it also set the rule on firewall of your router?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文