#include <GUIConstantsEx.au3>

;IP und Port von dir
$Ip = @IPAddress1
$Port = 3333

TCPStartUp ()

;IP und Port von denem Freund
$Ip2 = TCPNameToIP("icynator.ath.cx")
$Port2 = 3333

$Server = TCPListen($Ip,$Port,1)


$Form1 = GUICreate("Chat", 625, 445, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 56, 16, 505, 265)
$Input1 = GUICtrlCreateInput("", 64, 336, 401, 21)
$Button1 = GUICtrlCreateButton("Send", 488, 336, 97, 25, 0)
$Button2 = GUICtrlCreateButton("X", 592, 0, 25, 17, 0)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)


While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Button1
			$Client2 = TCPConnect ($Ip2,$Port2)
			TCPSend ($Client2, GUICtrlRead($Input1))
			ControlClick ("","",$Edit1)
			Send("-> " & GUICtrlRead($Input1),1)
			Send(" {Enter}",0)
		Case $Button2
			Exit
	EndSwitch

		$Client = TCPAccept($Server)
	If $Client >= 0 Then
		Do
			$Message = TCPRecv($Client,2048)
		Until $Message <> ""
		ControlClick ("","",$Edit1)
		Send("-> " & $Message,1)
		Send(" {Enter}",0)
	EndIf
WEnd