TcpClient SocketException .NET
我的电脑配置为自动获取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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在自己的计算机上测试它,可以使用
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.