Winsock 2.0 将无法连接到公共 IP 地址
所以我正在尝试构建一个简单的文本 IM 程序来进入奇妙的网络世界。我使用 Winsock 2.0 和 C++ 编写了 2 个程序:服务器和客户端。我已通过套接字创建指定了 UDP 连接:
SOCKET Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
当我尝试使用本地 IP 地址连接到服务器时,一切正常。但是,当我使用我的互联网 IP 地址时,它将无法连接。我相当确定这不是防火墙问题,因为我在禁用防火墙和防病毒软件的情况下进行了多次测试。我有什么遗漏的吗?你能想到为什么它能够通过本地地址连接但不能通过公共IP地址连接的任何其他原因吗?非常感谢!
So I am trying to build a simple text IM program to get into the wonderful world of networking. I have written 2 programs using Winsock 2.0 with C++: a server and a client. I have specified a UDP connection via the socket creation:
SOCKET Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
Everything works when I try to connect to the server using my local IP address. However, It will not connect when I use my internet IP address. I am fairly certain that it is NOT a firewall issue, because I did multiple tests with both my firewall and antivirus disabled. Is there something I am missing? Can you think of any other reasons why it would be able to connect via the local address, but not the public IP address? Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您拥有的公共 IP 地址很可能归您的网络路由器设备所有。需要将其配置为将流量传递到您的计算机
http://portforward.com/
Most likely the public IP address you have is owned by your network router appliance. It needs to be configured to pass traffic onto your computer
http://portforward.com/