Program architecture

Client

Reads keystrokes from server. Creates screenshots, detects changes in them and sends changed tiles (128x128px by default) to the server.

Two threads: GUI thread and ClientWorker, communicating with queues.

  • Queue<byte[]> received
    • filled by ClientWorker with messages from the server
    • read by GUI thread
    • contains keystrokes and mouse instructions, they are to be performed
  • Queue<byte[]> tosend
    • filled by GUI thread
    • read by ClientWorker, the messages are sent to server
    • contains bitmap tiles to be sent to the server

ClientWorker thread:

  • perform SSL handshake
  • enter an infinite loop:
    • send data from “tosend” queue
    • if some data in socket are available, put them to “received” queue

GUI thread:

  • on timer1.tick():
    • if some data (keystrokes or mouse instructions) are available in the “received” queue, process them
    • if “tosend” queue is empty (this is to prevent network congestion)
      • create screenshot
      • break it to 128x128px tiles
      • compare with previous screenshot
      • add changed tiles to “tosend” queue

Server

Displays tiles received from client. Forwards KeyPress and MouseClick events to the client.

Two threads: GUI thread and ServerWorker, communicating with queues.

  • Queue<byte[]> received
    • filled by ServerWorker with messages from the client
    • read by GUI thread
    • contains bitmap tiles to be displayed
  • Queue<byte[]> tosend
    • filled by GUI thread
    • read by ServerWorker, the messages are sent to client
    • contains keystrokes and mouse instructions

ServerWorker thread:

  • listen on socket, perform SSL handshake
  • read data from socket asynchronously, put them to “readData” queue
  • enter infinite loop:
    • read “readData” queue, put messages to “received” queue
    • if “tosend” queue is not empty, send data from it to client

GUI thread:

  • on timer1.tick():
    • get tiles from “received” queue, display them in picturebox
  • on MouseUp, MouseDown or KeyPress:
    • add the event to “tosend” queue

Protocol specification

Datagram format: 4B magic value “0x95400954”, 4B length, 4B type, lengthB-4 payload

Message type 0x02: Client -> Server Rectangle

payload: 2B format, 2B xstart, 2B ystart, 2B width, 2B height, data

format: 0x1 = JPEG

Contains image data to be displayed.

Message type 0x01: Server -> Client Hello

payload: nothing

Message type 0x02: Server -> Client Mouse Event

payload: 2B X, 2B Y, 4B flags

Message type 0x03: Server -> Client Text Input (type 0x3)

payload: text to be typed on the keyboard

Message type 0x04: Server -> Client Force Redraw (type 0x4)

payload: nothing

Forces client to resend all tiles again.

Sources used

 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki