To start, thanks Joel for your efforts on this repository.
This is more of design question/discussion. I'm porting some code from an old WinForms application to a more modern architecture using Avalonia.
The code being ported was using the TCPListener/TCPClient in it's raw form which proved to just work but wanted a bit more robustness and simplicity with the library.
My current setup is:
GUI frontend that talks with a 'middleware' piece of 'C' software that acts as a mediator between the GUI and a final end point.
GUI front-end that:
Establishes a server service using loopback on a given port. The server is responsible for receiving data from this middleware and displays data as needed (which is transmitted from the end point).
Establishes a client service using loopback on a given port. The client is responsible for taking UI data and sending to middleware which then sends to final end point.
The middleware piece is to remained untouched
The issue I'm running into from legacy software to new implementation is "single" transmits from 'final endpoint -> middleware -> GUI'. I noticed when data is 'set' on the end point and progresses through this line of transmission, my DataReceived function doesn't reliably get the data that is sent from the middleware. I do see it being sent as I have the means to debug it but it always seems like the data gets lost or dropped.
Scenario would be:
Final endpoint pushes a button
End point transmits the data associated w/ button press
Middleware processes
Middleware then relays the data to GUI
However, when data from the middleware sends the data in a periodic fashion, I'm not seeing any issue with receiving it. I'm assuming the periodic nature of this is what's helping.
Any ideas on implementation? I put my DataReceived function below:
private void DataReceived(object? sender, SuperSimpleTcp.DataReceivedEventArgs e)
{
// TODO: This 'message' doesn't always come in.
if (e.Data.Array[4] == 0x08 && e.Data.Array[5] == 0x01 && (e.Data.Array[6] == 0x00 || e.Data.Array[6] == 0x01))
{
Debug.WriteLine("Received My Non-Periodic Message");
}
try
{
byte[]? data = e.Data.Array;
if (data is not null && data.Length > 0)
{
// Convert the first 4 bytes (length of data)
int dataLength = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data, 0));
// Extract the rest of the data
byte[] dataPayload = new byte[dataLength];
Array.Copy(data, 4, dataPayload, 0, dataLength);
ProcessStatusData(dataPayload);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
To start, thanks Joel for your efforts on this repository.
This is more of design question/discussion. I'm porting some code from an old WinForms application to a more modern architecture using Avalonia.
The code being ported was using the TCPListener/TCPClient in it's raw form which proved to just work but wanted a bit more robustness and simplicity with the library.
My current setup is: GUI frontend that talks with a 'middleware' piece of 'C' software that acts as a mediator between the GUI and a final end point.
The issue I'm running into from legacy software to new implementation is "single" transmits from 'final endpoint -> middleware -> GUI'. I noticed when data is 'set' on the end point and progresses through this line of transmission, my
DataReceived
function doesn't reliably get the data that is sent from the middleware. I do see it being sent as I have the means to debug it but it always seems like the data gets lost or dropped.Scenario would be:
However, when data from the middleware sends the data in a periodic fashion, I'm not seeing any issue with receiving it. I'm assuming the periodic nature of this is what's helping.
Any ideas on implementation? I put my
DataReceived
function below: