'How can data get lost, using sockets from "System.Net.Sockets"?

I'm working on a C# TCP socket based application, based on the technology from the System.Net.Sockets package.

Receiving packets goes as follows:

private void OnReceivedData(IAsyncResult ar)
{
    // Socket was the passed in object
    var sock = (Socket)ar.AsyncState;

    // Check if we got any data
    try
    {
        int nBytesRec = sock.EndReceive(ar);
        ...

When too many data get sent, parts of it are getting lost.

I remember having worked with "Computer Management", "Services and Applications", "Message Queuing", ..., but I don't remember what it was all about.

Does anybody know how I can detect and solve such apparent buffer overflooding situations?

Edit First attempt

I just tried following way to catch the issue:

SocketError socket_ErrorCode;
int nBytesRec = sock.EndReceive(ar, out socket_ErrorCode);
if (socket_ErrorCode != 0)
{
    Log.Error($"Following socket errorcode is found: [{socket_ErrorCode}]");
}

=> Although again some packets were lost, that error was not shown.

Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source