C# How to connect a TCPListener (server) behind a router

北慕城南 提交于 2019-12-11 13:57:20

问题


I have a client and server application in two computers. i am trying to connect them through internet TCP connection. the problem im facing is.

Client (192.168.1.2) -> [router] (124.43.224.112) --

-> (internet) -> [router] (124.43.190.63) -> Server (192.168.1.3)

How do i establish a TCP connection ?


回答1:


Internet 101:

  • Network Address Translation http://en.wikipedia.org/wiki/Network_address_translation
  • Port Forwarding http://en.wikipedia.org/wiki/Port_forwarding

The router 124.43.190.63 must be configured to do port forwarding to 192.168.1.3. Client connects to 124.43.190.63.

You must understand these basics if you're writing a networking application.




回答2:


In order for the client to connect to a server that is hidden behind a router you need to setup port forwarding on the server's router. That way when the client attempts to connect to a configured port on the server's router, the request is forwarded onto the server.



来源:https://stackoverflow.com/questions/4111909/c-sharp-how-to-connect-a-tcplistener-server-behind-a-router

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!