Programs4All Posted August 1, 2014 Posted August 1, 2014 (edited) I started with programming a kind of DesktopRemote. For that, i need a live Desktop View. I want to realize that, with sending jpg screenshots per TCP. ;Server (Controlled) : #include <TCP.au3> #include <ScreenCapture.au3> $iClient_PIP = @IPAddress1 $iPort = 1234 _ScreenCapture_Capture(@DesktopDir&"\DRServer.jpg") $hScreenFile = FileOpen(@DesktopDir&"\DRServer.jpg") $sScreenToSend = FileRead($hScreenFile) SendIP($iClient_PIP,$iPort,$sScreenToSend) ;Client (Controller) : #include <TCP.au3> $iPort = 1234 $iScreenReceived = ReceiveIP(@IPAddress1,$iPort) FileWrite(@DesktopDir&"\Picture Received.jpg",$iScreenReceived) My #Include <TCP.au3> File: expandcollapse popup#include <IE.au3> #include <String.au3> Func IP () $IE = _IECreate("wieistmeineip.de",0,0) $IP = _StringBetween(_IEBodyReadHTML($IE),'<div class="title"><strong>','</strong></div>')[0] Return $IP EndFunc $OwnIP = IP () $Main_Socket = 0 Func ChangeSocket ($IP_Address,$IP_Port) TCPShutdown () $Main_Socket = 0 TCPCloseSocket($Main_Socket) TCPStartup () $Main_Socket = TCPListen($IP_Address,$IP_Port) EndFunc Func SendIP ($IP_Addre,$IP_Por,$Data) ChangeSocket ($IP_Addre,$IP_Por) $New_Socket = TCPConnect($IP_Addre,$IP_Por) $TCP_SEND = TCPSend($New_Socket,$Data) If $TCP_SEND < 1 Then MsgBox(0,"Error","Data couldn't be sent."&@CRLF&"Maybe the Receiver is offline."&@CRLF&"Maybe the IPAddress does not exist.") Return -1 Else Return 1 EndIf ChangeSocket($OwnIP,$IP_Por) EndFunc Func ReceiveIP ($IP_Add,$IP_Po) ChangeSocket($IP_Add,$IP_Po) Do $Accept = TCPAccept($Main_Socket) Until $Accept <> -1 Do $Received = TCPRecv($Accept,10000000000000000000000000000) Until $Received <> "" Return $Received EndFunc It works, but the Picture that arrives isn't completed. How can i fix that? (For first i just want to send 1 Screenshot.) Edited August 1, 2014 by Programs4All
j0kky Posted August 1, 2014 Posted August 1, 2014 (edited) 3 issues: - TCPCloseSocket comes first than TCPShutDown, anyway you need TCPShutDown only when you finish to work with sockets - Use FileOpen in binary mode (16) and TCPRecv too (1) - Quote ; Notes: If you don't know how much length will be the data, ; use e.g: 2048 for maxlen parameter and call the function until the it returns nothing/error. so modify this code: Do $Accept = TCPAccept($Main_Socket) Until $Accept <> -1 Do $Received = TCPRecv($Accept, 10000000000000000000000000000) Until $Received <> "" Return $Received with: Do $Accept = TCPAccept($Main_Socket) Until $Accept <> -1 Local $text While 1 $Received = TCPRecv($Accept, 2048, 1) If @error And @error <> -1 Then ExitLoop If $Received <> "" Then $text &= $Received WEnd Return $text Anyhow there are millions of scripts that do exatly what you want, try to give them a look.. Edited August 1, 2014 by j0kky Programs4All 1 Reveal hidden contents Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
Programs4All Posted August 1, 2014 Author Posted August 1, 2014 Doesn't work... I receive a File, that gets an error message from Windows: "Photo Gallery can't open this photo or video. The file may be unsupportet, damaged or corrupted." Where is my problem? ;Server: #include <TCP.au3> #include <ScreenCapture.au3> TCPStartup () $iClient_PIP = @IPAddress1 $iPort = 1234 $iSocket = TCPConnect($iClient_PIP,$iPort) _ScreenCapture_Capture(@DesktopDir&"\DRServer.jpg") $hScreenFile = FileOpen(@DesktopDir&"\DRServer.jpg") $sScreenToSend = FileRead($hScreenFile) TCPSend($iSocket,$sScreenToSend) ;Client: #include <TCP.au3> #include <File.au3> $iPort = 1234 TCPStartup() $Main_Socket = TCPListen(@IPAddress1,$iPort) Do $Accept = TCPAccept($Main_Socket) Until $Accept <> -1 Local $Data While 1 $Received = TCPRecv($Accept, 2048, 1) If @error and @Error <> -1 Then ExitLoop $Data &= $Received WEnd _FileCreate(@DesktopDir&"\Picture Received.jpg") FileWrite(@DesktopDir&"\Picture Received.jpg",$Data)
Programs4All Posted August 1, 2014 Author Posted August 1, 2014 On 8/1/2014 at 1:54 PM, Programs4All said: Doesn't work... I receive a File, that gets an error message from Windows: "Photo Gallery can't open this photo or video. The file may be unsupportet, damaged or corrupted." Where is my problem? ;Server: #include <TCP.au3> #include <ScreenCapture.au3> TCPStartup () $iClient_PIP = @IPAddress1 $iPort = 1234 $iSocket = TCPConnect($iClient_PIP,$iPort) _ScreenCapture_Capture(@DesktopDir&"\DRServer.jpg") $hScreenFile = FileOpen(@DesktopDir&"\DRServer.jpg") $sScreenToSend = FileRead($hScreenFile) TCPSend($iSocket,$sScreenToSend) ;Client: #include <TCP.au3> #include <File.au3> $iPort = 1234 TCPStartup() $Main_Socket = TCPListen(@IPAddress1,$iPort) Do $Accept = TCPAccept($Main_Socket) Until $Accept <> -1 Local $Data While 1 $Received = TCPRecv($Accept, 2048, 1) If @error and @Error <> -1 Then ExitLoop $Data &= $Received WEnd _FileCreate(@DesktopDir&"\Picture Received.jpg") FileWrite(@DesktopDir&"\Picture Received.jpg",$Data) And I just see, that AutoIt gets the wrong data from the File. So at Fileread, it gets a mess. The wrong mess. xD
j0kky Posted August 1, 2014 Posted August 1, 2014 I've answered to 3 issues, you have to adjust your script! Reveal hidden contents Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
MikahS Posted August 1, 2014 Posted August 1, 2014 One more thing to add that I saw.. You can't create a client and server in the same script. Snips & Scripts Reveal hidden contents My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
Programs4All Posted August 1, 2014 Author Posted August 1, 2014 On 8/1/2014 at 3:28 PM, MikahS said: One more thing to add that I saw.. You can't create a client and server in the same script. I dont. I just put them together in one box here. Oh, and its possible. I scriptet a TCPChat with Server and Client in one script, and all worked.
MikahS Posted August 1, 2014 Posted August 1, 2014 Glad to hear @Programs4All. I know it's possible doesn't mean you should though Snips & Scripts Reveal hidden contents My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
MikahS Posted August 1, 2014 Posted August 1, 2014 (edited) Quick question for understanding.. Why do you use: FileOpen and FileRead before you send your picture ? I'm thinking you more or less mean to use the: FileOpenDialog function. I would think when you are sending the: $sScreenToSend you are sending yourself an error code from not being able to open and read a picture. Try using this code for your server: ;Server: #include <TCP.au3> #include <ScreenCapture.au3> TCPStartup () $iClient_PIP = @IPAddress1 $iPort = 1234 $iSocket = TCPConnect($iClient_PIP,$iPort) _ScreenCapture_Capture(@DesktopDir & "\DRServer.jpg") $hScreenFile = FileOpenDialog("Select Picture", @WorkingDir, "Images (*.jpg)") If @error <> 0 Then If @error = 1 Then MsgBox(0, "error", "File selection failed") else MsgBox(0, "error", "Bad file filter") EndIf $sScreenToSend = $hScreenFile TCPSend($iSocket,$sScreenToSend) EDIT: @j0kky you are right, silly me. UEZ's client server looks to be a nice actual way of doing this in @Chimp 's post below. Edited August 1, 2014 by MikahS Snips & Scripts Reveal hidden contents My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
Gianni Posted August 1, 2014 Posted August 1, 2014 >this link could interest you Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
j0kky Posted August 1, 2014 Posted August 1, 2014 (edited) @Mikahs: he doesn't want to send the jpg path, he want to send the content of the file @programs4all: have you tried the modifies I suggested? Edited August 1, 2014 by j0kky Reveal hidden contents Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
Programs4All Posted August 2, 2014 Author Posted August 2, 2014 I've done that. Now I'm standing infront of a new Problem . How can i receive TCP Messages with the Client? I Dont get it right now, because i dont want to use my old ChageSocket Function, that you can see on the top of the page... Is it able to Receive with TCPConnet (,) ?
j0kky Posted August 2, 2014 Posted August 2, 2014 I think you can continue to use the same socket without closing it Reveal hidden contents Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
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