PPP Socket behaviour


We are currently using SoM SC20260E, Ublox Nina W131 Wifi module and Ublox SARA R4 4G module.
We managed to set UART over PPP (Wifi and 4G LTE) successfully and have been testing it for some weeks now.

We connected to our servers without issues and we are sending 1400 bytes of data continously over a TCP Socket on each of the 3 interfaces (native ethernet, 4G and Wifi) and data is sent and received successfully.

However we are seeing some strange behaviour when changing how sockets are managed on the Wifi interface.

Here is the thing, if we leave the socket open indefinitely after connecting, when sending and receiveing data, all data sent and received is fragmented into 536 bytes fragments and a significant delay of about 2.5seconds between those fragments. The same thing happens to all data received from the server

On the other hand, if we open and close the socket after sending and receiveing data, all bytes of data sent and received is not fragmented with almost no delay.

We think it might be related to a socket not being flushed properly by the TinyCLR when leaving it open indefinitely, because it seems that closing the socket on each send-receive makes the data being sent and received properly without fragmenting.
On an additional note, there is no socket Flush property in TinyCLR OS.

Any thoughts on this behaviour?

Have you turned Nagle off? TCP_NODELAY

I have tried disabling Nagle using:

socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);

But an Invalid Operation Exception is thrown by the TinyCLR OS:

Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (15) 
GHIElectronics.TinyCLR.Devices.Network.Provider.NetworkControllerApiWrapper::SetOption [IP: 0000] 
System.Net.Sockets.Socket::SetSocketOption [IP: 008c]
System.Net.Sockets.Socket::SetSocketOption [IP: 000d] 
DashCore.NetworkManager::SendSocket [IP: 004d] 
Exception thrown: 'System.InvalidOperationException' in GHIElectronics.TinyCLR.Devices.Network.dll

I corrected the SocketOptionLevel to TCP and the Invalid Operation Exception is not being thrown.

We checked and data is not being fragmented so Nagle seems to have been disabled properly, yet we see a 10second latency between data being sent and received.

When opening and closing the socket between sends-receive we see a 1second latency compared to 10second latency when leaving the socket open indefinetly.

This is a significant socket latency behaviour between the two.

Is it possible that nagle needs to be turned off in tinyclr and the ublox wi-fi?

I checked the moduleĀ“s datasheet and application notes and there is no mention of nagle whatsoever.

It is very weird that opening-closing the socket changes the socket behaviour only on this module.
I will try to check if there is some configuration that need tuning but I have not much hope.