I was trying to run a .Net socket server code on Win7-64bit machine .
I keep getting the following error:
System.Net.Sockets.SocketException: An address incompatible with the requested protocol
was used.
Error Code: 10047
The code snippet is :
IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
IPEndPoint ip = new IPEndPoint(ipAddress, 9989);
Socket serverSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);
try
{
serverSocket.Bind(ip);
serverSocket.Listen(10);
serverSocket.BeginAccept(new AsyncCallback(AcceptConn), serverSocket);
}
catch (SocketException excep)
{
Log("Native code:"+excep.NativeErrorCode);
// throw;
}
The above code works fine in Win-XP sp3 .
I have checked Error code details on MSDN but it doesn't make much sense to me.
Anyone has encountered similar problems? Any help?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…