Hallo
ich möchte in meinem Chat auf ein Benutzer links klicken und das ich dann nur an ihn was schreibe und wenn ich angechrieben wurde und ich im anderen Chat bin, das eine Zahl mehr bei Post steht, und ich möchte ein Chat für alle machen also das alles beim Server reingeht
Mein Problem ist jetzt (endlich fange ich damit an ^^), wie kriege ich hin das er nur auf ein Benutzer was schikt ? ich kriege es nur hin das er zu dem selben schikt
Client
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <String.au3>
#RequireAdmin
Global $iSocket, $iRecv, $iPacketlaenge, $login = 0
[/autoit] [autoit][/autoit] [autoit]TCPStartup()
[/autoit] [autoit][/autoit] [autoit]#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Client", 664, 334, 241, 111)
$Group1 = GUICtrlCreateGroup("Benutzer", 4, 0, 197, 241)
$ListView1 = GUICtrlCreateListView("", 10, 14, 186, 222)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Chat", 208, 2, 453, 329)
$Edit1 = GUICtrlCreateEdit("", 214, 16, 442, 286)
$Input1 = GUICtrlCreateInput("", 216, 306, 387, 21)
$Button1 = GUICtrlCreateButton("Senden", 608, 306, 47, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Login", 4, 242, 197, 89)
$Label1 = GUICtrlCreateLabel("ServerIP:", 12, 258, 48, 17)
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 62, 254, 130, 21)
_GUICtrlIpAddress_Set($IPAddress1, FileRead("serverip.ini"))
$Button2 = GUICtrlCreateButton("Login", 12, 280, 179, 25)
$Label = GUICtrlCreateLabel("Login Status", 14, 308, 179, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$iSend = _packet("Name: " & @ComputerName, GUICtrlRead($Input1))
TCPSend($iSocket, $iSend)
Case $Button2
$iSocket = TCPConnect(_GUICtrlIpAddress_Get($IPAddress1), 100)
If @error Then
MsgBox(0, "Fehler", "Server läuft ist nicht.")
Else
GUICtrlSetState($Button1, $GUI_ENABLE)
GUICtrlSetState($Button2, $GUI_DISABLE)
$login = 1
EndIf
EndSwitch
If $login = 1 Then
Server_Recv($iSocket)
EndIf
WEnd
Func Server_Recv($iSocket)
$iRecv &= BinaryToString(TCPRecv($iSocket, 2048, 1))
$iPacketlaenge = StringInStr($iRecv, @CRLF & @CRLF, 1)
If $iPacketlaenge Then
$sPacket = StringLeft($iRecv, $iPacketlaenge - 1)
$iRecv = StringTrimLeft($iRecv, $iPacketlaenge + 3)
$rPacket = Server_Packet_Split($sPacket)
If $rPacket == "Accept" Then
TCPSend($iSocket, _packet("Connection", "True: " & @ComputerName))
GUICtrlSetData($Edit1, "Connected: True" & @CRLF & GUICtrlRead($Edit1))
Else
If $rPacket <> False Then GUICtrlSetData($Edit1, $rPacket & @CRLF & @CRLF & GUICtrlRead($Edit1))
EndIf
EndIf
EndFunc ;==>Server_Recv
Func Server_Packet_Split($iPacket)
Local $iTime, $iAktion, $iMsg, $iText
$iTime = _StringBetween($iPacket, "time=[", "]=")
$iAktion = _StringBetween($iPacket, "aktion=[", "]=")
$iMsg = _StringBetween($iPacket, "msg=[", "]=")
If $iAktion[0] = "Connection" Then Return $iMsg[0]
If $iAktion[0] = "Ping" Then Sleep(10)
If StringInStr($iAktion[0], "Name: ") Then
$iText = $iTime[0] & " " & StringReplace($iAktion[0], "Name: ", "") & @CRLF & $iMsg[0]
Return $iText
EndIf
EndFunc ;==>Server_Packet_Split
Func _packet($iAktion, $iMsg = "")
$iPacket = "time=[" & @HOUR & ":" & @MIN & ":" & @MIN & "]=" & @CRLF & _
"aktion=[" & $iAktion & "]=" & @CRLF & _
"msg=[" & $iMsg & "]=" & @CRLF & @CRLF
Return $iPacket
EndFunc ;==>_packet
Server
#include <Array.au3>
#include <ArrayMore.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <GuiListView.au3>
#include <String.au3>
Global $iSocket, $iClient_Socket[1][2], $login = 0, $iRecv = "", $sItem[2]
$sItem[0] = "Alle|0|"
$iClient_Socket[0][0] = 0
TCPStartup()
[/autoit] [autoit][/autoit] [autoit]#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Server", 664, 334, 241, 111)
$Group1 = GUICtrlCreateGroup("Benutzer", 4, 0, 197, 241)
$ListView1 = GUICtrlCreateListView("Computername |Post", 10, 14, 186, 222)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Chat mit: Alle", 208, 2, 453, 329)
$Edit1 = GUICtrlCreateEdit("", 214, 16, 442, 286)
$Input1 = GUICtrlCreateInput("", 216, 306, 387, 21)
$Button1 = GUICtrlCreateButton("Senden", 608, 306, 47, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Login", 4, 242, 197, 89)
$Label1 = GUICtrlCreateLabel("ServerIP:", 12, 258, 48, 17)
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 62, 254, 130, 21)
_GUICtrlIpAddress_Set($IPAddress1, @IPAddress1)
$Button2 = GUICtrlCreateButton("Server starten", 12, 280, 179, 25)
$Label = GUICtrlCreateLabel("Server Status", 14, 308, 179, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlCreateListViewItem ("Alle|0",$ListView1)
_GUICtrlListView_SetItemSelected ($ListView1,0)
$iTimer = TimerInit()
[/autoit] [autoit][/autoit] [autoit]While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$iSend = _packet("Name: Server", GUICtrlRead($Input1))
TCPSend($sItem[1], $iSend)
Case $Button2
$iSocket = TCPListen(@IPAddress1, 100, 100)
If $iSocket = -1 Then
MsgBox(0, "Fehler", "Server konte nicht gestartet werden.")
Exit
Else
GUICtrlSetState($Button1, $GUI_ENABLE)
GUICtrlSetState($Button2, $GUI_DISABLE)
FileDelete("serverip.ini")
FileWrite("serverip.ini", @IPAddress1)
EndIf
$login = 1
EndSwitch
If $login = 1 Then
_Client_Suche($iSocket)
For $i = 1 To $iClient_Socket[0][0]
Client_Recv($iClient_Socket[$i][0])
Next
If TimerDiff($iTimer) >= 5000 Then
_Client_Ping()
$iTimer = TimerInit()
EndIf
EndIf
If $sItem[0] <> GUICtrlRead (GUICtrlRead ($ListView1)) <> 0 Then
$sItem[0] = GUICtrlRead (GUICtrlRead ($ListView1))
$string = StringSplit ($sItem[0],"|")
For $i = 1 To $iClient_Socket[0][0]
If $iClient_Socket[$i][1] = $string[1] Then
$sItem[1] = $iClient_Socket[$i][0]
ExitLoop
EndIf
Next
GUICtrlSetData ($Group2,"Chat mit: " & $string[1])
EndIf
WEnd
Func _Client_Suche($iSocket)
Local $sClient
$sClient = TCPAccept($iSocket)
If $sClient <> -1 Then
;_ArrayAdd($iClient_Socket, $sClient)
_Array2DAdd($iClient_Socket, $sClient & "|")
$iClient_Socket[0][0] += 1
TCPSend($sClient, _packet("Connection", "Accept"))
Do
$iRecv = TCPRecv($sClient, 1024)
Until $iRecv <> ""
EndIf
EndFunc ;==>_Client_Suche
Func _packet($iAktion, $iMsg = "")
$iPacket = "time=[" & @HOUR & ":" & @MIN & ":" & @MIN & "]=" & @CRLF & _
"aktion=[" & $iAktion & "]=" & @CRLF & _
"msg=[" & $iMsg & "]=" & @CRLF & @CRLF
Return $iPacket
EndFunc ;==>_packet
Func _Client_Ping()
For $i = 1 To $iClient_Socket[0][0]
TCPSend($iClient_Socket[$i][0], _packet("Ping", "test"))
If @error Then
For $j = 0 To $iClient_Socket[0][0]
$gItem = _GUICtrlListView_GetItem($ListView1, $j - 1)
If $gItem[3] = $iClient_Socket[$j][1] Then
_GUICtrlListView_DeleteItem($ListView1, $j)
ExitLoop
EndIf
Next
GUICtrlSetData($Edit1, $iClient_Socket[$i][1] & " is disconnected..." & @CRLF & @CRLF & GUICtrlRead($Edit1))
_ArrayDelete($iClient_Socket, $i)
$iClient_Socket[0][0] -= 1
EndIf
Next
EndFunc ;==>_Client_Ping
Func Client_Recv($iSocket)
$iRecv &= BinaryToString(TCPRecv($iSocket, 2048, 1))
$iPacketlaenge = StringInStr($iRecv, @CRLF & @CRLF, 1)
If $iPacketlaenge Then
$sPacket = StringLeft($iRecv, $iPacketlaenge - 1)
$iRecv = StringTrimLeft($iRecv, $iPacketlaenge + 3)
$rPacket = Client_Packet_Split($sPacket)
If StringInStr($rPacket, "True: ") Then
GUICtrlSetData($Edit1, StringReplace($rPacket, "True: ", "") & " is connected..." & @CRLF & @CRLF & GUICtrlRead($Edit1))
GUICtrlCreateListViewItem(StringReplace($rPacket, "True: ", ""), $ListView1)
$iClient_Socket[UBound($iClient_Socket) - 1][1] = StringReplace($rPacket, "True: ", "")
ElseIf $rPacket <> False Then
GUICtrlSetData($Edit1, $rPacket & @CRLF & @CRLF & GUICtrlRead($Edit1))
EndIf
EndIf
EndFunc ;==>Client_Recv
Func Client_Packet_Split($iPacket)
Local $iTime, $iAktion, $iMsg, $iText
$iTime = _StringBetween($iPacket, "time=[", "]=")
$iAktion = _StringBetween($iPacket, "aktion=[", "]=")
$iMsg = _StringBetween($iPacket, "msg=[", "]=")
If $iAktion[0] = "Connection" Then Return $iMsg[0]
If $iAktion[0] = "Ping" Then Sleep(10)
If StringInStr($iAktion[0], "Name: ") Then
$iText = $iTime[0] & " " & StringReplace($iAktion[0], "Name: ", "") & @CRLF & $iMsg[0]
Return $iText
EndIf
EndFunc ;==>Client_Packet_Split