Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista General Discussion > Socket problem migrating to Vista

Reply
Thread Tools Display Modes

Socket problem migrating to Vista

 
 
Valerie Hough
Guest
Posts: n/a

 
      09-24-2007
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,
ProtocolType.Tcp );
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,
ProtocolType.Tcp );
IPAddress ipAddress = Dns.GetHostEntry( computerName, port ).AddressList[0];
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
exception:

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 )
at MySocketClass.Sockets.Connect()

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,
Chris Hough


 
Reply With Quote
 
 
 
 
Andrew McLaren
Guest
Posts: n/a

 
      09-24-2007
"Valerie Hough" <> wrote ...
> 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
> exception:
> Error message: An address incompatible with the requested protocol was
> used


Hi Chris,

You need to create the socket as a IPv6 Socket:

Socket s = new Socket( AddressFamily.InterNetwork, ... etc ... );

and set the IPV6_V6ONLY Socket option to FALSE:

sock.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, 0);

In Vista and Server 2008, the TCP/IP stack will create IPv6 Sockets, by
default. To make them accept IPv4 comms, you need to configure them as "dual
mode" sockets, IPv6 *and&* IPv4. Your socket will always be IPv6 in its
heart-of-hearts; but with IPV6_V6ONLY turned off, it will handle IPv4 stuff
as well.

There's a great article describing this in more detail (helped me to
understand it, at last):
http://blogs.msdn.com/wndp/archive/2...e-sockets.aspx

Hope it helps,

--
Andrew McLaren
amclar (at) optusnet dot com dot au


 
Reply With Quote
 
Valerie Hough
Guest
Posts: n/a

 
      09-24-2007
Thanks for the reply. I was hoping to have code that would run both under
Vista as well as on older machines that did not have support for IPv6
Sockets. When I tried to use this article's approach for an older machine,
the socket did not get created.

One approach I considered was to use Try/Catch while trying to create a v6
socket, and then when this failed use my old approach, but this does not
seem to be a very robust solution.

Does anyone have any other thoughts?

Thanks in advance,
Chris Hough


 
Reply With Quote
 
Andrew McLaren
Guest
Posts: n/a

 
      09-24-2007
"Valerie Hough" <> wrote...
> I was hoping to have code that would run both under Vista as well as on
> older machines that did not have support for IPv6 Sockets. When I tried to
> use this article's approach for an older machine, the socket did not get
> created.


Maybe use System.Environment.OSVersion?

See:
How to determine the Windows version by using Visual C#
http://support.microsoft.com/kb/304283

Then put your Socket creation code in a conditional wrapper:

if (osInfo.Version.Major => 6)
// make an IPv6 sockets
else
// make an IPv4 Socket

For developer questions, you may get better results on groups like
microsoft.public.dotnet.languages.csharp or
microsoft.public.dotnet.framework. Even if it is a Vista-specific question,
very few developers are active in this
microsoft.public.windows.vista.general newsgroup.

Good luck with it!

(btw, Chris ... from here, you sure do look like Valerie, dude!
--
Andrew McLaren
amclar (at) optusnet dot com dot au


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Migrating from a Windows Me PC to a Vista PC Pravda Windows Vista General Discussion 2 01-25-2008 04:28 PM
Memory configurations in socket?2x256 socket 1/3 and 2x512 socket GT Windows Vista Hardware 1 11-25-2007 05:18 AM
Migrating programs to Vista Bob Newman Windows Vista General Discussion 3 10-09-2007 01:57 AM
Migrating Favorites from XP to Vista Michael R. Rojik Windows Vista General Discussion 7 02-25-2007 07:45 PM
Migrating Your Data From XP To Vista awolfe Windows Vista General Discussion 1 01-13-2007 09:25 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59