====== 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 received * filled by ClientWorker with messages from the server * read by GUI thread * contains keystrokes and mouse instructions, they are to be performed * Queue 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 received * filled by ServerWorker with messages from the client * read by GUI thread * contains bitmap tiles to be displayed * Queue 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 ===== * https://msdn.microsoft.com/en-us/library/bew39x2a%28v=vs.110%29.aspx * https://msdn.microsoft.com/en-us/library/fx6588te%28v=vs.110%29.aspx * https://stackoverflow.com/questions/2416748/how-to-simulate-mouse-click-in-c * https://msdn.microsoft.com/en-us/library/ms171548%28v=vs.110%29.aspx * http://ksvi.mff.cuni.cz/~holan/ (Czech) * https://stackoverflow.com/questions/5461338/how-to-create-a-jpg-image-dynamically-in-memory-with-net * https://stackoverflow.com/questions/362986/capture-the-screen-into-a-bitmap * https://msdn.microsoft.com/en-us/library/kb5kfec7%28v=vs.110%29.aspx * https://msdn.microsoft.com/en-us/library/5ey6h79d%28v=vs.110%29.aspx * https://stackoverflow.com/questions/695802/using-ssl-and-sslstream-for-peer-to-peer-authentication * http://blogs.msdn.com/b/joncole/archive/2007/06/13/sample-asynchronous-sslstream-client-server-implementation.aspx * https://msdn.microsoft.com/en-us/library/system.net.security.sslstream.aspx * https://www.sslshopper.com/article-most-common-openssl-commands.html * https://stackoverflow.com/questions/6686356/sslstream-equivelent-of-tcpclient-available