なぜこの時点でLocalEndpoint = 0.0.0.0ですか?ドキュメントによれば、システムによって選択された適切なアドレスでなければなりません。注:これは一部のマシンでのみ発生します。ほとんどのマシンは私が期待するIPアドレスを返します。これは.NETのバグですか?一部のマシンでC#Socket.LocalEndPointが0.0.0.0を返します
using (Socket s = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp))
{
Console.WriteLine("Connecting");
s.Connect("www.google.com", 80);
Console.WriteLine("Connected OK");
s.Send(new byte[] { 1 });
Console.WriteLine("Sent Byte OK");
Console.WriteLine("Local EndPoint = " +
s.LocalEndPoint.ToString());
}
//Local EndPoint = 0.0.0.0
私はまた、直接ソケットを作成した後
s.Bind(new IPEndPoint(IPAddress.Any, 0));
をやって試してみましたが、それは何の違いが行われていません。 「問題」マシンは常に0.0.0.0を返します。
Media State . . . . . . . . . . . : Media disconnected
Description . . . . . . . . . . . : VIA VT6105 Rhine Fast Ethernet Adapter
Physical Address. . . . . . . . . : 00-30-18-67-A0-EB
イーサネットアダプタローカルエリア接続:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Realtek RTL8029 PCI Ethernet Adapter
Physical Address. . . . . . . . . : 00-C0-DF-E7-C9-5D
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 10.0.0.6
Subnet Mask . . . . . . . . . . . : 255.0.0.0
Default Gateway . . . . . . . . . : 10.0.0.2
DHCP Server . . . . . . . . . . . : 10.0.0.2
DNS Servers . . . . . . . . . . . : 10.0.0.2
Lease Obtained. . . . . . . . . . : Wednesday, May 20, 2009 5:39:06 PM
Lease Expires . . . . . . . . . . : Thursday, May 21, 2009 5:39:06 PM
10.0.0.6ここ
は、ipconfig/allと
Windows IP Configuration
Host Name . . . . . . . . . . . . : andrepc
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Unknown
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
イーサネットアダプタローカルエリア接続2の結果であります結果として私が期待するIPだろうか。
マシンのコマンドコンソールで「ipconfig/all」と入力してみてください。 – ChrisW