Remote Workstation Control

From Bauman National Library
This page was last modified on 22 December 2015, at 09:19.

This article focuses on software product that provides remote management workstation on the LAN. Considered the software implemented in C# programming language.

Relevance of work

Now use of the programs providing connection to remote workstations is actual. It is convenient to use such programs for distant work, for example, from the house for connection in office and vice versa — for access to the home PC, for system administration of the whole park of computers and servers. They also found broad application in many companies which are engaged in development of any software. With the help ON for remote connection of the company provide the customers with the help with work and setup of the software product provided by them.

Structure of the software product

The developed software product consists of two parts: server application and client application.

Server application

Tasks of the server application

The server application solves the following problems:

  • Maintaining log.
  • Registration of the new client in system.
  • Authentication and authorization of users.
  • Data exchange with clients.
  • Operation, the return authorizations of the user.

The provided functionality

All necessary set of methods contains in the class RDServer. Some of them are given in the table below:

Method name Access level Pframeters Return value Description
Start Public - - Server start
BroadCastConnections Private - - Receive broadcast requests from client applications
GetTCPConnections Private - - Receive TCP requests from client applications
TcpClientConnection Private Endpoint - Process one TCP request from client application
ClientLogIn Private Endpoint, Client message - Client authorization
ClientLogOut Private Endpoint, Client message - Exit client from system

Implementation examples

Here is the method code that implements the reception of requests for TCP - connections from clients.

private void GetTCPConnections()
        IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, serverEndpoit.portNumber);
        serverTCP.Init(SocketType.Stream, ProtocolType.Tcp, endPoint);
        fileLogger.WriteLogFile("Сервер ожидает TCP запросы от клиентов\n");
        while (true)
            Socket client = null;
            serverTCP.AcceptClient(out client);
            fileLogger.WriteLogFile("TCP клиент: " + ((IPEndPoint)client.RemoteEndPoint).Address.ToString() + ":" +
                   Convert.ToString(((IPEndPoint)client.RemoteEndPoint).Port) + '\n');
            Console.WriteLine("Client : {0}:{1}", ((IPEndPoint)client.RemoteEndPoint).Address, ((IPEndPoint)client.RemoteEndPoint).Port);
            ParameterizedThreadStart th = new ParameterizedThreadStart(TcpClientConnection);

            Thread clientThread = new Thread(th);
    catch (Exception exception)

Client application

Tasks for client application

Client application has the following tasks:

  • Event logging.
  • Authorization.
  • Automatic detection of server.
  • Communicating with the server.
  • Remote mouse control.
  • Remote control keyboard.
  • Demonstration of the desktop.
  • Sign Out.

The provided functionality

The functionality of the client application contains in the class RDClient. The description of some methods of a class is given below:

Method name Access level Pframeters Return value Description
FindServer Public - - Automatic server discovery
Start Public - - Client application start
ConnectToOtherClient Public The index of the client in the client list - Establishing a connection with another party networking
LogIn Public Login, password - Authorization
LogOut Public - - Sign out
SendMouseCommand Public The coordinates of the mouse position, the type of command (offset cursor keystrokes) - Remote mouse control
SendKeyBoardCommand Public keyboard key - Remote keyboard control
ReloadOnlineClientsList Public - - Updating the list of clients on the network
CloseConnectionToClients Public - - Terminates all established connections.
ScreenWasReceived Private Endpoint - Handler receiving picture desktop.
MouseCommandReceived Private Endpoint - Handler receiving the command the mouse.
KeyBoardCommandReceived Private Endpoint - Handler receiving the command the keyboard.

Implementation examples

As an example, consider the implementation of the method, designed for client authentication:

