Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/29/2020 in all areas

  1. Hi guys, here is a small dll wrapper I made geared at making YOLOv3 (Joseph Redmon, Ali Farhadi) more accessible to AutoIt users. Homepage of YOLO: https://pjreddie.com/darknet/yolo/ Technical overview: You only look once (YOLO) is a state-of-the-art, real-time object detection system. On a Pascal Titan X it processes images at 30 FPS and has a mAP of 57.9% on COCO test-dev. (from https://pjreddie.com/darknet/yolo/) Screenshots: Features: This UDF currently supports recognizing objects in images passed in as a HBITMAP Below is a complete list of the functions currently available in this library: ; #CURRENT# ===================================================================================================================== ;_AutoYolo3_GetLastError ;_AutoYolo3_GetObjInHBitmap ;_AutoYolo3_GetVersion ;_AutoYolo3_SetConfig ;_AutoYolo3_YoloTest ; =============================================================================================================================== The _AutoYolo3_GetObjInHBitmap function returns a 2D Array of detected objects as illustrated below: Examples: Example1: basic_example.au3 #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <AutoYOLO3.au3> #include <GDIPlus.au3> ConsoleWrite("Using autoyolo version:" & _AutoYolo3_GetVersion() & @CRLF) _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\people-2557408_1920.jpg") Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage, 0x00000000) Local $aRes = _AutoYolo3_GetObjInHBitmap($hHBITMAP) _ArrayDisplay($aRes) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Example 2: gui_example.au3 #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 5 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <AutoYOLO3.au3> #include <GDIPlus.au3> ConsoleWrite("Using autoyolo version:" & _AutoYolo3_GetVersion() & @CRLF) _GUIExample1() Func _GUIExample1()     _GDIPlus_Startup()     Local $iPicW=609     Local $iPicH=385     #Region ### START Koda GUI section ### Form=     GUICreate(@ScriptName&" - Object Detection with AutoIt!", 625, 506)     GUISetFont(14, 400, 0, "Calibri")     Local $Button1 = GUICtrlCreateButton("browse", 472, 8, 145, 33)     Local $Input1 = GUICtrlCreateInput(@ScriptDir & "\scooter-5180947_1920.jpg", 8, 8, 457, 31)     Local $Button2 = GUICtrlCreateButton("detect objects!", 228, 448, 169, 49)     Local $Pic1 = GUICtrlCreatePic("", 8, 48, $iPicW, $iPicH, $SS_BITMAP)     GUISetState(@SW_SHOW)     #EndRegion ### END Koda GUI section ###     Local $hImage = _LoadImage($Input1, $Pic1, 0, $iPicW,$iPicH)     While 1         $nMsg = GUIGetMsg()         Switch $nMsg             Case $GUI_EVENT_CLOSE                 Exit             Case $Button1                 GUICtrlSetData($Input1, FileOpenDialog("Please select image", @ScriptDir, "All (*.*)"))                 $hImage = _LoadImage($Input1, $Pic1, $hImage, $iPicW,$iPicH)             Case $Button2                 GUICtrlSetState($Button2, $GUI_DISABLE)                 GUICtrlSetData($Button2, "working..")                 Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage, 0x00000000)                 Local $aRes = _AutoYolo3_GetObjInHBitmap($hHBITMAP)                 ;_ArrayDisplay($aRes)                 If @error Then                     Local $iErr = @error                     Local $asDllErrors[6] = ["No error", "unable to use the DLL file", "unknown ""return type""", """function"" not found in the DLL file", "bad number of parameters", "bad parameter"]                     If $iErr < 6 Then                         MsgBox(32, @ScriptName, "DLL Error, " & $asDllErrors[$iErr])                     Else                         MsgBox(32, @ScriptName, "DLL Error, " & _AutoYolo3_GetLastError())                     EndIf                 ElseIf _AutoYolo3_GetLastError() <> "" Then                     MsgBox(32, @ScriptName, _AutoYolo3_GetLastError())                 Else                     ;nice thick green boxes                     Local $hPen = _GDIPlus_PenCreate(0xFF00FF00, 2, 2)                     Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)                     Local $hFormat = _GDIPlus_StringFormatCreate()                     Local $hFamily = _GDIPlus_FontFamilyCreate("Calibri")                     Local $hFont = _GDIPlus_FontCreate($hFamily, 12, 0)                     Local $tLayout = _GDIPlus_RectFCreate(140, 110, 100, 20)                     Local $hBrushBack = _GDIPlus_BrushCreateSolid(0x7FFFFFFF) ;color format AARRGGBB (hex)                     $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage)                     _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)                     For $i = 1 To $aRes[0][0]                         ; Draw a frame around the object                         _GDIPlus_GraphicsDrawRect($hGraphics, $aRes[$i][2], $aRes[$i][3] , ($aRes[$i][4] - $aRes[$i][2]) , ($aRes[$i][5] - $aRes[$i][3]) , $hPen)                         ; Label it                         $sLabel = $aRes[$i][0] & " " & StringLeft($aRes[$i][1], 6)                         $tLayout = _GDIPlus_RectFCreate($aRes[$i][2] , $aRes[$i][3] , 200, 20)                         $iBackLen = 0                         If (StringLen($sLabel) * 8) > $iBackLen Then                             $iBackLen = StringLen($sLabel) * 8                         EndIf                         _GDIPlus_GraphicsFillRect($hGraphics, $aRes[$i][2] , $aRes[$i][3], $iBackLen, 20, $hBrushBack)                         _GDIPlus_GraphicsDrawStringEx($hGraphics, $sLabel, $hFont, $tLayout, $hFormat, $hBrush)                     Next                     $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage, 0x00000000)                     GUICtrlSendMsg($Pic1, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP)                     _GDIPlus_PenDispose($hPen)                     _GDIPlus_FontDispose($hFont)                     _GDIPlus_FontFamilyDispose($hFamily)                     _GDIPlus_StringFormatDispose($hFormat)                     _GDIPlus_BrushDispose($hBrush)                     _GDIPlus_BrushDispose($hBrushBack)                     _GDIPlus_GraphicsDispose($hGraphics)                 EndIf                 GUICtrlSetData($Button2, "detect objects!")                 GUICtrlSetState($Button2, $GUI_ENABLE)         EndSwitch     WEnd     If $hImage <> 0 Then         _GDIPlus_ImageDispose($hImage)     EndIf     _GDIPlus_Shutdown() EndFunc   ;==>_GUIExample1 Func _LoadImage($Input1, $Pic1, $hImage, $iPicW, $iPicH)     If $hImage <> 0 Then         _GDIPlus_ImageDispose($hImage)     EndIf     Local $sImagePath = GUICtrlRead($Input1)     $hImage = _GDIPlus_ImageLoadFromFile($sImagePath)     Local $iWidth = _GDIPlus_ImageGetWidth($hImage)     Local $iHeight = _GDIPlus_ImageGetHeight($hImage)     Local $sFactor = 1     If $iWidth > $iPicW Then         $sFactor = $iPicW / $iWidth     EndIf     If $iHeight > $iPicH And ($iHeight * $sFactor) > $iPicH Then         $sFactor = $iPicH / $iHeight     EndIf     $iHeight = $iHeight * $sFactor     $iWidth = $iWidth * $sFactor     $hResizedImage = _GDIPlus_ImageResize($hImage, $iWidth, $iHeight)     _GDIPlus_BitmapDispose($hImage)     Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hResizedImage, 0x00000000)     GUICtrlSendMsg($Pic1, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP)     Return $hResizedImage EndFunc   ;==>_LoadImage Requirements: Windows x64, AutoIt x64 Microsoft Visual C++ 2015-2019 Redistributable (x64) - https://aka.ms/vs/16/release/vc_redist.x64.exe OpenCV binaries - https://sourceforge.net/projects/opencvlibrary/files/4.3.0/opencv-4.3.0-vc14_vc15.exe/download Quickstart: Ensure you are running Windows x64, AutoIt x64 Install Microsoft Visual C++ 2015-2019 Redistributable (x64) if not already installed - https://aka.ms/vs/16/release/vc_redist.x64.exe Create your project directory anywhere, for this example we use C:\projectdir\ Download OpenCV - https://sourceforge.net/projects/opencvlibrary/files/4.3.0/opencv-4.3.0-vc14_vc15.exe/download Unpack OpenCV anywhere and copy opencv_videoio_ffmpeg430_64.dll, opencv_world430.dll to C:\projectdir\ Download trained weights, classes, config files Weights file: Save as C:\projectdir\yolo\yolov3.weights - https://pjreddie.com/media/files/yolov3.weights Classes file: Save as C:\projectdir\yolo\yolov3.txt - https://github.com/pjreddie/darknet/blob/master/data/coco.names https://raw.githubusercontent.com/zishor/yolo-python-rtsp/master/cfg/yolov3.txt NEW Config file: Save as C:\projectdir\yolo\yolov3.cfg - https://github.com/pjreddie/darknet/blob/master/cfg/yolov3.cfg https://raw.githubusercontent.com/zishor/yolo-python-rtsp/master/cfg/yolov3.cfg NEW Unpack autoyolo1.1.zip from downloads below to your project dir So your project directory should look like: C:\projectdir\ │   autoyolo.dll │   AutoYOLO3.au3 │   basic_example.au3 │   gui_example.au3 │   opencv_videoio_ffmpeg430_64.dll │   opencv_world430.dll │   people-2557408_1920.jpg │   scooter-5180947_1920.jpg │ └───yolo         yolov3.cfg         yolov3.txt         yolov3.weights You are done! Try running one of the examples! Download: LAST UPDATED: 06-JUN-2020 autoyolo1.1.zip 785 KB Credits: YOLOv3: An Incremental Improvement - Joseph Redmon, Ali Farhad https://pjreddie.com/yolo/ https://www.learnopencv.com/deep-learning-based-object-detection-using-yolov3-with-opencv-python-c/ zishor for alternative config and classes (https://github.com/zishor/yolo-python-rtsp) MIT License FAQ: I get error "Cannot use dll" Ensure that you are running script as x64, that you have Microsoft Visual C++ 2015-2019 Redistributable (x64) installed, and that the following files are in the @ScriptDir: autoyolo.dll, opencv_videoio_ffmpeg430_64.dll, opencv_world430.dll I get a crash when clicking detect Try using the NEW config and classes links above All feedback is welcome -smartee
    1 point
  2. ; ;################################## ; Include ;################################## #Include<file.au3> ;################################## ; Variables ;################################## $SmtpServer = "MailServer" ; address for the smtp-server to use - REQUIRED $FromName = "Name" ; name from who the email was sent $FromAddress = "your@Email.Address.com" ; address from where the mail should come $ToAddress = "your@Email.Address.com" ; destination address of the email - REQUIRED $Subject = "Userinfo" ; subject from the email - can be anything you want it to be $Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed $CcAddress = "CCadress1@test.com" ; address for cc - leave blank if not needed $BccAddress = "BCCadress1@test.com" ; address for bcc - leave blank if not needed $Importance = "Normal" ; Send message priority: "High", "Normal", "Low" $Username = "******" ; username for the account used from where the mail gets sent - REQUIRED $Password = "********" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS $tls = 0 ; enables/disables TLS when required ;~ $SmtpServer = "smtp.gmail.com" ; GMAIL address for the smtp-server to use - REQUIRED ;~ $IPPort=465 ; GMAIL port used for sending the mail ;~ $ssl=1 ; GMAIL enables/disables secure socket layer sending - put to 1 if using https ;~ $SmtpServer = "smtp.office365.com" ; O365 address for the smtp-server to use - REQUIRED ;~ $IPPort=25 ; O365 port used for sending the mail ;~ $ssl=1 ; O365 enables/disables secure socket layer sending - put to 1 if using https ;~ SmtpServer = "smtp.mail.yahoo.com" ; Yahoo address for the smtp-server to use - REQUIRED ;~ $IPPort = 465 ; Yahoo port used for sending the mail ;~ $ssl = 1 ; Yahoo enables/disables secure socket layer sending - put to 1 if using https ;################################## ; Script ;################################## Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl, $tls) If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc) EndIf ; ; The UDF Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0, $tls = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf If $s_AttachFiles <> "" Then Local $S_Files2Attach = StringSplit($s_AttachFiles, ";") For $x = 1 To $S_Files2Attach[0] $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x]) ;~ ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console If FileExists($S_Files2Attach[$x]) Then ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF) $objEmail.AddAttachment($S_Files2Attach[$x]) Else ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF) SetError(1) Return 0 EndIf Next EndIf $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 then $IPPort = 25 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf ; Set security params If $ssl Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True If $tls Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendtls") = True ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then SetError(2) Return $oMyRet[1] EndIf $objEmail="" EndFunc ;==>_INetSmtpMailCom ; ; ; Com Error Handler Func MyErrFunc() $HexNumber = Hex($oMyError.number, 8) $oMyRet[0] = $HexNumber $oMyRet[1] = StringStripWS($oMyError.description, 3) ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF) SetError(1); something to check for when this function returns Return EndFunc ;==>MyErrFunc Edit: Fixed Bcc ... Edit: Added support for different port and SLL which are used by GMail (Port 465) Edit: Added Importance support (10/2008) EDIT: Added $TLS option (07/2020 Some interesting Info from the thread:
    1 point
  3. That message box is not from that script. Try again? I think you used two example scripts and got confused about which you were running
    1 point
  4. Try adding this in your code to convert the name to utf-8 encoded base64: $s_FromName = "Jos ąćę" ; name from who the email was sent $s_Fromname = "=?utf-8?B?" & _Base64Encode(BinaryToString(StringToBinary($s_FromName,4),1)) & '?=' Func _Base64Encode($vInput) Local Const $CRYPT_STRING_BASE64 = 0x00000001 Local Const $CRYPT_STRING_NOCRLF = 0x40000000 $vInput = Binary($vInput) Local $tInput = DllStructCreate("byte[" & BinaryLen($vInput) & "]") DllStructSetData($tInput, 1, $vInput) Local $aCall = DllCall("Crypt32.dll", "bool", "CryptBinaryToStringA", _ "struct*", $tInput, _ "dword", DllStructGetSize($tInput), _ "dword", $CRYPT_STRING_BASE64 + $CRYPT_STRING_NOCRLF , _ "ptr", 0, _ "dword*", 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, "") ; error calculating the length of the needed buffer Local $tOut = DllStructCreate("char[" & $aCall[5] & "]") $aCall = DllCall("Crypt32.dll", "int", "CryptBinaryToStringA", _ "struct*", $tInput, _ "dword", DllStructGetSize($tInput), _ "dword", $CRYPT_STRING_BASE64 + $CRYPT_STRING_NOCRLF, _ "struct*", $tOut, _ "dword*", DllStructGetSize($tOut)) If @error Or Not $aCall[0] Then Return SetError(2, 0, ""); error encoding Return DllStructGetData($tOut, 1) EndFunc This seems to working for me.... maybe there is an other/simpler way, but this worked for me. Jos
    1 point
  5. 1 point
  6. I didn't really! Just a Google search led me to the CodeProject page, which I linked in this topic earlier. https://www.autoitscript.com/forum/topic/204723-non-focusable-gui-does-not-give-focus-after-calling-evil-functions/?do=findComment&comment=1471613 At first I didn't check it throughly, so couldn't notice that he wasn't using GetCaretPos but the GetGUIThreadInfo instead. Perhaps you might not have pursued this if Mikell did not make the comment about the AutoIt documentation regarding GETGUIThreadInfo 1 post later. Anyway, good job, must feel pretty nice now
    1 point
  7. If you don't want Desktop and Windows Explorer to trigger, the CodeProject link had one extra step checking for something like this.. $sActiveProcess = WinGetText (_WinAPI_GetForegroundWindow ( )) if StringInStr($sActiveProcess, "explorer") = 0 and not $sActiveProcess = "" then ; Do Stuff endif
    1 point
  8. ...and I should now seriously look at that code and comment on it in a professional manner after posted that BS? I am sorry, but I am not going to spent any more energy on that other than typing this post. enjoy
    1 point
  9. @Jos just one little code optimization: instead of $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 then $IPPort = 25 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf ; Set security params If $ssl Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True If $tls Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendtls") = True use this, where repeating string "http://schemas.microsoft.com/cdo/configuration/" is in variable (only once): $schema_cfg = "http://schemas.microsoft.com/cdo/configuration/" $objEmail.Configuration.Fields.Item ($schema_cfg & "sendusing") = 2 $objEmail.Configuration.Fields.Item ($schema_cfg & "smtpserver") = $s_SmtpServer If Number($IPPort) = 0 then $IPPort = 25 $objEmail.Configuration.Fields.Item ($schema_cfg & "smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item ($schema_cfg & "smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item ($schema_cfg & "sendusername") = $s_Username $objEmail.Configuration.Fields.Item ($schema_cfg & "sendpassword") = $s_Password EndIf ; Set security params If $ssl Then $objEmail.Configuration.Fields.Item ($schema_cfg & "smtpusessl") = True If $tls Then $objEmail.Configuration.Fields.Item ($schema_cfg & "sendtls") = True
    1 point
  10. mLipok

    STUN UDF

    Added to the WIKI: https://www.autoitscript.com/wiki/User_Defined_Functions#Internet_protocol_suite
    1 point
  11. TurionAltec

    Winsock UDF

    On the UDF, one feature I like is immediately knowing the IP/port of an incoming client. I've been looking at implementing application level IP filtering. It also looks like TCPRecv will actually respond correctly if the connection is closed. As I recall the built in TCPRecv has been broken in this regard for years. TCP Keepalive I've run into problems where idle connections are dropped from stateful firewalls. Usually after an hour or so, or they drop off a list as being unused (if there's a maximum number of connections). The socket will still appear to be active on both sides, but if the server tries to send data it will fail and close the connection on that side. The client will still think it's connected until it tries to send data. As well if the server PC were to crash, the client would never know. Ideally there you should have an application level Keepalive, for example Telnet command 0xFFF1, sent from both sides periodically to determine if the link is down, and to keep the connection active in any intermediate routers and firewalls. The TCP stack has an "SO_KEEPALIVE" option. An example of an application that can use this is the "Connection" configuration for PuTTY. The time for no activity before firing a keepalive is set by the registry entry "KeepAliveTime". The default is 2 hours which is too long, 300,000ms (5 minutes) is a good recommendation. I wouldn't want to venture below 1 minute. These keepalives should keep your connection active in any firewalls, and will alert your application if the connection is broken. This option is off by default and must be enabled on a per connection basis. Here's a "_TCPKeepAlive()" function that's a good fit for this UDF. @j0kky's use of Winsock API let me bluff my way around DllCall. ; #FUNCTION# ==================================================================================================================== ; Name...........: _TCPKeepAlive ; Description ...: Set SO_KEEPALIVE Socket Option to enable stack level keepalive ; Syntax.........: _TCPKeepAlive($iMainsocket) ; Parameters ....: $iMainsocket - The array as returned by _TCPAccept ; or the connected socket identifier (SocketID) as returned by _TCPListen and _TCPConnect. ; Return values .: On success it returns: ; |0 - Success. ; On failure it returns -1 and sets @error to non zero: ; |-1 - internal error ; |-2 - missing DLL (Ws2_32.dll) ; |-3 - undefined error ; |Any Windows Socket Error Code retrieved by WSAGetLastError ; Author ........: TurionAltec ; Modified ......: 0.0.1 ; Remarks .......: KeepAlive will send a keepalive packet without sending any data. ; Some Firewalls may drop idle connections which can cause problems if a connection is quiet for an hour+ ; Can also be used to detect if the other end of a connection was dropped (computer abruptly powered off) ; ; Delay with no traffic before sending packet set globally from registry key: ; HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\KeepAliveTime ; Default is 7200000 (1 hour) Recommended is 300000 (5 minutes) ; ; "On Windows Vista and later, the SO_KEEPALIVE socket option can only be set using the setsockopt function ; when the socket is in a well-known state not a transitional state." ; ; Links .........: SO_KEEPALIVE: https://msdn.microsoft.com/en-us/library/windows/desktop/ee470551(v=vs.85).aspx ; setsockopt function: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740476(v=vs.85).aspx ; KeepAliveTime Reg Entry: https://technet.microsoft.com/en-us/library/dd349797(v=ws.10).aspx#BKMK_2 ; =============================================================================================================================== Func _TCPKeepAlive($iMainsocket) If IsArray($iMainsocket) And (UBound($iMainsocket, 0) = 1) And (UBound($iMainsocket) > 0) Then $iMainsocket = $iMainsocket[0] Local $SOL_SOCKET = 0xffff Local $SO_KEEPALIVE = 0x0008 Local $hWs2 = DllOpen("Ws2_32.dll") If @error Then Return SetError(-2, 0, -1) ;missing DLL Local $bError = 0, $nCode = 0, $nExtended = 0 If Not $bError Then $aRet = DllCall($hWs2, "int", "setsockopt", "uint", $iMainsocket, "int", $SOL_SOCKET, "int", $SO_KEEPALIVE, "int*", 1, "int", 4) ;MSDN calls for "char*" not "int*", but DLLCall returns @Error=1 for char If @error Then $bError = -1 ElseIf $aRet[0] <> 0 Then ;SOCKET_ERROR $bError = 1 EndIf EndIf If $bError < 0 Then $nCode = -1 ;internal error $nReturn = -1 ;failure ElseIf $bError > 0 Then If Not $nCode Then $aRet = DllCall($hWs2, "int", "WSAGetLastError") If @error Then $nCode = -1 Else $nCode = $aRet[0] EndIf If $nCode = 0 Then $nCode = -3 ;undefined error EndIf If $nCode = -10 Then $nCode = 0 $nReturn = -1 Else $nReturn = $aRet EndIf DllClose($hWs2) Return SetError($nCode, 0, $nReturn) EndFunc ;==>_TCPKeepAlive KeepAliveTime.reg: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters] "KeepAliveTime"=dword:000493e0 ;Hex 493e0 = Decimal 300000 ;300,000 ms = 5 minutes I call _TCPKeepAlive() after _TCPAccept(), or _TCPConnect() return a good socket identifier. Note that MSDN says the sockets must not be in a transitional state… I found the included example scripts a little wonky, but below is a Wireshark Trace. I had sent the KeepAliveTime to 10 seconds for demonstration on the server, 10.0.0.2. "A TCP keep-alive packet is simply an ACK with the sequence number set to one less than the current sequence number for the connection. A host receiving one of these ACKs will respond with an ACK for the current sequence number." Now if only I can figure out how to set keepalive on sockets owned by another application!
    1 point
  12. Jon

    Forum Rules

    We want the forum to be a pleasant place for everyone to discuss AutoIt scripting, and we also want to protect the reputation of AutoIt. So we ask you to respect these simple rules while you are here: Forum Posting 1. Do not ask for help with AutoIt scripts, post links to, or start discussion topics on the following subjects: Malware of any form - trojan, virus, keylogger, spam tool, "joke/spoof" script, etc. Bypassing of security measures - log-in and security dialogs, CAPTCHAs, anti-bot agents, software activation, etc. Automation of software/sites contrary to their EULA (see Reporting bullet below). Launching, automation or script interaction with games or game servers, regardless of the game. Running or injecting any code (in any form) intended to alter the original functionality of another process. Decompilation of AutoIt scripts or details of decompiler software. This list is non-exhaustive - the Moderating team reserve the right to close any thread that they feel is contrary to the ethos of the forum. 2. Do not post material that could be considered pornographic, violent or explicit - or express personal opinions that would not be acceptable in a civilized society. Do not post any copyrighted material unless the copyright is owned by you or by this site. 3. To protect this community, any files posted by you are subject to checks to ensure that they do not contain malware. This includes, but is not limited to, decompilation and reverse engineering. 4. Do not flame or insult other members - and just report the thread to a Moderator (see below) if you are so attacked. 5. Do not PM other users asking for support - that is why the forum exists, so post there instead. 6. Do not create multiple accounts - if you inadvertently created multiple accounts then contact a Moderator to close the unwanted ones. 7. Do not repost the same question if the previous thread has been locked - particularly if you merely reword the question to get around one of the prohibitions listed above. 8. Do not delete your posts, nor completely remove their content, if doing so will interrupt the flow of the thread. 9. Do not post in a thread while the Moderating team are actively trying to determine whether it is legal. The Moderation team will do their best to act in fair and reasonable manner. Sanctions will only be applied as a last resort and any action taken will be explained in the relevant thread. If moderation action is taken, you will need to acknowledge this through a dialog or you will be unable to post further in the forum. Please note that this dialog is not an agreement that the warning was justified - it is only there so that members are aware that moderation action has been taken and that they may have certain restrictions applied to their account. If you feel that you have been unfairly moderated then contact the Moderator concerned - using a PM or the "Report" button is preferable to opening a new thread (although new members may have to do this). But do be aware that the Moderation team has the final word - the rules are set out by the site owner and you are only welcome here if you respect his wishes. Signatures and Avatars There is no formal policy for the use of signatures but if a moderator thinks it is too big and/or distracting then you may be asked to tone it down. No-one likes wading through signatures that are a page high. Similarly for avatars, expect distracting flashing and animated gifs to be removed. Reporting If you feel a post needs Moderator attention, please use the "Report" button next to the post date at the top. You can then enter details of why you have reported the post - but there is no need to include the content of the post as that is done automatically. The Moderating team will be alerted to the post and will deal with it as soon as they can. If you suspect a EULA violation, do not expect the Moderating team to do all the work - please provide some evidence in the report such as a copy of (or link to) the EULA in question, as well as the section you believe has been violated. Finally, please do not enter into an argument with the original poster - that is why we have Moderators. Spam Please do not react to spam in any way other than reporting it. Multiple reports are combined by the forum software, so there is no need to announce that you have reported the spam - in fact doing so only increases the work for the Moderator who deals with it. Interacting with this website Anyone found abusing the website is subject to harsh punishment without warning. A non-exhaustive list of potential abuses include: Automated forum registration or login. Automated posting or sending messages on the forum. Automated manipulation of polls, user reputation or other forum features. Automated creation or comments on issue tracker tickets. Automated creation or editing of wiki pages. Other abuses which are either examples of excessive bandwidth usage or automation of the site. Use common sense. If you do not have common sense, don't do anything. Do not automate the forum, wiki or issue tracker in any way at all. Scripts which automatically update AutoIt such as AutoUpdateIt are acceptable as long as they are not abused and do not generate excessive bandwidth usage.
    1 point
  13. Here are another three methods of converting the three colour values to a RGB colour. Note the ease of of identifying RGB colours in 0xRRGGBB hexadecimal format. e.g. 0x0000FF if blue (blue color channel is full); 0xFF0000 is red (red color channel is full); 0x000000 if black (no color in any of the color channels); 0xFFFFFF is white (all color channels are full). Local $red = 0x80 Local $green = 0x90 Local $blue = 255 ConsoleWrite("The three color channels are:-" & @LF) ConsoleWrite("red = 0x" & Hex($red, 2) & " or " & $red & "; " & @LF) ConsoleWrite("green = 0x" & Hex($green, 2) & " or " & $green & "; " & @LF) ConsoleWrite("blue = 0x" & Hex($blue, 2) & " or " & $blue & "; " & @LF) ;--- Using String to number - color channels to color -------------- Local $color = Execute("0x" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2)) ; Use either Execute(), Int(), or Number() function. ConsoleWrite("RGB Color Execute String" & @TAB & "0x" & Hex($color, 6) & " or " & $color & @LF) ;--- Multiply & Add color channels together to get color ------------ Local $colorAddMulti = ($red * 0x10000 + $green * 0x100 + $blue) ConsoleWrite("RGB Color Add/Multiply " & @TAB & "0x" & Hex($colorAddMulti, 6) & " or " & $colorAddMulti & @LF) ; --- Using Bit operators - color channels to color ---------------- Local $colorBitWise = BitOR(BitShift(($red), -16), BitShift(($green), -8), ($blue)) ConsoleWrite("RGB Color Bit operations" & @TAB & "0x" & Hex($colorBitWise, 6) & " or " & $colorBitWise & @LF) #cs Output:- The three color channels are:- red = 0x80 or 128; green = 0x90 or 144; blue = 0xFF or 255; RGB Color Execute String 0x8090FF or 8425727 RGB Color Add/Multiply 0x8090FF or 8425727 RGB Color Bit operations 0x8090FF or 8425727 #ce
    1 point
×
×
  • Create New...