DeathSpree Posted September 20, 2013 Posted September 20, 2013 Hello, I got a working Multi-Threading Script from> here And now I changed the script for my use expandcollapse popup#include <Process.au3> Opt("TrayAutoPause", 0) Opt("TrayMenuMode", 1) Opt("TrayOnEventMode", 1) TraySetOnEvent(-13, "FExit") Global $IP = "203.117.124." Global $Port = 7456 Global $ServerList Global $Percent = 0.7874015748031496 Global $CurrentPercent = 0 Const $SCKTCPPROTOCOL = 0 Const $SCKUDPPROTOCOL = 1 Const $SCKCONNECTED = 7 Const $SCKERROR = 9 Main() Func Main() Local $CurrentIP, $hThread, $Struct $hThread = DllCallbackRegister("CheckThread", "int", "ptr") TCPStartup() SplashTextOn("GGServerFinder", "Finding Working Servers - 0%", 250, 44, Default, Default, 1) For $i = 0 To 127 $Struct = DllStructCreate("int Num;") DllStructSetData($Struct, 1, $i) CreateThread($hThread, $Struct) Next TCPShutdown() SplashOff() $Struct = 0 ;Free the allocated memory MsgBox(64, "Working Servers", $ServerList) EndFunc ;==> Main Func CheckThread($Data) Local $Pointer, $Num, $Socket $Num = DllStructGetData($Data, "Num") $CurrentPercent += $Percent ControlSetText("GGServerFinder", "", "Static1", "Finding Working Servers - " & String(Round($CurrentPercent)) & "%") $CurrentIP = $IP & String($Num) $Socket = _TCPConnect( $CurrentIP, $Port, 1000 ) If (@error) Then Return $ServerList &= $CurrentIP & @CRLF TCPCloseSocket($Socket) EndFunc ;==> CheckThread Func _TCPConnect($sIPAddr, $iPort, $iTimeOut = -1) Local $hWs2 = DllOpen("Ws2_32.dll") Local $iDllErr, $fError = False, $aRes Local $hSock = DllCall($hWs2, "uint", "socket", "int", 2, "int", 1, "int", 6) If @error Then $iDllErr = 3 ElseIf $hSock[0] = 4294967295 Or $hSock[0] = -1 Then $fError = True Else $hSock = $hSock[0] $aRes = DllCall($hWs2, "ulong", "inet_addr", "str", $sIPAddr) If @error Or $aRes[0] = -1 Or $aRes[0] = 4294967295 Then $iDllErr = 1 Else $iPort = DllCall($hWs2, "ushort", "htons", "ushort", $iPort) If @error Then $iDllErr = 2 Else $iPort = $iPort[0] EndIf EndIf If 0 = $iDllErr Then Local $tSockAddr = DllStructCreate("short sin_family;ushort sin_port; ulong sin_addr;char sin_zero[8];") DllStructSetData($tSockAddr, 1, 2) DllStructSetData($tSockAddr, 2, $iPort) DllStructSetData($tSockAddr, 3, $aRes[0]) If IsKeyword($iTimeOut) Or $iTimeOut = 0 Then $iTimeOut = Opt("TCPTimeout") If $iTimeOut > -1 Then DllCall($hWs2, "int", "ioctlsocket", "int", $hSock, "long", 0x8004667e, "uint*", 1) $aRes = DllCall($hWs2, "int", "connect", "int", $hSock, "ptr", DllStructGetPtr($tSockAddr), "int", DllStructGetSize($tSockAddr)) Select Case @error $iDllErr = 4 Case $aRes[0] <> 0 $aRes = DllCall($hWs2, "int", "WSAGetLastError") If Not @error And $aRes[0] = 10035 Then ContinueCase $fError = True Case $iTimeOut > -1 If IsKeyword($iTimeOut) Or $iTimeOut = 0 Then $iTimeOut = Opt("TCPTimeout") Local $t = DllStructCreate("uint;int") DllStructSetData($t, 1, 1) DllStructSetData($t, 2, $hSock) Local $to = DllStructCreate("long;long") DllStructSetData($to, 1, Floor($iTimeOut / 1000)) DllStructSetData($to, 2, Mod($iTimeOut, 1000)) $aRes = DllCall($hWs2, "int", "select", "int", $hSock, "ptr", DllStructGetPtr($t), "ptr", DllStructGetPtr($t), "ptr", 0, "ptr", DllStructGetPtr($to)) If Not @error And $aRes[0] = 0 Then $aRes = DllCall($hWs2, "int", "WSAGetLastError") If Not @error And $aRes[0] = 0 Then $iDllErr = 10060 Else $fError = True EndIf Else DllCall($hWs2, "int", "ioctlsocket", "int", $hSock, "long", 0x8004667e, "uint*", 0) EndIf EndSelect EndIf EndIf If $iDllErr Then TCPCloseSocket($hSock) $hSock = -1 ElseIf $fError Then $iDllErr = DllCall($hWs2, "int", "WSAGetLastError") If Not @error Then $iDllErr = $iDllErr[0] If $iDllErr = 0 Then $iDllErr = 5 TCPCloseSocket($hSock) $hSock = -1 EndIf DllClose($hWs2) Return SetError($iDllErr, 0, $hSock) EndFunc ;==> _TCPConnect Func CreateThread($Handle, $struct) $return = DllCall("kernel32.dll", "hwnd", "CreateThread", "ptr", 0, "dword", 0, "long", DllCallbackGetPtr($Handle), "ptr", DllStructGetPtr($struct), "long", 0, "int*", 0) Return $return[0] EndFunc ;==> CreateThread Func FExit() Exit EndFunc ;==> FExit The problem is that I get couple of errors in runtime I think I'm not correctly using DllStructSetData & DllStructCreate or just using (not using) them in the right place Thanks in advance
FireFox Posted September 20, 2013 Posted September 20, 2013 Hi, AutoIt does not support multithreading. Br, FireFox.
water Posted September 20, 2013 Posted September 20, 2013 Here's a list of things AutoIt will never do: One position on this list is Multithreading My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
DeathSpree Posted September 20, 2013 Author Posted September 20, 2013 Well , I know that autoit that will never add multi threading feature and it's not officially supported BUT, There is some trick to do this and it posted on here And other places on the forum And IF you are really (100% sure) that what I'm going to do is impossible feel free to close this thread
FireFox Posted September 20, 2013 Posted September 20, 2013 It's a simple MsgBox, but still if you read the note there is an issue.
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