Hey!
Danke Progandy! Ich versuche nun irgendwie die Connect funktion mit diesem hier zu verbinden:
http://publib.boulder.ibm.com/infocenter/ise…x2multicast.htm
Aber ich schaffe es einfach nicht. Hier ist mal was ich bisher habe, aber er hat schon ein Fehler bei dem socket Aufruf. Diesen Fehler gibt es übrigends auch bei der ürsprünglichen Funktion, die du mir geschickt hast. Er gibt mir immer 4294967295 zurück (0xFFFFFFFF).
Spoiler anzeigen
; #FUNCTION# ====================================================================================================================
; Name...........: _TCPConnect
; Description ...: Triess to establishes a TCP-connection in a specified time limit
; Syntax.........: _TCPConnect($sIPAddr, $iPort, $iTimeOut = -1)
; Parameters ....: $sIpAddr - IP address to connect to (IPv4)
; $iPort - Port to use
; $iTimeOut - Timeout for connection in milliseconds (default: -1)
; |Values < 0: default timeout
; |Values 0, Keyword Default: use time from Opt("TCPTimeout")
; |Values > 0: timeout in milliseconds
; Return values .: Success - Socket to use with TCP-functions
; Failure - -1, sets @error
; |1 - $sIpAddr incorrect
; |2 - could not get port
; |3 - could not create socket
; |4 - could not connect
; |5 - could not get WSAError
; |and errors from WSAGetLastError
; Author ........: ProgAndy
; Modified.......:
; Remarks .......:
; Related .......: TCPConnect, TCPCloseSocket, TCPSend, TCPRecv
; Link ..........:
; Example .......:
; ===============================================================================================================================
UDPStartup()
UDPBind("192.168.0.2",5555)
ConsoleWrite(@error & @CRLF);kein fehler
ConsoleWrite("_TCPConnect Return: "&_TCPConnect("192.168.0.2", 5555) & @CRLF);fehler!
Func _TCPConnect($sIPAddr, $iPort, $iTimeOut = -1)
[/autoit] [autoit][/autoit] [autoit]Local $udp = 17
[/autoit] [autoit][/autoit] [autoit]Local $hWs2 = DllOpen("Ws2_32.dll")
Local $iDllErr, $fError = False, $aRes
Local $hSock = DllCall($hWs2, "uint", "socket", "int", 2, "int", 1, "int", $udp);ipv4, sock_dgram, udp
If @error Then
$iDllErr = 3
ElseIf $hSock[0] = 4294967295 Or $hSock[0] = -1 Then
ConsoleWrite($hSock[0] & @CRLF)
$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, $udp)
DllStructSetData($tSockAddr, 2, $iPort)
DllStructSetData($tSockAddr, 3, $aRes[0])
If IsKeyword($iTimeOut) Or $iTimeOut = 0 Then $iTimeOut = Opt("TCPTimeout")
[/autoit] [autoit][/autoit] [autoit]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))
$aRes = DllCall($hWs2, "int", "bind", "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
Local $tIPmreq = DllStructCreate("ulong imr_multiaddr;ulong imr_interface")
[/autoit] [autoit][/autoit] [autoit]DllStructSetData($tIPmreq,1,"225.1.1.1")
DllStructSetData($tIPmreq,1,@IPAddress1)
DllCall($hWs2,"uint","setsockopt","int",$hSock,"int",0,"int",0,"ptr",DllStructGetPtr($tIPmreq),"int",DllStructGetSize($tIPmreq))
[/autoit] [autoit][/autoit] [autoit]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
Wäre super wenn du da mal drüber schauen könntest
Gruß
Spider