public void LogIn(string Login, string Password)
    if (Login.Length == 0 || Password.Length == 0)
        clientlogInStatus = ErrorType.EmptyData;
    clientlogInStatus = ErrorType.Ok;
    clientTCP.Init(SocketType.Stream, ProtocolType.Tcp);

    RDProtocol messageLogin = CreateLogInMessage(Login, Password);
    messageLogin.commandType = CommandType.LogIn;           
    RDProtocol serverAnswer = null;
    clientTCP.Receive(out serverAnswer);

    if (serverAnswer.commandType == CommandType.MessageSizeAccepted)
        RDProtocol otherClientsInfo = null;
        RDProtocol logInStatus = null;
        clientTCP.Receive(out logInStatus);
        if (logInStatus.commandType == CommandType.LogInOk)
            myLogin = Login;
            int clientsInfoSize = 0;
            clientTCP.ReceiveMsgSize(out clientsInfoSize);
            RDProtocol sizeAnswer = new RDProtocol();
            sizeAnswer.commandType = CommandType.MessageSizeAccepted;
            clientTCP.Receive(out otherClientsInfo, clientsInfoSize);
            ClientsInfo info = null;
            RDProtocolConvertor.ByteArrayToClientsInfo(, out info);
            otherClients = info.clientsList;

            Thread makeScreensThread = new Thread(new ThreadStart(ScreenMaker));
            makeScreensThread.IsBackground = true;
        else if (logInStatus.commandType == CommandType.LogInError)
            clientlogInStatus = ErrorType.IncorrectData;
        else if (logInStatus.commandType == CommandType.ClientHasAlreadyBeenLogIn)
            clientlogInStatus = ErrorType.ClientHasAlreadyBeenLogIn;
        clientlogInStatus = ErrorType.ServerError;

Communication protocol

To solve this problem has been realized a high-level protocol. The protocol consists of two parts - the message header and the actual data transmitted. Communication protocol is presented below.

public enum CommandType { FindSever, LogIn, LogOut, SignIn, MoveMouse, PressKey, ShowScreen, ClientsInfo, ConnectToClient, ServerFound,  LogInOk, LogInError, MessageSize, MessageSizeAccepted, DisconnectFromClient, MouseDblClick, MouseLeftBtnCLick,MouseRightBtnCLick, MouseWheel, MouseUp, MouseDown, iAlreadyConnected, SmbConnectedToMe }                                
public class RDProtocol
    public CommandType commandType { get; set; }
    public byte[] data { get; set; }       

epending on the message header field of data communication, is responsible for the actual data transmitted over the network, may contain different information. For example, if the header of the transmitted message is MoveMouse, which corresponds to control the mouse cursor, the data field will be presented in the form of a class object MouseCoordinates, converted into an array of bytes. MouseCoordinates class and other classes that describe the possible variations of the field data, are presented below.

public class MouseCoordinates
    public int MouseX { get; set; }
    public int MouseY { get; set; }
public class ClientKeys
    public string ClientLogin { get; set; }
    public string ClientPassword { get; set; }
public class RDEndpoint
    public IPAddress ipAddress { get; set; }
    public int portNumber { get; set; }
public class ClientsInfo
    public List<RDEndpoint> clientsList { get; set; }
public class ClientLoginData
    public ClientKeys clientKeys { get; set; }
    public RDEndpoint clientTCPEndpoint { get; set; }


Loggingis implemented on both the client and server side. This was done in order to identify the causes of emergency situations, as well as to obtain information about the system, the collection of statistics. Each line of the log has the following format:

<Message time>:<Message text>

System requirements

You must have .Net Framework 4.0.

Expanding the system

In order to be able to operate software necessary instructions to perform the steps provided below:

  • Run the server application.
  • Start the first client application on the same physical machine (can run on the machine where the server was started).
  • Perform a successful authentication of the first user.
  • Start the second client application on a different machine from the one on which the first application was launched - the customer. Running applications on different machines due to the convenience of only operating software.
  • Perform a successful authorization of the second user.
  • Make the connection of the first client to the second or vice versa.
  • Perform the necessary remote commands.
  • To end your Remote Desktop session to disconnect the client from the first second, or vice versa, depending on who established the connection.
  • Close the client - applications.
  • Close the server application.

en:Управление удаленной рабочей станцией