Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDPReceiver Exception on WinDesktop #55

Closed
usasos000 opened this issue Jan 6, 2016 · 3 comments
Closed

UDPReceiver Exception on WinDesktop #55

usasos000 opened this issue Jan 6, 2016 · 3 comments

Comments

@usasos000
Copy link

when I started UDPReceiver,and remote close udp port,then I get an Exception
An existing connection was forcibly closed by the remote host
sadly,I can`t catch this exception at anywhere,and if it shows that the Receiver will done,
but i need the Receiver alive,
to fix it I searched at google,it says
var udpClient = new UdpClient();
uint IOC_IN = 0x80000000;
uint IOC_VENDOR = 0x18000000;
uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
udpClient.Client.IOControl((int)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null);

So,I changed the source code and re-compile it,
Problem solved

At UdpSocketReveiver.cs

public Task StartListeningAsync(int port = 0, ICommsInterface listenOn = null)
{
if (listenOn != null && !listenOn.IsUsable)
throw new InvalidOperationException("Cannot listen on an unusable interface. Check the IsUsable property before attemping to bind.");

        return Task.Run(() =>
        {
            var ip = listenOn != null ? ((CommsInterface)listenOn).NativeIpAddress : IPAddress.Any;
            var ep = new IPEndPoint(ip, port);

            _messageCanceller = new CancellationTokenSource();
            _backingUdpClient = new UdpClient(ep)
            {
                EnableBroadcast = true
            };
            uint IOC_IN = 0x80000000;
            uint IOC_VENDOR = 0x18000000;
            uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12; 
            _backingUdpClient.Client.IOControl((int)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null);
            RunMessageReceiver(_messageCanceller.Token);
        });
    }
@rdavisau
Copy link
Owner

rdavisau commented Jan 6, 2016

Howdy,

Interesting to see because in 'theory' UDP is stateless and connectionless!
I'm confused by it but not exactly surprised that their might be something obscure like this.

Can you share the link to resources that gave you that solution? If I understand better what it is doing I can decide how to include it.

Thanks! 👍

@usasos000
Copy link
Author

http://stackoverflow.com/questions/7201862/an-existing-connection-was-forcibly-closed-by-the-remote-host
very glad to help u to improve the Plugin,this is the link I found,
The exception will occur when
1.use other tools to Start listen UDP port at local,
2.Use UDPReceiver start a UDP port and send msg to 1 local port
3.Close 1 local port,
It`s very weird that for UDP.
May this info could help u,thanks

@rdavisau
Copy link
Owner

I've implemented the solution you researched, so this will be enabled in the next release. Pretty crazy error!

Thanks again! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants