I've created a remote desktop control application. Obviously, it consists of client and server parts:

Server:

  • Receiving mouse/keyboard actions from client;
  • Sending screenshot of desktop to client.

Client:

  • Receiving screenshot from server;
  • Sending mouse/keyboard actions;

Consider sending the screenshot. When I use my home PC as a server - I end up with a 1920x1080 screenshot dimension. By using JAI Image I/O Tools and encoding it as PNG I was able to achieve the following stats for such a big image:

  1. Write time ~0.2 s; (not into socket, but into some "regular" output stream, i. e. encode time)
  2. Read time ~0.05 s; (not from socket, but from some "regular" input stream, i. e. decode time)
  3. Size ~250 KB;
  4. Perfect quality.

As a result, according to #1 - the ideal possible FPS should be ~5.

Unfortunately, I'm not able to achieve even those ~5 FPS, not even 2 FPS. I searched for the bottleneck and found out that writing/reading to/from socket I/O streams takes up to ~2 s (See appendix 1 and 2 for clarification). Surely that is unacceptable.

I've researched the topic a bit - and added buffering of socket's I/O streams (with BufferedInputStream and BufferedOutputStream) on both sides. I've started with 64 KB sizes. This indeed improved performance. But still can't have at least 2 FPS! In addition, I've experimented with Socket#setReceiveBufferSize and Socket#setSendBufferSize and there were some changes in speed, but I don't know how exactly they behave, therefore I don't know which values to use.

Look at initialization code:

Server:


                    
                    
                    
Edit
Report