public static void main(String[] args) throws Exception {
    DatagramSocket serverSocket = new DatagramSocket(8083);
    int count = 0;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int middleOfScreenX = (int) Math.round(screenSize.getWidth() / 2);
    int middleOfScreenY = (int) Math.round(screenSize.getHeight() / 2);

    System.out.println("Server started");
    byte[] receiveData = new byte[128];
    Robot robot = new Robot();
    while (true) {
      DatagramPacket receivedPacket = new DatagramPacket(receiveData, receiveData.length);
      serverSocket.receive(receivedPacket);

      SenderObject senderObject = SenderObject.parseFrom(receivedPacket.getData());
      float y = senderObject.getY();
      float x = senderObject.getX();
      int type = senderObject.getType();
      System.out.println(senderObject.toString());
      // Get the current pointer location.
      Point mousePointer = MouseInfo.getPointerInfo().getLocation();

      // Check if the type is mouse click.
      if (type == 2) {
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
      }
      // otherwise move the mouse pointer by subtracting to current
      // coordinates. Subtraction, because of the flipped right and left.
      else {
        float curX = mousePointer.x - x;
        float curY = mousePointer.y - y;
        robot.mouseMove(Math.round(curX), Math.round(curY));
      }
    }
  }