Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Remote screen (desktop)

Posted on 2009-12-27
19
Medium Priority
?
2,135 Views
Last Modified: 2013-11-23
Hi !

First ... Merry Christimas for all of you!

Well... I need to create a client/server app for screen monitoring purposes (only monitoring, not interact as VNC). In this first step, It will monitor only a lan (not internet). I have researched here in EE and Google, found a lot of codes, that only confused me...

I would like to know wich is the best (faster and low memory/traffic consumption) way to do this:

1. I tried using INDY. Is it the best component for this? Can you sugest other?
2. I tried convert screen from BMP to JPG (60%) before send. I do not know if it is a good idea, because we "lost" some miliseconds doing this... In other hand, I think will become faster to send, and reduce lan traffic. What you think?

If possible give me some code for doing this in "thread" way.

PS. Well, a VNC like component will help a lot too... If you know some (commercial) component for this, I appreciate.


Thanks a lot!!
0
Comment
Question by:delphibr
  • 8
  • 8
  • 3
19 Comments
 
LVL 18

Expert Comment

by:Johnjces
ID: 26129373
You  might have a look at delphi.about.com as they have a complete application ready to go, full Delphi source included that may do exactly what you want and easily modifiable,

It is called Screethief.

http://delphi.about.com/od/internetintranet/l/aa012004a.htm

Let me know if this does it for you.

John
0
 
LVL 1

Author Comment

by:delphibr
ID: 26130825
Hi Johnjces,

I already see Screenthief a long time ago. Sorry, but I do not think this is the best solution for this (faster and low memory/traffic consumption). Do you have some other ideas?

I heard that VNC do not send the "all" picture of screen, only the pixels that changed. Do you know a function or some component for this? I can pay for it.

Thanks!
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 26131135
The only thing VNC for Delphi that I know of is from SourceForge. OpenSource all code included.

http://sourceforge.net/projects/delphivnc/
http://delphivnc.sourceforge.net/

Good luck!

John
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:delphibr
ID: 26131695
Hi Johnjces,

Thanks, but ... have you tried this code? I think it is only for connect with VNC server (or client). Please, correct me if I am wrong...

DelphiBR
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 26131713
Nope... never tried it... just the only thing I know of.
0
 
LVL 1

Author Comment

by:delphibr
ID: 26132663
Well, I just increase the points to 500...

Please, some good soul help me! ;-)

DelphiBR
0
 
LVL 16

Expert Comment

by:CodedK
ID: 26148689
Hi delphibr,

About compressing BMP to JPEG or sending it as BMP i support the idea of compressing.
Better a fragment of a millisecond than some seconds...
If you think that ScreenThief is memory / time consuming then try to use the minimum functions needed for this operation. For example :

Server side :
function GetScreenShot: TJPEGImage;
var
  Desktop: HDC;
  bmp: TBitmap;
begin
  Result:=TJPEGImage.Create;
  bmp  := TBitmap.Create;
  Desktop := GetDC(0);
  try
    try
      bmp.PixelFormat := pf32bit;
      bmp.Width := Screen.Width;
      bmp.Height := Screen.Height;
      BitBlt(bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height, Desktop, 0, 0, SRCCOPY);
      bmp.Modified := True;
      Result.Assign(bmp);
    finally
      ReleaseDC(0, Desktop);
    end;
  except
    bmp.Free;
    bmp := nil;
    Result.Free;
    Result:=nil;
  end;
end;
//Code modified from Torry.net

