ghi-electronics / TinyCLR-Libraries

Official Libraries supporting TinyCLR OS
https://www.ghielectronics.com/tinyclr/
17 stars 16 forks source link

Sending too many TCP messages hangs entire system #1343

Closed TGlev closed 4 months ago

TGlev commented 4 months ago

As discussed over mail, sending too much TCP will hang entire system until TCP connection is dropped. Below is a sample project to reproduce the issue: https://github.com/TGlev/TCPStackGhiTest

Palomino34 commented 4 months ago

could it be same as: #1015, #802 ?

TGlev commented 4 months ago

Can be the same. I will try the workaround.

TGlev commented 4 months ago

This prevents the system from hanging completely. But when opening a putty window, only a first NMEA sentence is received and then nothing more because the poll function will always return false.

Palomino34 commented 4 months ago

If you don't want delay then you can try nodelay, look at // GHI added

public virtual void OpenConnection() {
while (true)
{
    try
    {
        //Wait for a connection
        Socket ClientSocket = Socket.Accept();

        ClientSocket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true); // GHI added

        //If we make it this far, a connection was been established!
        IsConnected = true;

....

We tried and it works fine.

Another way, sender sends message to receiver and wait for the response from that receiver, before sending a new message.