【发布时间】:2015-08-14 05:30:10
【问题描述】:
我一直在尝试设置一个基本场景,其中TcpClient 连接到同一台机器上的TcpListener,但到目前为止它仅适用于127.0.0.1 和192.168.X.Y。这是我的代码:
var server = new TcpListener(IPAddress.Any, 51328);
server.Start();
var client = new TcpClient();
client.ConnectAsync(IPAddress.Parse("address from whatismyip"), 51328);
server.AcceptTcpClient(); // hangs indefinitely here
Console.ReadKey();
我从whatismyip 获得了我的外部地址,但我不确定我是否做得正确。我的程序有问题吗?
【问题讨论】:
-
你正在攻击你的路由器防火墙。您需要端口转发。
标签: c# tcp ip ip-address tcpclient