#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\..\AutoIt\Zusätze\Aeon_Icon_Pack\ICO\Misc\Buddy-Blue.ico
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; ##### Server #####
; starte Server zuerst


#include <GUIConstants.au3>


$ServerIP = @IPAddress1
$Port = 33891

TCPStartup()
$MainSocket = TCPListen($ServerIP, $Port)
if $MainSocket = -1 Then Exit

$ConnectedSocket = -1

Do
	$ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1

While 1
	$recv = TCPRecv($ConnectedSocket, 2048)
	if @error Then ExitLoop

	if $recv <> "" Then
		TrayTip("Incoming Command", $recv, 5)
		_CommandToAction($recv)
	EndIf
WEnd

if $ConnectedSocket	<> -1 Then TCPCloseSocket($ConnectedSocket)
TCPShutdown()


Func _CommandToAction($command)
	$ar = StringSplit($command, "|")
	Switch $ar[1]
		Case "Msg"
			MsgBox(0, $ar[2], $ar[3])
		Case "Run"
			Run($ar[2])
		Case "Space"
			TCPSend($ConnectedSocket, "Test")
	EndSwitch
EndFunc
