howdyho!
auch wenn ich jetzt erst auf das prog gestoßen bin: nice work.. kann man beinahe täglich gebrauchen
mfg
sgtigram
howdyho!
auch wenn ich jetzt erst auf das prog gestoßen bin: nice work.. kann man beinahe täglich gebrauchen
mfg
sgtigram
howdyho leute..
ich wende mich hier an euch weil ich einfach nicht weiterkomme!
was ich vorhabe(sollte zwar vom titel entnehmbar sein aber trotzdem) ist das ich aufgenommene daten zu einem server schicke und zu einem empfänger geschickt wird.
das habe ich auch schon vollbracht... aber:
ich möchte das mehr wie eine konferenz händeln lassen .. deshalb versuche ich die empfangenen daten von allen sendern beim server in einen stream zu mixen und erst dann allen clienten zu senden. allerdings funktioniert das irgendwie nicht =/
nachdem ich die daten zusammen mixe, muss ich die daten da erst wieder irgendwie codieren(z.b. mit der lame.exe) wie nach dem aufnehmen der daten?
muss ich sonst irgendwas beachten?
ich würde euch den code gerne senden aber das wäre ne ziemliche fummelarbeit da ich das alles ziemlich verschachtelt habe^^
mfg
sgtigram
möpmöp,
vielen dank euch beiden.. das mit dem WindowCaption wusst ich zwar schon aber trotzdem danke für den tipp.
funktioniert einwandfrei.
das problem war nämlich das TCP verbindungen und die soundengine sich im ersten moment immer gesträubt haben sich ordnungsgemäß zu schließen.. und an den server sollte ja auch eine "abmelde" nachricht geschickt werden damits kein timeout wird oder so.
muss mich wohl echt mal intensiver mit DLLCalls auseinander setzen..
mfg
sgtigram
howdy!
folgendes problem:
ich verwende IrrLicht für ein projekt und würde gerne das Icon vom fenster ändern.. hab mir mal die WinAPI funktionen durchgeschaut aber dabei nichts gefunden.. vorallem weil ich nicht weiß wie ich an den handler für das irrlicht fenster kommen sollte.
zweite sache wäre das X^^
undzwar wird versucht beim betätigen des Xs das programm abrupt zu beenden.. ich möchte aber wie es bei einer normalen GUI möglich ist eine bestimmte funktion zum beenden aufrufen um z.b. die engine erstmal ordnungsgemäßig herunterzufahren und speicher zu leeren usw. etc...
ich hab jetzt schon ne weile rumprobiert aber nichts hatte funktioniert.. hab sogar solche verzweifelten versuche wie:
[autoit]GUIRegisterMsg(0x0002,"_close")
GUIRegisterMsg(0x0010,"_close")
GUIRegisterMsg(0x0012,"_close")
...ausprobiert.. aber nix^^
mfg sgtigram
howdy!
du könntest beispielsweise, da es sich um eine installation handelt, überprüfen ob eine bestimmte datei schon erstellt wurde
mfg
sgtigram
meine idee dabei war das du ein netzlaufwerk daraus machst um darauf zugreifen zu können.. lokal beschränkt versteht sich
howdyho
nur ein gedankenspiel aber kommst du da vielleicht mit der WinNet.au3 weiter?
ich kann das hier vorort leider nicht testen da ich ein solches gerät grade nicht zur verfügung hab^^
mfg
sgtigram
also meine güte^^.. für den anderen server musst du den port natürlich bei dem clienten anpassen.. verschiedene ports haben diese jedoch.. also keine verfrühten schlüsse ziehen^^
lg chess
er meint das kompilieren damit ;D..
InetGet speichert die Datei auf dem PC.
muss nicht sein!
[autoit]$download = InetRead($variablenort,1)
$content = BinaryToString($download)
hiermit überspringt man das abspeichern in einer datei einfach!
und eine includete ini bringt auch nichts anderes als fixe werte.. wenn er sie normal ausließt über IniRead dann wäre das eine möglichkeit.. aber absolut unnötig wenn er durch mein beispiel den download direkt in einer variable hat.
*bam bam baaam*
ja natürlich!^^
das #include ist für UDFs gedacht und nicht für variable dateien^^
nutze einfach das downloadverfahren was ich gepostet hatte und darüber kannst du die variablen direkt nutzen ohne dateien erstellen zu müssen..
wenn du allerdings autoit code später in der kompilierten form ausführen lassen möchtest ist das extrem unsicher aber machbar:
Zitat
wenn irgendwelche werte "fix" sind, dann, meiner meinung nach, unterläuft beim erstellen der neuen datei irgendein fehler.. wie gesagt.. entweder wird was aus dem cache gezogen oder die vorherige datei kann nicht gelöscht werden.. lass dir das am besten immer überprüfen.. schau immer ob dir ein true zurückgegeben wird und ob dein programm auch zugriff hat.. möglicherweise fehlen die adminrechte zum anlegen der heruntergeladenen datei.. mach mal rechtsklick+als administrator ausführen bei deiner kompilierten exe.. irgendwas beschränkt die möglichkeit deine neue datei anzulegen
komm nich ganz dahinter was da eigentlich genau abgeht aber stell am besten sicher das nichts aus dem cache geholt wird und du die werte immer neu lädst. und solange du nicht fileinstall bei deiner heruntergeladenen datei verwendest, fällt mir nicht ein wieso dein programm sich so verhält
also... nur um festzuhalten..
nach dem kompilieren deines scripts, führt dein programm den download nichtmehr aus sondern greift auf einen wert vor(während) dem kompilieren zurück???
klingt nämlich etwas eigenartig^^
Was soll das eigentlich für eine "TCP.au3" sein?
TCP UDF von Kip
#cs ----------------------------------------------------------------------------
[/autoit] [autoit][/autoit] [autoit]AutoIt Version: 3.3.0.0
Author: Kip
Script Function:
TCP UDF v3
#ce ----------------------------------------------------------------------------
[/autoit] [autoit][/autoit] [autoit]; Script Start - Add your code below here
[/autoit] [autoit][/autoit] [autoit]#cs
[/autoit] [autoit][/autoit] [autoit]Functions:
[/autoit] [autoit][/autoit] [autoit]_TCP_Server_Create($iPort, $sIP="0.0.0.0")
_TCP_Server_Broadcast($sData)
_TCP_Server_ClientList()
_TCP_Server_ClientIP($hSocket)
_TCP_Server_DisconnectClient($hSocket)
_TCP_Server_Stop()
_TCP_Client_Create($sIP , $iPort)
_TCP_Client_Stop($hSocket)
_TCP_Send($hSocket, $sText)
_TCP_RegisterEvent($hSocket, $iEvent, $sFunction)
Register event values:
[/autoit] [autoit][/autoit] [autoit]$TCP_SEND ; Function ($hSocket, $iError)
$TCP_RECEIVE ; Function ($hSocket, $sReceived, $iError)
$TCP_CONNECT ; Function ($hSocket, $iError) => Client only
$TCP_DISCONNECT ; Function ($hSocket, $iError)
$TCP_NEWCLIENT ; Function ($hSocket, $iError) => Server only
#ce
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Global Const $FD_READ = 1
Global Const $FD_WRITE = 2
Global Const $FD_OOB = 4
Global Const $FD_ACCEPT = 8
Global Const $FD_CONNECT = 16
Global Const $FD_CLOSE = 32
Global $hWs2_32 = -1
Global Const $TCP_SEND = 1
Global Const $TCP_RECEIVE = 2
Global Const $TCP_CONNECT = 4
Global Const $TCP_DISCONNECT = 8
Global Const $TCP_NEWCLIENT = 16
TCPStartup()
Global Const $__TCP_WINDOW = GUICreate("Async Sockets UDF")
Global $__TCP_SOCKETS[1][7]
; #FUNCTION# ;===============================================================================
;
; Name...........: _TCP_Server_Create
; Description ...: Initializes the server.
; Syntax.........: _TCP_Server_Create($iPort, $sIP="0.0.0.0")
; Parameters ....: $iPort - The port number the server should listen to.
; $sIP - IP address. (Default = "0.0.0.0")
; Return values .: The socket handle.
; Author ........: Kip
; Modified.......:
; Remarks .......: Only 1 server can be created per script.
; Related .......:
; Link ..........;
; Example .......;
;
; ;==========================================================================================
Func _TCP_Server_Create($iPort, $sIP="0.0.0.0")
[/autoit] [autoit][/autoit] [autoit]Global $hListenSocket = ___ASocket()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]___ASockSelect( $hListenSocket, $__TCP_WINDOW, 0x0400, $FD_ACCEPT)
GUIRegisterMsg( 0x0400, "___TCP_OnAccept" )
___ASockListen( $hListenSocket, $sIP, $iPort )
[/autoit] [autoit][/autoit] [autoit]$__TCP_SOCKETS[0][0] = $hListenSocket
$__TCP_SOCKETS[0][1] = 0x0400
Return $hListenSocket
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func ___TCP_OnAccept($hWnd, $iMsgID, $WParam, $LParam)
[/autoit] [autoit][/autoit] [autoit]Local $hSocket = $WParam
Local $iError = ___HiWord( $LParam )
Local $iEvent = ___LoWord( $LParam )
Local $hClient, $uBound
[/autoit] [autoit][/autoit] [autoit]Abs($hWnd) ; Stupid AU3Check...
If IsArray($__TCP_SOCKETS) Then
If $iMsgID = $__TCP_SOCKETS[0][1] Then
If $iEvent = $FD_ACCEPT Then
[/autoit] [autoit][/autoit] [autoit]If Not $iError Then
[/autoit] [autoit][/autoit] [autoit]ReDim $__TCP_SOCKETS[UBound($__TCP_SOCKETS)+1][7]
$uBound = UBound($__TCP_SOCKETS)
$hClient = TCPAccept($hSocket)
[/autoit] [autoit][/autoit] [autoit]___ASockSelect($hClient, $__TCP_WINDOW, 0x0400 + $uBound - 1, BitOR($FD_READ, $FD_WRITE, $FD_CLOSE))
GUIRegisterMsg(0x0400 + $uBound - 1, "___TCP_Server_OnSocketEvent" )
$__TCP_SOCKETS[UBound($__TCP_SOCKETS)-1][0] = $hClient
$__TCP_SOCKETS[UBound($__TCP_SOCKETS)-1][1] = 0x0400 + $uBound - 1
Call($__TCP_SOCKETS[0][6], $hClient, $iError)
[/autoit] [autoit][/autoit] [autoit]Else
[/autoit] [autoit][/autoit] [autoit]Call($__TCP_SOCKETS[0][6], 0, $iError)
[/autoit] [autoit][/autoit] [autoit]EndIf
[/autoit] [autoit][/autoit] [autoit]ElseIf $iEvent = $FD_CONNECT Then
[/autoit] [autoit][/autoit] [autoit]Call($__TCP_SOCKETS[0][4], $hSocket, $iError)
[/autoit] [autoit][/autoit] [autoit]EndIf
[/autoit] [autoit][/autoit] [autoit]EndIf
EndIf
EndFunc
; #FUNCTION# ;===============================================================================
;
; Name...........: _TCP_Client_Stop
; Description ...: Stops the client.
; Syntax.........: _TCP_Client_Stop($hSocket)
; Parameters ....: $hSocket - Client socket.
; Return values .: Success - True
; Failure - False
; Author ........: Kip
; Modified.......:
; Remarks .......: The client socket is the return value of _TCP_Client_Create().
; Related .......:
; Link ..........;
; Example .......;
;
; ;==========================================================================================
Func _TCP_Client_Stop($hSocket)
Local $iElement, $i
$iElement = 0
[/autoit] [autoit][/autoit] [autoit]For $i = 1 to UBound($__TCP_SOCKETS)-1
[/autoit] [autoit][/autoit] [autoit]If $__TCP_SOCKETS[$i][0] = $hSocket Then
$iElement = $i
ExitLoop
EndIf
Next
[/autoit] [autoit][/autoit] [autoit]If $iElement Then
[/autoit] [autoit][/autoit] [autoit]___ASockShutdown($__TCP_SOCKETS[$iElement][0])
TCPCloseSocket($__TCP_SOCKETS[$iElement][0])
___ArrayDelete($__TCP_SOCKETS, $iElement)
[/autoit] [autoit][/autoit] [autoit]Return True
[/autoit] [autoit][/autoit] [autoit]EndIf
[/autoit] [autoit][/autoit] [autoit]Return False
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]; #FUNCTION# ;===============================================================================
;
; Name...........: _TCP_Server_Stop
; Description ...: Stops the server, and closes all client connections.
; Syntax.........: _TCP_Server_Stop()
; Parameters ....:
; Return values .: True
; Author ........: Kip
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
;
; ;==========================================================================================
Func _TCP_Server_Stop()
[/autoit] [autoit][/autoit] [autoit]Local $i
[/autoit] [autoit][/autoit] [autoit]___ASockShutdown($__TCP_SOCKETS[0][0])
TCPCloseSocket($__TCP_SOCKETS[0][0])
$__TCP_SOCKETS[0][0] = ""
$__TCP_SOCKETS[0][1] = ""
$__TCP_SOCKETS[0][2] = ""
$__TCP_SOCKETS[0][3] = ""
$__TCP_SOCKETS[0][4] = ""
$__TCP_SOCKETS[0][5] = ""
$__TCP_SOCKETS[0][6] = ""
For $i = UBound($__TCP_SOCKETS)-1 to 1 Step -1
___ArrayDelete($__TCP_SOCKETS, $i)
Next
Return True
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func ___TCP_Server_OnSocketEvent( $hWnd, $iMsgID, $WParam, $LParam )
[/autoit] [autoit][/autoit] [autoit]Local $hSocket = $WParam
Local $iError = ___HiWord( $LParam )
Local $iEvent = ___LoWord( $LParam )
Local $sDataBuff, $iElement, $i
[/autoit] [autoit][/autoit] [autoit]Abs($hWnd)
[/autoit] [autoit][/autoit] [autoit]$hSocket = 0
$iElement = 0
For $i = 1 to UBound($__TCP_SOCKETS)-1
[/autoit] [autoit][/autoit] [autoit]If $__TCP_SOCKETS[$i][1] = $iMsgID Then
$hSocket = $__TCP_SOCKETS[$i][0]
$iElement = $i
ExitLoop
EndIf
Next
[/autoit] [autoit][/autoit] [autoit]If $hSocket Then
[/autoit] [autoit][/autoit] [autoit]Switch $iEvent
Case $FD_READ
$sDataBuff = TCPRecv($hSocket, 1024)
[/autoit] [autoit][/autoit] [autoit]Call($__TCP_SOCKETS[0][2], $hSocket, $sDataBuff, $iError)
[/autoit] [autoit][/autoit] [autoit]Case $FD_WRITE
[/autoit] [autoit][/autoit] [autoit]Call($__TCP_SOCKETS[0][3], $hSocket, $iError)
[/autoit] [autoit][/autoit] [autoit]Case $FD_CLOSE
[/autoit] [autoit][/autoit] [autoit]___ASockShutdown($hSocket)
TCPCloseSocket($hSocket)
Call($__TCP_SOCKETS[0][5], $hSocket, $iError)
[/autoit] [autoit][/autoit] [autoit]___ArrayDelete($__TCP_SOCKETS, $iElement)
[/autoit] [autoit][/autoit] [autoit]EndSwitch
[/autoit] [autoit][/autoit] [autoit]EndIf
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]; #FUNCTION# ;===============================================================================
;
; Name...........: _TCP_Server_DisconnectClient
; Description ...: Disconnects a client of the server.
; Syntax.........: _TCP_Server_DisconnectClient($hSocket)
; Parameters ....: $hSocket - Client socket.
; Return values .: Success - True
; Failure - False
; Author ........: Kip
; Modified.......:
; Remarks .......: The client socket is the $hSocket parameter of a _TCP_RegisterEvent callback function.
; Related .......:
; Link ..........;
; Example .......;
;
; ;==========================================================================================
Func _TCP_Server_DisconnectClient($hSocket)
[/autoit] [autoit][/autoit] [autoit]Local $iElement, $i
[/autoit] [autoit][/autoit] [autoit]$iElement = 0
[/autoit] [autoit][/autoit] [autoit]For $i = 1 to UBound($__TCP_SOCKETS)-1
[/autoit] [autoit][/autoit] [autoit]If $__TCP_SOCKETS[$i][0] = $hSocket Then
$iElement = $i
ExitLoop
EndIf
Next
[/autoit] [autoit][/autoit] [autoit]If $iElement Then
[/autoit] [autoit][/autoit] [autoit]___ASockShutdown($hSocket)
TCPCloseSocket($hSocket)
___ArrayDelete($__TCP_SOCKETS, $iElement)
[/autoit] [autoit][/autoit] [autoit]Return True
[/autoit] [autoit][/autoit] [autoit]EndIf
[/autoit] [autoit][/autoit] [autoit]Return False
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]; #FUNCTION# ;===============================================================================
;
; Name...........: _TCP_Server_ClientList
; Description ...: Returns the sockets of all connected clients.
; Syntax.........: _TCP_Server_ClientList()
; Parameters ....:
; Return values .: An 1 dimensional array of all connected clients.
; Author ........: Kip
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
;
; ;==========================================================================================
Func _TCP_Server_ClientList()
[/autoit] [autoit][/autoit] [autoit]Local $aReturn[1], $i
[/autoit] [autoit][/autoit] [autoit]For $i = 1 to UBound($__TCP_SOCKETS)-1
If $__TCP_SOCKETS[$i][0] Then
ReDim $aReturn[UBound($aReturn)+1]
$aReturn[UBound($aReturn)-1] = $__TCP_SOCKETS[$i][0]
EndIf
Next
$aReturn[0] = UBound($aReturn)-1
[/autoit] [autoit][/autoit] [autoit]Return $aReturn
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit]; #FUNCTION# ;===============================================================================
;
; Name...........: _TCP_Server_Broadcast
; Description ...: Sends data to all connected clients.
; Syntax.........: _TCP_Server_Broadcast($sData)
; Parameters ....: $sData - The data to send.
; Return values .: True
; Author ........: Kip
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
;
; ;==========================================================================================
Func _TCP_Server_Broadcast($sData)
[/autoit] [autoit][/autoit] [autoit]Local $i,$__TCP_SENDCHECK
[/autoit] [autoit][/autoit] [autoit]For $i = 1 to UBound($__TCP_SOCKETS)-1
[/autoit] [autoit][/autoit] [autoit]If $__TCP_SOCKETS[$i][0] Then
TCPSend($__TCP_SOCKETS[$i][0], $sData)
EndIf
Next
Return True
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]; #FUNCTION# ;===============================================================================
;
; Name...........: _TCP_Client_Create
; Description ...: Creates a new client.
; Syntax.........: _TCP_Client_Create($sIP , $iPort)
; Parameters ....: $sIP - The IP address to connect to.
; $iPort - Port on which the created socket will be connected.
; Return values .: Client socket handle.
; Author ........: Kip
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
;
; ;==========================================================================================
Func _TCP_Client_Create($sIP , $iPort)
[/autoit] [autoit][/autoit] [autoit]ReDim $__TCP_SOCKETS[UBound($__TCP_SOCKETS)+1][7]
[/autoit] [autoit][/autoit] [autoit]local $hSocket = ___ASocket()
[/autoit] [autoit][/autoit] [autoit]$__TCP_SOCKETS[UBound($__TCP_SOCKETS)-1][0] = $hSocket
$__TCP_SOCKETS[UBound($__TCP_SOCKETS)-1][1] = 0x0400 + (UBound($__TCP_SOCKETS)-1)
___ASockSelect( $hSocket, $__TCP_WINDOW, 0x0400 + (UBound($__TCP_SOCKETS)-1), BitOR( $FD_READ, $FD_WRITE, $FD_CONNECT, $FD_CLOSE ) )
GUIRegisterMsg( 0x0400 + (UBound($__TCP_SOCKETS)-1), "___TCP_Client_OnSocketEvent" )
___ASockConnect( $hSocket, $sIP, $iPort )
Return $hSocket
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]; #FUNCTION# ;===============================================================================
;
; Name...........: _TCP_RegisterEvent
; Description ...: Registers an event.
; Syntax.........: _TCP_RegisterEvent($hSocket, $iEvent, $sFunction)
; Parameters ....: $hSocket - Socket of the server or a client.
; $iEvent - Event number. It can be any these values:
; * $TCP_SEND
; * $TCP_RECEIVE
; * $TCP_CONNECT => Client only
; * $TCP_DISCONNECT
; * $TCP_NEWCLIENT => Server only
; Return values .: Success - True
; Failure - False
; Author ........: Kip
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
;
; ;==========================================================================================
Func _TCP_RegisterEvent($hSocket, $iEvent, $sFunction)
[/autoit] [autoit][/autoit] [autoit]Local $iSelected = 0
Local $i
If $__TCP_SOCKETS[0][0] Then
[/autoit] [autoit][/autoit] [autoit]$iSelected = 0
[/autoit] [autoit][/autoit] [autoit]Else
[/autoit] [autoit][/autoit] [autoit]For $i = 0 to UBound($__TCP_SOCKETS)-1
If $__TCP_SOCKETS[$i][0] = $hSocket Then
$iSelected = $i
ExitLoop
EndIf
Next
If Not $iSelected Then Return 0
[/autoit] [autoit][/autoit] [autoit]EndIf
[/autoit] [autoit][/autoit] [autoit]Switch $iEvent
Case $TCP_SEND
$__TCP_SOCKETS[$iSelected][3] = $sFunction
Case $TCP_RECEIVE
$__TCP_SOCKETS[$iSelected][2] = $sFunction
Case $TCP_CONNECT
$__TCP_SOCKETS[$iSelected][4] = $sFunction
Case $TCP_DISCONNECT
$__TCP_SOCKETS[$iSelected][5] = $sFunction
Case $TCP_NEWCLIENT
$__TCP_SOCKETS[$iSelected][6] = $sFunction
Case Else
Return False
EndSwitch
Return True
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]; #FUNCTION# ;===============================================================================
;
; Name...........: _TCP_Server_ClientIP
; Description ...: Converts a client socket handle to IP address.
; Syntax.........: _TCP_Server_ClientIP($hSocket)
; Parameters ....: $hSocket - Client socket handle.
; Return values .: A string with the IP address.
; Author ........: Unknown
; Modified.......: Kip
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
;
; ;==========================================================================================
Func _TCP_Server_ClientIP($hSocket)
[/autoit] [autoit][/autoit] [autoit]Local $pSocketAddress, $aReturn
[/autoit] [autoit][/autoit] [autoit]$pSocketAddress = DllStructCreate("short;ushort;uint;char[8]")
$aReturn = DllCall("Ws2_32.dll", "int", "getpeername", "int", $hSocket, "ptr", DllStructGetPtr($pSocketAddress), "int*", DllStructGetSize($pSocketAddress))
If @error Or $aReturn[0] <> 0 Then Return 0
$aReturn = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($pSocketAddress, 3))
If @error Then Return 0
$pSocketAddress = 0
[/autoit] [autoit][/autoit] [autoit]Return $aReturn[0]
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]; #FUNCTION# ;===============================================================================
;
; Name...........: _TCP_Send
; Description ...: Sends data to a server or client.
; Syntax.........: _TCP_Send($hSocket, $sText)
; Parameters ....: $hSocket - Client or server socket handle.
; $sText - Data to send.
; Return values .:
; Author ........: Kip
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
;
; ;==========================================================================================
Func _TCP_Send($hSocket, $sText)
[/autoit] [autoit][/autoit] [autoit]Return TCPSend($hSocket, $sText)
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func ___TCP_Client_OnSocketEvent( $hWnd, $iMsgID, $WParam, $LParam )
[/autoit] [autoit][/autoit] [autoit]Local $iError = ___HiWord( $LParam )
Local $iEvent = ___LoWord( $LParam )
Local $hSocket, $iElement, $i, $sDataBuff
[/autoit] [autoit][/autoit] [autoit]Abs($hWnd)
Abs($WParam)
$hSocket = 0
$iElement = 0
For $i = 1 to UBound($__TCP_SOCKETS)-1
[/autoit] [autoit][/autoit] [autoit]If $__TCP_SOCKETS[$i][1] = $iMsgID Then
$hSocket = $__TCP_SOCKETS[$i][0]
$iElement = $i
ExitLoop
EndIf
Next
[/autoit] [autoit][/autoit] [autoit]If $hSocket Then
[/autoit] [autoit][/autoit] [autoit]Switch $iEvent
Case $FD_READ; Data has arrived!
$sDataBuff = TCPRecv( $hSocket, 1024)
[/autoit] [autoit][/autoit] [autoit]Call($__TCP_SOCKETS[$i][2], $hSocket, $sDataBuff, $iError)
[/autoit] [autoit][/autoit] [autoit]$sDataBuff = ""
[/autoit] [autoit][/autoit] [autoit]Case $FD_WRITE
[/autoit] [autoit][/autoit] [autoit]Call($__TCP_SOCKETS[$i][3], $hSocket, $iError)
[/autoit] [autoit][/autoit] [autoit]Case $FD_CONNECT
[/autoit] [autoit][/autoit] [autoit]Call($__TCP_SOCKETS[$i][4], $hSocket, $iError)
[/autoit] [autoit][/autoit] [autoit]Case $FD_CLOSE
[/autoit] [autoit][/autoit] [autoit]___ASockShutdown( $hSocket )
TCPCloseSocket( $hSocket )
Call($__TCP_SOCKETS[$i][5], $hSocket, $iError)
[/autoit] [autoit][/autoit] [autoit]___ArrayDelete($__TCP_SOCKETS, $iElement)
[/autoit] [autoit][/autoit] [autoit]EndSwitch
[/autoit] [autoit][/autoit] [autoit]EndIf
[/autoit] [autoit][/autoit] [autoit]EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit];==================================================================================================================
;
; Zatorg's Asynchronous Sockets UDF Starts from here.
;
;==================================================================================================================
Func ___ASocket($iAddressFamily = 2, $iType = 1, $iProtocol = 6)
If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" )
Local $hSocket = DllCall($hWs2_32, "uint", "socket", "int", $iAddressFamily, "int", $iType, "int", $iProtocol)
If @error Then
SetError(1, @error)
Return -1
EndIf
If $hSocket[ 0 ] = -1 Then
SetError(2, ___WSAGetLastError())
Return -1
EndIf
Return $hSocket[ 0 ]
EndFunc ;==>_ASocket
Func ___ASockShutdown($hSocket)
If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" )
Local $iRet = DllCall($hWs2_32, "int", "shutdown", "uint", $hSocket, "int", 2)
If @error Then
SetError(1, @error)
Return False
EndIf
If $iRet[ 0 ] <> 0 Then
SetError(2, ___WSAGetLastError())
Return False
EndIf
Return True
EndFunc ;==>_ASockShutdown
Func ___ASockClose($hSocket)
If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" )
Local $iRet = DllCall($hWs2_32, "int", "closesocket", "uint", $hSocket)
If @error Then
SetError(1, @error)
Return False
EndIf
If $iRet[ 0 ] <> 0 Then
SetError(2, ___WSAGetLastError())
Return False
EndIf
Return True
EndFunc ;==>_ASockClose
Func ___ASockSelect($hSocket, $hWnd, $uiMsg, $iEvent)
If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" )
Local $iRet = DllCall( _
$hWs2_32, _
"int", "WSAAsyncSelect", _
"uint", $hSocket, _
"hwnd", $hWnd, _
"uint", $uiMsg, _
"int", $iEvent _
)
If @error Then
SetError(1, @error)
Return False
EndIf
If $iRet[ 0 ] <> 0 Then
SetError(2, ___WSAGetLastError())
Return False
EndIf
Return True
EndFunc ;==>_ASockSelect
; Note: you can see that $iMaxPending is set to 5 by default.
; IT DOES NOT MEAN THAT DEFAULT = 5 PENDING CONNECTIONS
; 5 == SOMAXCONN, so don't worry be happy
Func ___ASockListen($hSocket, $sIP, $uiPort, $iMaxPending = 5); 5 == SOMAXCONN => No need to change it.
Local $iRet
Local $stAddress
If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" )
[/autoit] [autoit][/autoit] [autoit]$stAddress = ___SockAddr($sIP, $uiPort)
If @error Then
SetError(@error, @extended)
Return False
EndIf
$iRet = DllCall($hWs2_32, "int", "bind", "uint", $hSocket, "ptr", DllStructGetPtr($stAddress), "int", DllStructGetSize($stAddress))
If @error Then
SetError(3, @error)
Return False
EndIf
If $iRet[ 0 ] <> 0 Then
$stAddress = 0; Deallocate
SetError(4, ___WSAGetLastError())
Return False
EndIf
$iRet = DllCall($hWs2_32, "int", "listen", "uint", $hSocket, "int", $iMaxPending)
If @error Then
SetError(5, @error)
Return False
EndIf
If $iRet[ 0 ] <> 0 Then
$stAddress = 0; Deallocate
SetError(6, ___WSAGetLastError())
Return False
EndIf
Return True
EndFunc ;==>_ASockListen
Func ___ASockConnect($hSocket, $sIP, $uiPort)
Local $iRet
Local $stAddress
If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" )
[/autoit] [autoit][/autoit] [autoit]$stAddress = ___SockAddr($sIP, $uiPort)
If @error Then
SetError(@error, @extended)
Return False
EndIf
$iRet = DllCall($hWs2_32, "int", "connect", "uint", $hSocket, "ptr", DllStructGetPtr($stAddress), "int", DllStructGetSize($stAddress))
If @error Then
SetError(3, @error)
Return False
EndIf
$iRet = ___WSAGetLastError()
If $iRet = 10035 Then; WSAEWOULDBLOCK
Return True; Asynchronous connect attempt has been started.
EndIf
SetExtended(1); Connected immediately
Return True
EndFunc ;==>_ASockConnect
; A wrapper function to ease all the pain in creating and filling the sockaddr struct
Func ___SockAddr($sIP, $iPort, $iAddressFamily = 2)
Local $iRet
Local $stAddress
If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" )
[/autoit] [autoit][/autoit] [autoit]$stAddress = DllStructCreate("short; ushort; uint; char[8]")
If @error Then
SetError(1, @error)
Return False
EndIf
DllStructSetData($stAddress, 1, $iAddressFamily)
$iRet = DllCall($hWs2_32, "ushort", "htons", "ushort", $iPort)
DllStructSetData($stAddress, 2, $iRet[ 0 ])
$iRet = DllCall($hWs2_32, "uint", "inet_addr", "str", $sIP)
If $iRet[ 0 ] = 0xffffffff Then; INADDR_NONE
$stAddress = 0; Deallocate
SetError(2, ___WSAGetLastError())
Return False
EndIf
DllStructSetData($stAddress, 3, $iRet[ 0 ])
Return $stAddress
EndFunc ;==>__SockAddr
Func ___WSAGetLastError()
If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" )
Local $iRet = DllCall($hWs2_32, "int", "WSAGetLastError")
If @error Then
;ConsoleWrite("+> _WSAGetLastError(): WSAGetLastError() failed. Script line number: " & @ScriptLineNumber & @CRLF)
SetExtended(1)
Return 0
EndIf
Return $iRet[ 0 ]
EndFunc ;==>_WSAGetLastError
; Got these here:
; http://www.autoitscript.com/forum/index.ph…620&hl=MAKELONG
Func ___MakeLong($LoWord, $HiWord)
Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF)); Thanks Larry
EndFunc ;==>_MakeLong
Func ___HiWord($Long)
Return BitShift($Long, 16); Thanks Valik
EndFunc ;==>_HiWord
Func ___LoWord($Long)
Return BitAND($Long, 0xFFFF); Thanks Valik
EndFunc ;==>_LoWord
; ========================================= Array functions
[/autoit] [autoit][/autoit] [autoit]; #FUNCTION# ====================================================================================================================
; Name...........: _ArrayDelete
; Description ...: Deletes the specified element from the given array.
; Syntax.........: _ArrayDelete(ByRef $avArray, $iElement)
; Parameters ....: $avArray - Array to modify
; $iElement - Element to delete
; Return values .: Success - New size of the array
; Failure - 0, sets @error to:
; |1 - $avArray is not an array
; |3 - $avArray has too many dimensions (only up to 2D supported)
; |(2 - Deprecated error code)
; Author ........: Cephas <cephas at clergy dot net>
; Modified.......: Jos van der Zande <jdeb at autoitscript dot com> - array passed ByRef, Ultima - 2D arrays supported, reworked function (no longer needs temporary array; faster when deleting from end)
; Remarks .......: If the array has one element left (or one row for 2D arrays), it will be set to "" after _ArrayDelete() is used on it.
; Related .......: _ArrayAdd, _ArrayInsert, _ArrayPop, _ArrayPush
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func ___ArrayDelete(ByRef $avArray, $iElement)
If Not IsArray($avArray) Then Return SetError(1, 0, 0)
Local $iUBound = UBound($avArray, 1) - 1
[/autoit] [autoit][/autoit] [autoit]If Not $iUBound Then
$avArray = ""
Return 0
EndIf
; Bounds checking
If $iElement < 0 Then $iElement = 0
If $iElement > $iUBound Then $iElement = $iUBound
; Move items after $iElement up by 1
Switch UBound($avArray, 0)
Case 1
For $i = $iElement To $iUBound - 1
$avArray[$i] = $avArray[$i + 1]
Next
ReDim $avArray[$iUBound]
Case 2
Local $iSubMax = UBound($avArray, 2) - 1
For $i = $iElement To $iUBound - 1
For $j = 0 To $iSubMax
$avArray[$i][$j] = $avArray[$i + 1][$j]
Next
Next
ReDim $avArray[$iUBound][$iSubMax + 1]
Case Else
Return SetError(3, 0, 0)
EndSwitch
Return $iUBound
EndFunc ;==>_ArrayDelete
gleichwertiges beispiel das ebenfalls nicht funktioniert:
serverA.au3
#include <TCP.au3>
[/autoit] [autoit][/autoit] [autoit]Global $socket = _TCP_Server_Create(5021)
_TCP_RegisterEvent($socket, $TCP_RECEIVE, "_recieve")
While 1
Sleep(10)
WEnd
Func _recieve($hSocket, $sReceived, $iError)
MsgBox(0,$hSocket,$sReceived)
_TCP_Send($hSocket, "habe von dir '" & $sReceived & "' empfangen!")
EndFunc
Func _close()
_TCP_Server_Stop()
Exit
EndFunc
serverB.au3
#include <TCP.au3>
[/autoit] [autoit][/autoit] [autoit]Global $socket = _TCP_Server_Create(5022)
_TCP_RegisterEvent($socket, $TCP_RECEIVE, "_recieve")
Global $clientSocket = _TCP_Client_Create("127.0.0.1" , 5021)
_TCP_RegisterEvent($clientSocket, $TCP_RECEIVE, "_recieve")
Sleep(5000)
_TCP_Send($clientSocket, "blubb")
[/autoit] [autoit][/autoit] [autoit]While 1
Sleep(10)
WEnd
Func _recieve($hSocket, $sReceived, $iError)
MsgBox(0,$hSocket,$sReceived)
EndFunc
Func _close()
_TCP_Server_Stop()
Exit
EndFunc
clientC.au3
#include <TCP.au3>
[/autoit] [autoit][/autoit] [autoit]Global $socket = _TCP_Client_Create("127.0.0.1" , 5022) ; //EDIT: NATÜRLICH muss man den port für serverA anpassen und nicht einfach drauf loskopieren
_TCP_RegisterEvent($socket, $TCP_RECEIVE, "_recieve")
Sleep(5000)
_TCP_Send($socket, "ich bin ein client")
[/autoit] [autoit][/autoit] [autoit]While 1
Sleep(10)
WEnd
Func _recieve($hSocket, $sReceived, $iError)
MsgBox(0,$hSocket,$sReceived)
EndFunc
-beide server können von clienten empfangen
-serverA kann von serverB empfangen ABER(!problem!) nicht andersherum
nachdem ich beide server ganz normal gestartet habe und mit einem externen clienten getestet habe(funktioniert einwandfrei) habe ich an server B zusätzlich einen client per
[autoit]$masterSocket = _TCP_Client_Create($master_IP , $master_Port)
[/autoit]gestartet und sende eine anfrage.
die kommt auch an server A wunderbar an.
server A schaut also nach was er auf beispielsweise "blubb" antworten soll, sendet dies, es kommt aber an Server B nicht wieder an..
server B will nicht von einem anderen server empfangen(obwohl ich einen clienten im script gestartet habe).. lediglich von clienten
habe zudem auch versucht für den client socket
[autoit]_TCP_RegisterEvent($masterSocket, $TCP_RECEIVE, "_masteranswer")
[/autoit]zu verwenden (was ein "true" ergeben hat) aber es kommt nichts an.. er reagiert nicht..
andere dinge wie offene ports/firewall einstellungen etc. konnt ich ja alles ausschließen und als ich einen externen clienten auf die server angesetzt hatte, waren die server ja auch ganz gesellig.. nur untereinander eben nicht
ah okay.. hätte zweimal lesen sollen!^^
an den eigentlich programmcode kommst du ja garnicht herran und das aus gutem grund.. wärst du berechtigt die daten einzusehen hättest du uns warscheinlich nach einer FTP verbindung gefragt.
wie wärs also wenn du uns genau erläuterst was du da eigentlich vor hast^^
was die server genau tun ist nicht relevant soweit ich weiß.
server A ist eine art Masterserver an dem sich server B anmelden soll.
um eine verbindung mit server B aufzubauen muss ich ja parallel ein client erstellen.
verbindung wird aufgebaut, daten werden von server A empfangen.. aber server(client) B empfängt nichts zurück.
howdy
[autoit]$download = InetRead($variablenort,1)
$content = BinaryToString($download)
bei bedarf musst du natürlich die variable erstmal rausfiltern falls mehr als die gewünschte variable ausgelesen wird.