Comments (2)
Pasting the code of OnReceiveData also.
I've tried adding code that disposes the socket in multple places to see where it could fall through, but the exceptions always gets caught corrently when I try.
private void OnReceiveData(IAsyncResult asyncResult)
{
var connection = (UdpClient)asyncResult.AsyncState;
try
{
IPEndPoint ep = null;
byte[] receiveBuffer;
try
{
receiveBuffer = connection.EndReceive(asyncResult, ref ep);
}
finally
{
if (connection.Client != null && !_disposing)
{
try
{
// BeginReceive ASAP to enable parallel processing (e.g. query additional data while processing a notification)
connection.BeginReceive(OnReceiveData, connection);
}
catch (Exception ex)
{
Log.Error($"Failed to restart data receive. {ex}");
}
}
}
var receiveBufferHex = ConvertToHex(receiveBuffer);
var receivedLength = receiveBuffer.Length;
if (receivedLength == 0) // Empty frame : port scanner maybe
return;
//verify message
Convert(ep, out var remoteAddress);
if (receivedLength < BVLC.BVLC_HEADER_LENGTH)
{
Log.Warn($"Some garbage data got in: {receiveBufferHex}");
return;
}
// Basic Header lenght
var headerLength = Bvlc.Decode(receiveBuffer, 0, out var function, out var _, ep);
if (headerLength == -1)
{
Log.Warn($"Unknow BVLC Header in: {receiveBufferHex}");
return;
}
switch (function)
{
case BacnetBvlcFunctions.BVLC_RESULT:
// response to BVLC_REGISTER_FOREIGN_DEVICE, could be BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK
// but we are not a BBMD, we don't care
Log.Debug("Receive Register as Foreign Device Response");
break;
case BacnetBvlcFunctions.BVLC_FORWARDED_NPDU:
// BVLC_FORWARDED_NPDU frame by a BBMD, change the remote_address to the original one
// stored in the BVLC header, we don't care about the BBMD address
var ip = ((long) receiveBuffer[7] << 24) + ((long) receiveBuffer[6] << 16) +
((long) receiveBuffer[5] << 8) + receiveBuffer[4];
var port = (receiveBuffer[8] << 8) + receiveBuffer[9]; // 0xbac0 maybe
Convert(new IPEndPoint(ip, port), out remoteAddress);
break;
}
if (function != BacnetBvlcFunctions.BVLC_ORIGINAL_UNICAST_NPDU &&
function != BacnetBvlcFunctions.BVLC_ORIGINAL_BROADCAST_NPDU &&
function != BacnetBvlcFunctions.BVLC_FORWARDED_NPDU)
{
Log.Debug($"{function} - ignoring");
return;
}
if (receivedLength <= headerLength)
{
Log.Warn($"Missing data, only header received: {receiveBufferHex}");
return;
}
InvokeMessageRecieved(receiveBuffer, headerLength, receivedLength - headerLength, remoteAddress);
}
catch (ObjectDisposedException)
{
Log.Debug("Connection has been disposed");
}
catch (Exception e)
{
if (connection.Client == null || _disposing)
return;
Log.Error("Exception in OnRecieveData", e);
}
}
from bacnet.
I might have found the issue. Disassembling the libbacnet.dll we used showed that the code didn't match what was in 1.1.0 and what I pasted here. We where using 1.0.0, where it actually looks like the the exception could be found without being caught.
if finishes like this:
catch (Exception ex)
{
if (asyncState.Client == null)
return;
Trace.TraceError("Exception in Ip OnRecieveData: " + ex.Message);
asyncState.BeginReceive(new AsyncCallback(this.OnReceiveData), (object) asyncState);
}
from bacnet.
Related Issues (20)
- problem with 'shared port' in bacnet ip/udp module HOT 1
- OutOfRangeException when sending big request HOT 3
- Setting up a notification class
- Trouble Publishing Due to Out-Of-Date Dependencies HOT 1
- Throws exception when parsing 'BacnetAddress' structure with broadcast mac address HOT 1
- IndexOutOfRangeException when calling BacnetClient.ReadPropertyResponse
- Setting `.DontFragment` on `UdpClient` on MacOS fails with an exception HOT 1
- SEGMENTATION NOT SUPPORTED WHEN REQUESTING DEVICE WITH MANY OBJECT PROPERTIES HOT 5
- Secure Bacnet (BACnetSC)
- BasicReadAndWrite Example got Nullreference exception when reading Analog input HOT 1
- Is it Possible to Create a BACnet/IP to BACnet/MSTP Router using This Library?
- VS2022 Compile issues with BasicReadWrite Example
- YABE compatibility
- ExceptionSchedule Property - Write
- Notification Class not receiving all notifications in .Net 6.0 Windows/Linux
- Problem in Discovering devices in a network from docker container running in Ubuntu 18 HOT 2
- Decode error when reading PROP_ACTIVE_COV_SUBSCRIPTIONS HOT 2
- False negative address comparison for some BACnet Devices HOT 1
- Error on notification class reception
- Failed to read property PROP_OBJECT_LIST
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bacnet.