My app currently runs C#, .NET v2.0 on Windows Xp/Windows Server 2003, using
asynchronous socket communication.
I set up my server socket:
Socket s = new Socket( AddressFamily.InterNetwork, SocketType.Stream,
IPEndPoint ep = new IPEndPoint( IPAddress.Any, 0 );
s.Bind( ep );
int port = ep.Port;
The server socket's computer name and port number get stored in a SQL
database and new clients retrieve them to connect as follows:
Socket sClient = new Socket( AddressFamily.InterNetwork, SocketType.Stream,
IPAddress ipAddress = Dns.GetHostEntry( computerName, port ).AddressList;
IPEndPoint ep = new IPEndPoint( ipAddress, port );
sClient.Bind( ep );
When I run the server socket application on the Vista machine and the client
socket application from the XP machine everything works fine.
When I run the server socket application on the XP machine and the client
socket application from the Vista machine everything works fine.
However, when I run both applications from Vista machines, the server socket
gets set up, but when my client tries to connect, I get the following
Error message: An address incompatible with the requested protocol was used
at System.Net.Sockets.Socket.DoBeginConnect( EndPoint endPointShapshot,
SocketAddress socketAddress, LazyAsyncResult asyncResult )
at System.Net.Sockets.Socket.BeginConnect( EndPoint remoteEP,
AsyncCallback callback, Object state )
My googling suggests that the problem stems from Vista by default using
IPv6 socket and the way I have my client socket created resulting in IPv4.
Is there a solution which will work correctly in all three of these
scenarios without switching versions of .NET ?
Thanks in advance,