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

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

4

1 回答 1

1

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

一般应使用 IPv4 地址 ( 192.168.72.198)。

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

于 2010-07-02T06:41:34.893 回答