caleb41610 Posted September 30, 2012 Posted September 30, 2012 server function: expandcollapse popupFunc 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: expandcollapse popupFunc 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? Multi-Connection TCP Server
FireFox Posted September 30, 2012 Posted September 30, 2012 This question has been asked a ton of times... make a forum search. Br, FireFox.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now