> Since I found out about the IOControl call with SIO_UDP_CONNRESET the
> problem is gone (no more silly exceptions that I don't care about with
> UDP!). I've successfully used that on W2K and XP so far.
Max, thanks a lot for the solution.
By the way how did you set SIO_UDP_CONNRESET to FALSE?
I have tried doing as per Zupancic's suggestion
(http://blog.devstone.com/aaron/archive/2005/02/20.aspx):
// 0x9800000C == 2440136844 (uint) == -174483042 (int) == 0x9800000C
const int SIO_UDP_CONNRESET = -174483042;
byte[] inValue = new byte[] { 0, 0, 0, 0 }; // == false
byte[] outValue = new byte[] { 0, 0, 0, 0 }; // initialize to 0
_socket.IOControl(SIO_UDP_CONNRESET, inValue, outValue);
But it does not work for me - it throws a SocketException (An invalid
argument was supplied).
The code illustrated in http://thedotnet.com/nntp/8375/showpost.aspx
does not work for me either.
By the way I am currently on .NET1.1/VS2003.
Even if I had been on .NET2.0 I guess the new method
Socket.IOControl(IOControlCode, Byte[], Byte[]) wouldn't have helped
me...I couldn't find the equivalent for SIO_UDP_CONNRESET in
IOControlCode enum
(http://msdn2.microsoft.com/en-us/library/system.net.sockets.iocontrolcode.aspx)
Jonas Hei - 22 Jun 2006 18:48 GMT
> I have tried doing as per Zupancic's suggestion
> (http://blog.devstone.com/aaron/archive/2005/02/20.aspx):
[quoted text clipped - 6 lines]
> But it does not work for me - it throws a SocketException (An invalid
> argument was supplied).
Zupancic was just telling us that it is kind of lame to copy and paste
code snippets from anywhere without giving them a serious thought first.
So after being lame for a few hours (give or take a few more hours), I
finally gave some thought to it and luckily managed to solve the problem:
instead of
// 0x9800000C == 2440136844 (uint) == -174483042 (int) == 0x9800000C
we need
// 0x9800000C == 2550136844 (uint) == -1744830452 (int) == 0x9800000C
so this snippet seems to work:
const int SIO_UDP_CONNRESET = -1744830452;
byte[] inValue = new byte[] { 0, 0, 0, 0 }; // == false
byte[] outValue = new byte[] { 0, 0, 0, 0 }; // initialize to 0
_socket.IOControl(SIO_UDP_CONNRESET, inValue, outValue);
Markus Stoeger - 22 Jun 2006 20:39 GMT
> Zupancic was just telling us that it is kind of lame to copy and paste
> code snippets from anywhere without giving them a serious thought first.
[quoted text clipped - 12 lines]
> byte[] outValue = new byte[] { 0, 0, 0, 0 }; // initialize to 0
> _socket.IOControl(SIO_UDP_CONNRESET, inValue, outValue);
I used the following code... looks clean to me. I don't think it's
necessary to pass arrays of 4 bytes. 1 byte is enough. And the second
array can be null because we don't need the return values:
uint IOC_IN = 0x80000000;
uint IOC_VENDOR = 0x18000000;
uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
s.IOControl((int)SIO_UDP_CONNRESET, new byte[] {Convert.ToByte(false)},
null);
Max