Ich bauen grad einen TCP recv Script, um von einem Process die Packete zu empfangen. Habe hier ein bespiel server&client gebaut um packete zu simulieren. Diese Packete möchte ich nun per script empfangen. Nun bin ich grad am hängen. Hab da wenig erfahrung mit DLLCall und weiß nicht zu 100% ob das überhaupt möglich ist.
Hier der Server:
Code:
#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
;==============================================
;==============================================
;SERVER!! Start Me First !!!!!!!!!!!!!!!
;==============================================
;==============================================
Example()
Func Example()
; Set Some reusable info
; Set your Public IP address (@IPAddress1) here.
; Local $szServerPC = @ComputerName
; Local $szIPADDRESS = TCPNameToIP($szServerPC)
Local $szIPADDRESS = @IPAddress1
Local $nPORT = 33891
Local $MainSocket, $GOOEY, $edit, $ConnectedSocket, $szIP_Accepted
Local $msg, $recv
; Start The TCP Services
;==============================================
TCPStartup()
; Create a Listening "SOCKET".
; Using your IP Address and Port 33891.
;==============================================
$MainSocket = TCPListen($szIPADDRESS, $nPORT)
; If the Socket creation fails, exit.
If $MainSocket = -1 Then Exit
; Create a GUI for messages
;==============================================
$GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ")", 300, 200)
$edit = GUICtrlCreateEdit("", 10, 10, 280, 180)
GUISetState()
; Initialize a variable to represent a connection
;==============================================
$ConnectedSocket = -1
;Wait for and Accept a connection
;==============================================
Do
$ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1
; Get IP of client connecting
$szIP_Accepted = SocketToIP($ConnectedSocket)
; GUI Message Loop
;==============================================
While 1
$msg = GUIGetMsg()
; GUI Closed
;--------------------
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
; Try to receive (up to) 2048 bytes
;----------------------------------------------------------------
$recv = TCPRecv($ConnectedSocket, 2048)
; If the receive failed with @error then the socket has disconnected
;----------------------------------------------------------------
If @error Then ExitLoop
; Update the edit control with what we have received
;----------------------------------------------------------------
If $recv <> "" Then GUICtrlSetData($edit, _
$szIP_Accepted & " > " & $recv & @CRLF & GUICtrlRead($edit))
WEnd
If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket)
TCPShutdown()
EndFunc ;==>Example
; Function to return IP Address from a connected socket.
;----------------------------------------------------------------------
Func SocketToIP($SHOCKET)
Local $sockaddr, $aRet
$sockaddr = DllStructCreate("short;ushort;uint;char[8]")
$aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
"ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
If Not @error And $aRet[0] = 0 Then
$aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
If Not @error Then $aRet = $aRet[0]
Else
$aRet = 0
EndIf
$sockaddr = 0
Return $aRet
EndFunc ;==>SocketToIP
Der Client sendet automatisch jede Sekunde ein Packet
Code:
Opt('MustDeclareVars', 1)
;==============================================
;==============================================
;CLIENT! Start Me after starting the SERVER!!!!!!!!!!!!!!!
;==============================================
;==============================================
Example()
Func Example()
; Set Some reusable info
;--------------------------
Local $ConnectedSocket, $szData
; Set $szIPADDRESS to wherever the SERVER is. We will change a PC name into an IP Address
; Local $szServerPC = @ComputerName
; Local $szIPADDRESS = TCPNameToIP($szServerPC)
Local $szIPADDRESS = @IPAddress1
Local $nPORT = 33891
; Start The TCP Services
;==============================================
TCPStartup()
; Initialize a variable to represent a connection
;==============================================
$ConnectedSocket = -1
;Attempt to connect to SERVER at its IP and PORT 33891
;=======================================================
$ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT)
; If there is an error... show it
If @error Then
MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error)
; If there is no error loop an inputbox for data
; to send to the SERVER.
Else
;Loop forever asking for data to send to the SERVER
While 1
; InputBox for data to transmit
$szData = Random(1,1000,1)
; If they cancel the InputBox or leave it blank we exit our forever loop
If @error Or $szData = "" Then ExitLoop
; We should have data in $szData... lets attempt to send it through our connected socket.
TCPSend($ConnectedSocket, $szData)
Sleep(1000)
; If the send failed with @error then the socket has disconnected
;----------------------------------------------------------------
If @error Then ExitLoop
WEnd
EndIf
EndFunc ;==>Example
Der Hauptcode um das ganze zu empfangen:
Dies habe ich ein wenig umgeschrieben, von

Ich hoffe es macht keinem was aus, (natürlich danke dafür)
Code:
GUICreate("recv", 210, 260)
$List = GUICtrlCreateList("", 5, 5, 200, 188)
$B_Refresh = GUICtrlCreateButton("Aktualisieren", 5, 200, 200, 25)
$B_Recv = GUICtrlCreateButton("Recv", 5, 230, 95, 25)
GUISetState()
Local $recv
local $dll = DllOpen("Ws2_32.dll")
While Sleep(10)
$Msg = GUIGetMsg()
Switch $Msg
Case -3
Exit
Case $B_Refresh
GUICtrlSetData($List, "")
$ProcessList = ProcessList()
For $i = 1 To $ProcessList[0][0]
GUICtrlSetData($List, $ProcessList[$i][0], True)
Next
Case $B_Recv
_Recv(GUICtrlRead($List))
If @error Then MsgBox(48, "Fehler", "Fehler beim pausieren des Threads!")
EndSwitch
If $recv <> "" Then
ToolTip($recv,1,1)
EndIf
WEnd
Func _OpenProcess($ProcessId)
If Not ProcessExists($ProcessId) Then Return SetError(1, "", False)
$hProcess = DllCall("Kernel32.dll", "HWND", "OpenProcess", "DWORD", 0x800, "bool", False, "DWORD", $ProcessId)
If @error Then
Return SetError(2, "", False)
Else
Return SetError(0, "", $hProcess[0])
EndIf
EndFunc
Func _CloseHandle($hObj)
If Not IsHWnd($hObj) Then Return SetError(1, "", False)
DllCall("Kernel32.dll", "BOOL", "CloseHandle", "HWND", $hObj)
If @error Then
Return SetError(2, "", False)
Else
Return SetError(0, "", True)
EndIf
EndFunc
Func _Recv($ProcessName)
$hProcess = _OpenProcess(ProcessExists($ProcessName))
If @error Or $hProcess == 0 Then SetError(1, "", False)
$recv = DllCall($dll, "int", "recv", "int" , 900, "ptr", $hProcess)
If @error Then
Return SetError(2, "", False)
Else
Return SetError(0, "", True)
EndIf
EndFunc
Wie gesagt, kenn mich mit dem DLLCall nicht ganz aus, bitte daher um hilfe
Danke
PS:
Sonstige Infos
recv Function






