Hallo,
Ich habe ein Problem, undzwar ich habe heute mal das Tutorial für TCP/IP (http://wiki.autoit.de/wiki/index.php/Tutorial#TCP.2FIP ) mal angefangen und etwas gescript was nicht funktioniert hat. Darauf hin habe ich die musterlösung ausprobiert. Und komischer weise hat sie auch nicht funktioniert. Wir haben beim Client acuh extra darauf geachtet das die ip richtig ist (also die server ip) aber immer kommt der error. Liegt es an der Firewall?
mfg Kangtar
(TCP/IP Tutorial ) verbindung schlägt immer fehl
-
- [ offen ]
-
Kangtar -
29. Mai 2010 um 20:23 -
Geschlossen -
Erledigt
-
-
wenn ihr nicht im lokalen netzwerk seit, wird es denke ich mal an der routerfirewall liegen bzw die port sind ncht offen
-
Poste mal das skript
-
Die Server Ip muss deine eigene sein und im client muss die ip des servers stehen also auch deine
-
Bei mir hat es erst funktioniert als ich (der Server) mein PC ins Netz bzw. Lokale Netzwerk freigegeben habe.
-
Hallo
ich war zu faul ein neuen Thread aufzumachen und schreibe hier einfach mal rein (past ja auch zu Thema ^^)So, 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
[autoit]#include <GUIConstantsEx.au3>
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
#include <GuiIPAddress.au3>
#include <String.au3>
#RequireAdminGlobal $iSocket, $iRecv, $iPacketlaenge, $login = 0
[/autoit] [autoit][/autoit] [autoit]TCPStartup()
[/autoit] [autoit][/autoit] [autoit]#Region ### START Koda GUI section ### Form=
[/autoit] [autoit][/autoit] [autoit]
$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
[/autoit] [autoit][/autoit] [autoit]
$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
WEndFunc Server_Recv($iSocket)
[/autoit] [autoit][/autoit] [autoit]
$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_RecvFunc Server_Packet_Split($iPacket)
[/autoit] [autoit][/autoit] [autoit]
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_SplitFunc _packet($iAktion, $iMsg = "")
[/autoit]
$iPacket = "time=[" & @HOUR & ":" & @MIN & ":" & @MIN & "]=" & @CRLF & _
"aktion=[" & $iAktion & "]=" & @CRLF & _
"msg=[" & $iMsg & "]=" & @CRLF & @CRLF
Return $iPacket
EndFunc ;==>_packetServer
[autoit]#include <Array.au3>
[/autoit] [autoit][/autoit] [autoit]
#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]
[/autoit] [autoit][/autoit] [autoit]
$sItem[0] = "Alle|0|"
$iClient_Socket[0][0] = 0TCPStartup()
[/autoit] [autoit][/autoit] [autoit]#Region ### START Koda GUI section ### Form=
[/autoit] [autoit][/autoit] [autoit]
$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)
[/autoit] [autoit][/autoit] [autoit]
_GUICtrlListView_SetItemSelected ($ListView1,0)$iTimer = TimerInit()
[/autoit] [autoit][/autoit] [autoit]While 1
[/autoit] [autoit][/autoit] [autoit]
$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
EndIfIf $sItem[0] <> GUICtrlRead (GUICtrlRead ($ListView1)) <> 0 Then
[/autoit] [autoit][/autoit] [autoit]
$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
WEndFunc _Client_Suche($iSocket)
[/autoit] [autoit][/autoit] [autoit]
Local $sClient
$sClient = TCPAccept($iSocket)
If $sClient <> -1 Then
;_ArrayAdd($iClient_Socket, $sClient)
_Array2DAdd($iClient_Socket, $sClient & "|")$iClient_Socket[0][0] += 1
[/autoit] [autoit][/autoit] [autoit]
TCPSend($sClient, _packet("Connection", "Accept"))
Do
$iRecv = TCPRecv($sClient, 1024)
Until $iRecv <> ""
EndIf
EndFunc ;==>_Client_SucheFunc _packet($iAktion, $iMsg = "")
[/autoit] [autoit][/autoit] [autoit]
$iPacket = "time=[" & @HOUR & ":" & @MIN & ":" & @MIN & "]=" & @CRLF & _
"aktion=[" & $iAktion & "]=" & @CRLF & _
"msg=[" & $iMsg & "]=" & @CRLF & @CRLF
Return $iPacket
EndFunc ;==>_packetFunc _Client_Ping()
[/autoit] [autoit][/autoit] [autoit]
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_PingFunc Client_Recv($iSocket)
[/autoit] [autoit][/autoit] [autoit]
$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_RecvFunc Client_Packet_Split($iPacket)
[/autoit]
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 -
Ich weiß nicht ob es gut ist, bei 2 unterschiedlichen "Threadstellern" zwei Fragen gleichzeitig zu beantworten, das kann leicht zu Verwirrung führen. Würde ein neuer Thread abhilfe schaffen!