TcpClient SocketException .NET

发布于 2024-09-07 13:33:44 字数 1286 浏览 1 评论 0原文

我的电脑配置为自动获取IP地址。当我使用ipconfig /all时,它显示如下所示:

Windows IP Configuration

PPP adapter Broadband Connection:

Connection-specific DNS Suffix . :
IPv4 Address. . . . . . . . . . . : 95.38.95.204
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 0.0.0.0

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::64d7:e4ee:ba7e:1ede
IPv4 Address. . . . . . . . . . . : 192.168.72.198
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1

我应该使用95.38.95.204还是192.168.72.198作为服务器的IP地址,客户?

当我使用 192.168.72.198 时,服务器连接成功,但客户端抛出 SocketException ,如下所示

 var tcpServer = new TcpClient();
 tcpServer.Connect(new IpAddress("192.168.72.198"), 1986);

连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应 192.168.72.198:1986

我在 geekpedia 上使用了这篇文章 http://www.geekpedia.com/tutorial239_Csharp-Chat-Part-1 ---Building-the-Chat-Client.html

如果有人可以帮助我,谢谢。

My computer is configured to automatically obtain IP address. When I use ipconfig /all, it shows something like below:

Windows IP Configuration

PPP adapter Broadband Connection:

Connection-specific DNS Suffix . :
IPv4 Address. . . . . . . . . . . : 95.38.95.204
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 0.0.0.0

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::64d7:e4ee:ba7e:1ede
IPv4 Address. . . . . . . . . . . : 192.168.72.198
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1

Should I use 95.38.95.204 or 192.168.72.198 as IP address for server and client?

When I used 192.168.72.198, server connected successfully but client threw an SocketException like below

 var tcpServer = new TcpClient();
 tcpServer.Connect(new IpAddress("192.168.72.198"), 1986);

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.72.198:1986

I used this articles on geekpedia at http://www.geekpedia.com/tutorial239_Csharp-Chat-Part-1---Building-the-Chat-Client.html

Thanks if anybody can help me.

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

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

发布评论

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

评论(1

肤浅与狂妄 2024-09-14 13:33:44

如果您在自己的计算机上测试它,可以使用 127.0.0.1"localhost"

通常您应该使用 IPv4 地址 (192.168.72.198)。

听起来您的服务器尚未在该套接字上运行。

If you are testing it on your own computer you can use 127.0.0.1 or "localhost".

You should use the IPv4 address generally (192.168.72.198).

It sounds like you don't have your server already running on that socket.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文