Giter VIP home page Giter VIP logo

Comments (8)

mykah89 avatar mykah89 commented on June 28, 2024 2

I fixed this in my fork awhile ago, sorry for being vague since i dont completely remember, but the best i could gather when i looked into it was that the conn reset was a windows only thing. Hope it helps.

        /// <summary>
        ///   Done to prevent exceptions in Socket.BeginReceive()
        ///   May only be an issue on windows.
        /// </summary>
        /// <remarks>
        ///   http://microsoft.public.win32.programmer.networks.narkive.com/RlxW2V6m/udp-comms-and-connection-reset-problem
        ///   https://stackoverflow.com/questions/34242622/windows-udp-sockets-recvfrom-fails-with-error-10054
        ///   https://stackoverflow.com/questions/38790802/determine-operating-system-in-net-core
        /// </remarks>
        private static void DisableConnReset(UdpClient client)
        {
            if (EnvironmentHelper.IsWindowsEnvironment())
            {
                const uint IOC_IN = 0x80000000;
                const uint IOC_VENDOR = 0x18000000;
                const uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;

                client?.Client.IOControl(unchecked((int)SIO_UDP_CONNRESET),
                    new[] { System.Convert.ToByte(false) }, null);
            }
        }

from bacnet.

minzdrav avatar minzdrav commented on June 28, 2024 2

Hi BACnet libary team
Please reopen issue and integrate fix for DisableConnReset to v2-netstandard branch.
I'm using .net core 3.1. Library working fine on windows 10 + wsl2 + docker and on raspberry pi 4 + ubuntu + docker.
IsOSPlatform is supported by .net core, .net framework, .net standard
https://docs.microsoft.com/en-US/dotnet/api/system.runtime.interopservices.runtimeinformation.isosplatform?view=netcore-3.1

        private static void DisableConnReset(UdpClient client)
        {
            bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
            if (isWindows)
            {
                const uint IOC_IN = 0x80000000;
                const uint IOC_VENDOR = 0x18000000;
                const uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;

                client?.Client.IOControl(unchecked((int)SIO_UDP_CONNRESET),
                    new[] { System.Convert.ToByte(false) }, null);
            }
        }

from bacnet.

pnguyen-ecs avatar pnguyen-ecs commented on June 28, 2024 1

I'm getting the same exception with the same calls as hoangdungt2 on a OSX and Linux Debian. I'm using an ARM processor. The error seems to stem from the following line in the BACnet.dll

client?.Client.IOControl(unchecked((int)SIO_UDP_CONNRESET),
                new[] { System.Convert.ToByte(false) }, null);

from bacnet.

gralin avatar gralin commented on June 28, 2024 1

Hi @minzdrav, you are right this should be integrated with that branch. I will let you know when this is available.

from bacnet.

hoangdungt2 avatar hoangdungt2 commented on June 28, 2024

for my case, it works just fine, when you create bacnet client do not enter ip address in there
var bacnetClient = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));
bacnetClient.start();
I don't use mono, just publish as "linux-arm" and it will work well for rp3, e.g.
dotnet publish -c Release -r linux-arm -o outputFolder

from bacnet.

pnguyen-ecs avatar pnguyen-ecs commented on June 28, 2024

I made the following change to BacnetIpUdpProtocolTransport.cs file of the v2-netstandard branch

line 85
if (_dontFragment) _sharedConn.DontFragment = _dontFragment;

removed line 105

added line 107
if (_dontFragment) _exclusiveConn.DontFragment = _dontFragment;

changed line 139 to

            try
            {
                client?.Client.IOControl(unchecked((int)SIO_UDP_CONNRESET),
                    new[] { System.Convert.ToByte(false) }, null);
            }
            catch (PlatformNotSupportedException ex)
            {
                var socket = new Socket(client.Client.AddressFamily, client.Client.SocketType, client.Client.ProtocolType);
                socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
            }

Note: This will only work if you call BacnetIpUdpProtocolTransport() with dontFragment=false. I don't know much about socket programming but I assume that disabling connection reset is the same as keeping the connection alive.

from bacnet.

JawadJaber avatar JawadJaber commented on June 28, 2024

The solution provided by @mykah89 and @pnguyen-ecs worked for me and no errors appeared.
Many thanks everybody.🙏

from bacnet.

Sn3b avatar Sn3b commented on June 28, 2024

Any idea when this change will be available?

from bacnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.