Now we have to specify when the server will start sending the picture.
For example when sending the command "Req_Screen". Adding the routine check in onClientRead and if the text is received "Req_Screen," it creates the Stream, saves the photo in TJpegImage stream, sends the size of the stream, and finally sends the stream ...

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
s: string;
Stream: TMemoryStream;
jpg: TJPEGImage;
begin
s:=Socket.ReceiveText;
if s = 'Req_Screen' then
  begin
  Stream:=TMemoryStream.Create;
  jpg:=TJPEGImage.Create;
  jpg:=GetScreenShot;
  jpg.SaveToStream(Stream);
  Stream.Position:=0;
  Socket.SendText(inttostr(Stream.Size) + #0);
  Socket.SendStream(Stream);
  end;
end;

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~

Now the client side :

Global vars
  stSize: integer;
  Stream: TMemoryStream;
  Received: boolean;
  jpg: TJpegImage;

Inside a button ...

procedure TForm1.Button1Click(Sender: TObject);
begin
ClientSocket1.Socket.SendText('Req_Screen');
end;


Sendind the command correctly the position must be 0 (reading the data flow will start from the beginning).


procedure TForm1.ClientSocket1Read(Sender: TObject;
  Socket: TCustomWinSocket);
var
s: string;
begin
s:=Socket.ReceiveText;
if not Received then
  begin
  if pos(#0,s) > 0 then
    stSize:=strtoint(copy(s,1,pos(#0,s)-1))
  else
    exit;
  Stream:=TMemoryStream.Create;
  Received:=True;
  delete(s,1,pos(#0,s));
  end;
try
  Stream.Write(s[1],length(s));
  if Stream.Size = stSize then
    begin
    Stream.Position:=0;
    Received:=False;
    jpg:=TJPEGImage.Create;
    jpg.LoadFromStream(Stream);
    Image1.Picture.Assign(jpg);
    Stream.Free;
    end;
except
  Stream.Free;
end;
end;

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~

You can use Stream.LoadFromFile ('SomeFile.zip') if you want to send a file instead of an image.
You can even compress the stream. You can use Asm. And you can change those procedures to minimize memory and time consumption.

Some free components here :
http://www.torry.net/quicksearchd.php?String=vnc&Title=Yes

I hope this helps.

0
 
LVL 1

Author Comment

by:delphibr
ID: 26148971
Hi CodedK,

Thanks for your reply! I will analise carefully and let you know...

One thing about this client/server socket programming that is very confusing for me is when use TCPClient and when use TCPServer. In ScreenThief code, the author used TCPServer on server side (the main computer) to coordenate the connections. In your code you used TCPServer on client site.... Why? I really do not understand!

Happy New Year!!

Delphi BR
0
 
LVL 16

Accepted Solution

by:
CodedK earned 1500 total points
ID: 26149228
You are the client you will do the request.
On the other hand the server could coordinate everything automatically in small intervals.
So Server side when you want everything to be automated for example you know that  you want to receive every 1 sec a screenshot then there is no need to push any button.

But when you want to get a screenshot when you want then there's got to be a man in the middle ... You. To decide when with the push of a button.

I presented the most easy way/code for you to understand the core of the problem.
From this point you can automate the server or the client. You decision.
0
 
LVL 16

Expert Comment

by:CodedK
ID: 26149238
And happy new year :)
0
 
LVL 1

Author Comment

by:delphibr
ID: 26158132
Hi CodedK,

Thanks! This client / server programming is a little bit clear for me now!

You sent a Torry´s link, with some components. I am looking for VNC Server Component since last week, but http://www.usestream.com/ is offline. Do you know where can I get it?

Many thanks!

Delphi BR
0
 
LVL 16

Expert Comment

by:CodedK
ID: 26158621
0
 
LVL 16

Expert Comment

by:CodedK
ID: 26158627
By the way you don't need any components just use the code i gave you.
Since you don't want any VNC functionality ...
0
 
LVL 1

Author Comment

by:delphibr
ID: 26158694
This link is to download the test app, not the Delphi component...
0
 
LVL 16

Expert Comment

by:CodedK
ID: 26159107
0
 
LVL 1

Author Comment

by:delphibr
ID: 26159676
I got into the website, but when I click to download VNC Server Source Code there is a message: "Not in Archive"... :-(  Thanks anyway!

If no one places a better solution until sunday you will get the points!

Thanks again!

Delphi BR
0
 
LVL 1

Author Closing Comment

by:delphibr
ID: 31670293
Thanks!
0
 
LVL 16

Expert Comment

by:CodedK
ID: 26170783
Thanks... But why B grade?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question