eltorro Posted September 3, 2007 Share Posted September 3, 2007 Here's a quick example of sending a screen capture with TCP. Tested on a lan and localhost. It sends a raw bitmap thus the size can get large. The bigger the size of the capture the slower the transfer. The server will try to determine the lan ip address of itself. This is the server: [autoit]#include <GUIConstants.au3> Local $iWidth = 320 Local $iHeight = 240 Local $iX = (@DesktopWidth - $iWidth)/2 Local $iY =(@DesktopHeight - $iHeight)/2 Local $v_IpAddress = "" ; network ip GetIp($v_IpAddress) Local $iPort = "5874" $ShotServer = GUICreate("Screen Server", 225, 250, 300, 116) $Status1 = GUICtrlCreateLabel("Ready.", 2, 230, 220, 17, $SS_SUNKEN) $Label2 = GUICtrlCreateLabel("Left:", 30, 10, 25, 17) $inLeft = GUICtrlCreateInput($iX, 75, 10, 121, 21) $Label3 = GUICtrlCreateLabel("Top:", 30, 35, 26, 17) $inTop = GUICtrlCreateInput($iY, 75, 35, 121, 21) $Label4 = GUICtrlCreateLabel("Width:", 30, 60, 35, 17) $inWidth = GUICtrlCreateInput($iWidth, 75, 60, 121, 21) $Label5 = GUICtrlCreateLabel("Height:", 30, 85, 38, 17) $inHeight = GUICtrlCreateInput($iHeight, 75, 85, 121, 21) $btnStart = GUICtrlCreateButton("Start", 40, 185, 65, 30, $BS_FLAT) $btnStop = GUICtrlCreateButton("Stop", 125, 185, 65, 30, $BS_FLAT) $ckMinimize = GUICtrlCreateCheckbox("Minimize on connection", 60, 160, 137, 17) $Label6 = GUICtrlCreateLabel("Ip Address:", 10, 110, 57, 17) $inIpAddress = GUICtrlCreateInput($v_IpAddress, 75, 110, 121, 21) $Label1 = GUICtrlCreateLabel("Port:", 40, 135, 26, 17) $inPort = GUICtrlCreateInput($iPort, 75, 135, 121, 21) GUISetState(@SW_SHOW) Global $MainSocket, $ConnectedSocket, $iCount Local $TIMER = 0 Local $temp While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnStart If $v_IpAddress <> "" And ($iPort > 0 And $iPort < 65536) Then Start($v_IpAddress, $iPort, $iX, $iY, $iWidth, $iHeight) StatusWrite ($Status1, "Ready.") EndIf Case $btnStop StatusWrite ($Status1, "Server Stopped.") $TIMER = TimerInit() Case $inLeft $temp = GUICtrlRead($inLeft) If $temp >= 0 Then $iX = $temp StatusWrite ($Status1, "Left changed to: " & $iX) Case $inTop $temp = GUICtrlRead($inTop) If $temp >= 0 Then $iY = $temp StatusWrite ($Status1, "Top changed to: " & $iY) Case $inWidth $temp = GUICtrlRead($inWidth) If $temp > 0 Then $iWidth = $temp StatusWrite ($Status1, "Width changed to: " & $iWidth) Case $inHeight $temp = GUICtrlRead($inHeight) If $temp > 0 Then $iHeight = $temp StatusWrite ($Status1, "Height changed to: " & $iHeight) Case $inIpAddress $temp = GUICtrlRead($inIpAddress) If $temp > 0 Then $v_IpAddress = $temp Case $inPort $temp = GUICtrlRead($inPort) If $temp > 0 Then $iPort = $temp EndSwitch If $TIMER Then If TimerDiff($TIMER) > 10000 Then $TIMER = 0 If GUICtrlRead($Status1) <> "Ready." Then StatusWrite ($Status1, "Ready.") EndIf EndIf WEnd Func Start($g_IP, $g_Port, $x, $y, $width, $height) StatusWrite ($Status1, "Awaiting connection from client...") While 1 TCPStartup() $MainSocket = TCPListen($g_IP, $g_Port, 100) If $MainSocket = -1 Then ExitLoop StatusWrite ($Status1, "Waiting for request...") While 1 If GUIGetMsg() = $btnStop Then TCPCloseSocket($MainSocket) Return EndIf $ConnectedSocket = TCPAccept($MainSocket) If $ConnectedSocket >= 0 Then StatusWrite ($Status1, "Client Connected") If GUICtrlRead($ckMinimize) = $GUI_CHECKED Then GUISetState(@SW_MINIMIZE) ExitLoop EndIf WEnd $retval = 0 While 1 If GUIGetMsg() = $btnStop Then TCPCloseSocket($ConnectedSocket) TCPCloseSocket($MainSocket) $MainSocket = -1 StatusWrite ($Status1, "Socket Closed.") Return EndIf $bBytes = DllStructCreate("byte[" & BitAND(($width + 3), 0xFFFFFFFC) * $height * 3 & "]") GetImage($x, $y, $width, $height, $bBytes) $retval = SendImage($bBytes, $width, $height) $bBytes = 0 If $retval = 0 Then ExitLoop WEnd StatusWrite ($Status1, "Client Connection Terminated") WEnd EndFunc ;==>Start Func SendImage(ByRef $bBytes, $width, $height) Local $ERR Local $iWritten Local $buffer $buffer = DllStructGetData($bBytes, 1) Sleep(10) $Msg = TCPRecv($ConnectedSocket, 65535) $ERR = @error If $ERR Then TCPCloseSocket($ConnectedSocket) TCPCloseSocket($MainSocket) $MainSocket = -1 StatusWrite ($Status1, "Error TCPConnect failed.") Sleep(2000) StatusWrite ($Status1, "WSA error was: " & $ERR) Sleep(3000) Return 0 Else Select Case $Msg = "sendsize" StatusWrite ($Status1, "Sending size...") Local $size = StringFormat("%s|%s|", $width, $height) $iWritten = TCPSend($ConnectedSocket, $size) Sleep(100) Case $Msg = "send" While BinaryLen($buffer) And Not $ERR $iWritten = TCPSend($ConnectedSocket, $buffer) $ERR = @error Sleep(100) $buffer = BinaryMid($buffer, $iWritten + 1, BinaryLen($buffer) - $iWritten) WEnd $iCount += 1 StatusWrite ($Status1, "Sent :" & $iWritten & " Count :" & $iCount) EndSelect EndIf $buffer = 0 If $ERR Then Return 0 Return 1 EndFunc ;==>SendImage Func GetImage($get_x, $get_y, $wid, $ht, ByRef $byteStruct, $hwnd = 0) Local Const $DIB_RGB_COLORS = 0 Local Const $SRCCOPY = 0xCC0020 Local $BitInfo = DllStructCreate("dword;int;int;ushort;ushort;dword;dword;int;int;dword;dword;byte[4]") DllStructSetData($BitInfo, 1, 40) DllStructSetData($BitInfo, 2, $wid) DllStructSetData($BitInfo, 3, $ht) DllStructSetData($BitInfo, 4, 1) DllStructSetData($BitInfo, 5, 24) Local $dc = DllCall("user32.dll", "int", "GetWindowDC", "hwnd", $hwnd) $dc = $dc[0] Local $iDC = DllCall("gdi32.dll", "int", "CreateCompatibleDC", "int", $dc) $iDC = $iDC[0] Local $iBitmap = DllCall("gdi32.dll", "hwnd", "CreateDIBSection", "int", $iDC, "ptr", DllStructGetPtr($BitInfo), _ "int", $DIB_RGB_COLORS, "ptr", 0, "hwnd", 0, "int", 0) $iBitmap = $iBitmap[0] DllCall("gdi32.dll", "hwnd", "SelectObject", "int", $iDC, "hwnd", $iBitmap) DllCall("gdi32.dll", "int", "BitBlt", "int", $iDC, "int", 0, "int", 0, "int", $wid, "int", _ $ht, "int", $dc, "int", $get_x, "int", $get_y, "int", $SRCCOPY) DllCall("gdi32.dll", "int", "GetDIBits", "int", $iDC, "hwnd", $iBitmap, "int", 0, "int", $ht, "ptr", _ DllStructGetPtr($byteStruct), "ptr", DllStructGetPtr($BitInfo), "int", $DIB_RGB_COLORS) $BitInfo = 0 DllCall("user32.dll", "int", "ReleaseDC", "int", $dc, "hwnd", $hwnd) DllCall("gdi32.dll", "int", "DeleteDC", "int", $iDC) DllCall("gdi32.dll", "int", "DeleteObject", "hwnd", $iBitmap) EndFunc ;==>GetImage Func StatusWrite ($nCtrl, $Msg) If $nCtrl = 0 Then Return GUICtrlSetData($nCtrl, $Msg) $TIMER = TimerInit() EndFunc ;==>StatusWrite Func GetIp(ByRef $v_IpAddress) Select Case CheckIp(@IPAddress1) $v_IpAddress = @IPAddress1 Case CheckIp(@IPAddress2) $v_IpAddress = @IPAddress2 Case CheckIp(@IPAddress3) $v_IpAddress = @IPAddress3 Case CheckIp(@IPAddress4) $v_IpAddress = @IPAddress4 Case Else $v_IpAddress = "127.0.0.1" EndSelect EndFunc ;==>GetIp Func CheckIp($ip) $aIp = StringSplit($ip, ".") If IsArray($aIp) Then If UBound($aIp) = 5 Then If $aIp[1] > 0 Then Return True EndIf EndIf Return False EndFunc ;==>CheckIp Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
Alek Posted September 4, 2007 Share Posted September 4, 2007 wow, this is awsome, remote control here i come (I think) [font="Impact"]Never fear, I is here.[/font] Link to comment Share on other sites More sharing options...
arcker Posted September 4, 2007 Share Posted September 4, 2007 i like the way you made this new code from our webcam script ! didn't think about it -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects :[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] Link to comment Share on other sites More sharing options...
Xwolf Posted April 27, 2008 Share Posted April 27, 2008 Oh my god, this is really nice. Thanks very much. Link to comment Share on other sites More sharing options...
echelonintel Posted July 25, 2016 Share Posted July 25, 2016 please i want to know if its possible to link login page to inbuilt webcam so once someone clicks login from any site the in-built webcam is activated to take snapshots of the person and saved with current location and ip address of the pc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 25, 2016 Moderators Share Posted July 25, 2016 echelonintel, Very definitely doing that is something that we will not support under any circumstances - thread closed. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts