不同网络上的 TcpListener [英] TcpListener on different network

查看:49
本文介绍了不同网络上的 TcpListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到我在另一个网络上创建的 Tcp 服务器,但没有成功.有没有办法做到这一点?

I am trying to connect to a Tcp server I created on another network, I have had no luck. Is there a way to do this?

我需要输入客户端程序的 IP 地址是什么?

What is is the IP Address that i need to put in to the Client program?

如果您在网络上,服务器工作正常,但如果我在不同的网络上,我如何连接?

The server works fine if you are on the network but how do i connect is i am on a different network?

我尝试连接外部 IP 地址,但消息只是在路由器上,我如何让路由器将消息发送到我的 PC?

I have tried to connect with the external IP Address but the message just sat at the router, how do i make the router send the message to my PC?

  • 我做错了什么
  • 我该如何解决

推荐答案

您的 TCP 服务器应该位于具有公共(外部)IP 地址的系统上.这样,即使客户端位于 LAN 内,它们也可以连接到服务器.请注意,LAN 中的 ip 地址与外部 ip 地址不同.转换称为 NAT.

Your TCP server should be on a system with a public(external) ip address. Clients then will be able to connect to the server even if they are inside a LAN. Note that the ip adresses in a LAN are different from external ip-addresses. The translation is called NAT.

因此,因为您的服务器在 LAN 内的计算机上运行,​​因此 Internet 上的其他计算机将无法访问它.另一方面,您的路由器具有可从 Internet 访问的公共 IP 地址.您可以将路由器配置为将端口转发到您的计算机,以便您的路由器将您的服务器与互联网连接起来.请注意,端口转发通常是一种糟糕的安全做法.确保您选择的端口号未被任何其他程序使用.

So because your server runs on a computer inside a LAN it will not be accessible for other computers on the internet. Your router on the other hand has a public ip address which will be accessible from the internet. You can configure your router to forward a port to your computer so that your router connects your server with the internet. Note that port forwarding is often a bad security practice. Make sure that you pick a port number that's not used by any other program.

还要记住,从客户端到服务器的 TCP 流量可能未加密.这意味着您的流量将容易受到中间人攻击.您应该尝试建立使用 SSL 的连接.(注意:SSL 不等于 https)有关更多信息,请查看 OSI 模型.

Also keep in mind that the TCP traffic from the client to the server is probably un-encrypted. This means that your traffic will be vulnerable for man-in-the-middle attacks. You should try to establish an connection which uses SSL. (Note: SSL is not equal to https) For more information please look at the OSI-model.

这篇关于不同网络上的 TcpListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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