Hallöchen zusammen.
Anhanden der Wiki Artikel versuche ich einen Client/Server zu schreiben.
Leider habe ich das Problem, dass der Server die Daten nicht wirklich empfängt oder teilweise funktioniert es einmalig.
Habe ich mich "verschrieben"?
Spoiler anzeigen
;Check startup parameters (exit when no parameters are set!)
if $CmdLine[0] = 0 Then
exit
EndIf
;Server or Client
Switch $CmdLine[1]
case 1 ;Server
;Start TCP service
TCPStartup()
;Create listening socket
$MainSocket = TCPListen(@IPAddress1,555)
;Exit if socket could not be created!
If $MainSocket = -1 then
exit
EndIf
while 1
;Initialize a variable to represent a connection
$ConnectedSocket = -1
;Wait for and accept a connection
Do
$ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1
While 1
$Recv = TCPRecv($ConnectedSocket,4096)
if $Recv <> "" then TrayTip("SERVER","Received " & $Recv,1000)
if @error then
ExitLoop
EndIf
WEnd
;If existing, close open socket
If $ConnectedSocket <> -1 then
TCPCloseSocket($ConnectedSocket)
TrayTip("SERVER","Closed a ConnectedSocket",1000)
EndIf
WEnd
;Shutdown TCP service
TCPShutdown()
case 2 ;Client
;Start TCP service
TCPStartup()
;Initialize a variable to represent a connection
$ConnectedSocket = -1
;Attemp to connect to the server
$ConnectedSocket = TCPConnect(@IPAddress1,555)
;Exit on error
If @error then
exit
EndIf
TCPSend($ConnectedSocket,"TEST")
[/autoit] [autoit][/autoit] [autoit];Shutdown TCP service
TCPShutdown()
EndSwitch