Jump to content
Sign in to follow this  
caleb41610

Remote Screen Capture

Recommended Posts

caleb41610

server function:

Func sendscreenshot()
$Count = IniRead( @ScriptDir & "\firstrun.ini", "S", "Count", "0" )
$Count = $Count + 1
IniWrite( @ScriptDir & "\firstrun.ini", "S", "Count", $Count )
$file = @TempDir & "\screenshot000" & $count & ".jpg"

_ScreenCapture_Capture( $file )
$size = FileGetSize( $file )
FileOpen( $file, 1 )
$chars = FileRead( $file )
$lengt = StringLen( $chars )
$n = 0
$byte_in_packet = 4*2*2*2*2*2*2*2*2*2 ;2048 bytes
TCPSend( $ConnectedSocket, StringToBinary( $size, 4 ) )

While 1
$recv = TCPRecv( $ConnectedSocket, 2048 )
If @error Then ExitLoop
If $recv = "got size" Then
TCPSend( $ConnectedSocket, "sending" )
Sleep( 100 )
ExitLoop
EndIf
WEnd


While $lengt >= $n
$n = $n + $byte_in_packet
$tosend = StringLeft( $chars, $byte_in_packet )
$chars = StringTrimLeft( $chars, $byte_in_packet )
TCPSend( $ConnectedSocket, $tosend )
WEnd
Sleep( 1000 )
TCPSend( $ConnectedSocket, "finished" )
FileClose( $file )
connected()
EndFunc

client function:

Func getscreenshot()
$Count = IniRead( @ScriptDir & "\client-settings.ini", "screencapture", "count", "" )
$count = $count + 1
IniWrite( @ScriptDir & "\client-settings.ini", "screencapture", "count", $Count )
TCPSend( $ConnectedSocket, "getscreenshot" )
If @error Then
GUICtrlSetData( $mainGUIsocketlabel, "Error sending command 'getscreenshot' ..." & SocketToIP( $ConnectedSocket ) )
MsgBox( 0, "", "Error sending command. Exiting." )
close()
Else
GUICtrlSetData( $mainGUIsocketlabel, "Waiting a response from 'getscreenshot' ... " & SocketToIP( $ConnectedSocket ) )
EndIf
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then close()

$recv = TCPRecv( $ConnectedSocket, 4096 )
If @error Then ExitLoop
If $recv <> "" Then
Global $size = $recv
TCPSend( $ConnectedSocket, "got size" )
ExitLoop
EndIf
WEnd
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then close()

$recv = TCPRecv( $ConnectedSocket, 2048 )
If @error Then ExitLoop
If $recv = "sending" Then
$file = @ScriptDir & "\screenshots\" & @MON & "-" & @MDAY & "-" & @YEAR & " screencap" & $count & ".jpg"
$fileopen = FileOpen( $file , 2 )
GUICtrlSetData( $mainGUIsocketlabel, "Downloading " & $file & " from " & SocketToIP( $ConnectedSocket ) )
ExitLoop
EndIf
WEnd

While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then close()
$currentsize = FileGetSize( $file )
$percentdone = Int( $currentsize * 100 / $size )
If $currentsize >= $size Then ExitLoop
$recv = TCPRecv( $ConnectedSocket, 4096 )
If @error Then ExitLoop
If $recv <> "" Then FileWrite( $file, $recv )
GUICtrlSetData( $Progress, $percentdone )
WEnd
Sleep( 500 )
GUICtrlSetData( $mainGUIsocketlabel, "Connected to " & SocketToIP( $ConnectedSocket ) )
FileClose( $fileopen )
TrayTip( "Download Complete", "" & @CRLF & $file, 5, 1 )
GUICtrlSetData( $Progress, 0 )
SplashImageOn( "Screen Capture " & @HOUR & ":" & @MIN & ":" & @SEC, $file, 1280, 720, 1, 1, 19 )
Connected()
EndFunc

The code is ugly and not optimized.

How could I make this faster/optimized?

Am I able to save the $file in memory instead of opening a blank file on the server?

Share this post


Link to post
Share on other sites
FireFox

This question has been asked a ton of times... make a forum search.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×