By "lagging" I mean that the remote desktop client is running for a few seconds behind the server. What the server does at a certain moment is reflected on the client side after a delay of about 15-20 seconds.
You need to 100% confirm two things.
1) Is the client fread in fread ? If not, then it lags behind because it is too busy to keep up with the server (or the code is broken and foolishly doesn't call fread ). In any case, buffering and the network are not to blame.
2) Did the client receive fewer bytes from completed calls to fread than the server sent its completed calls to fwrite ? If not, then he is “behind” because he misunderstood some of the data he received (he did not understand that he received some data that he received). In this case, buffering and the network are not to blame.
I bet from 10 to 1 that one of the two things that I talked about above is a case.
To clarify two cases, if this is not clear, consider the following example:
1) The server sends a message.
2) The server sends a message.
3) The client calls fread and receives both messages, but due to broken code, only thinks that he received it. (Perhaps a broken code suggests that messages cannot "stick together.")
4) At this stage, it may seem that the client is “behind” the message, but in fact the client code is simply broken. The client read as many bytes as the server sent. He is not far behind, just broke.
Until you exclude these two types of “busy code” and “broken code,” you should not assume that the network is to blame, as this is the least likely explanation.