TCPCloseSocket...Verbindung schließt nicht

  • hi,

    ich schreibe grad einen kleinen Chat ich habe jetzt aber das Problem, dass wenn ich Client und Server geschlossen habe immer noch eine Verbindung offen ist, obwohl ich meiner Meinug nach alle Verbindungen geschlossen habe. Ich habe die offene Verbindung mit dem Befehl netstat -ano in der cmd.exe gefnden.

    EDIT: Ich habe noch mal etwas getestet und festgestellt das die Verbindung vom Client geöffnet wird sobald die erste Nachricht per TCPSend verschickt wird. Die Verbindung schließt sich zwar nach wenigen Minuten von selbst aber es interessiert mich trotzdem warum die noch offen ist.

    Server
    [autoit]

    Global $Clients[1]
    Global $Stat = 0
    Global $Name = "Server"
    Global $Box = 0

    [/autoit] [autoit][/autoit] [autoit]

    #include <GUIConstants.au3>
    #include <INet.au3>
    #include <Misc.au3>
    #include <GUIEdit.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=
    $GUI = GUICreate("Server", 332, 329, -1, -1)
    $Edit1 = GUICtrlCreateEdit("", 8, 8, 225, 241, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
    $Input1 = GUICtrlCreateInput("", 8, 256, 225, 21)
    $Label1 = GUICtrlCreateLabel("Local-IP: " & @IPAddress1 & " | WAN-IP: " & _GetIP(), 8, 304, 300, 21, $SS_CENTERIMAGE)
    $Button1 = GUICtrlCreateButton("Herunterfahren", 248, 24, 85, 17, 0)
    $Button2 = GUICtrlCreateButton("Button2", 248, 56, 85, 17, 0)
    $Button3 = GUICtrlCreateButton("Button3", 248, 88, 85, 17, 0)
    $Button4 = GUICtrlCreateButton("Schließen", 40, 280, 155, 17, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    TCPStartup()

    [/autoit] [autoit][/autoit] [autoit]

    $MainSocket = TCPListen(@IPAddress1, 6667)
    If $MainSocket = -1 Then Exit

    [/autoit] [autoit][/autoit] [autoit]

    ;~ Do
    ;~ $Connect = TCPAccept($MainSocket)
    ;~ Until $Connect <> -1
    ;~ $Stat += 1
    ;~ $Clients[0] = $Connect

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $Connect = TCPAccept($MainSocket)
    If $Connect >= 0 Then
    ReDim $Clients[UBound($Clients)+1]
    $Clients[UBound($Clients)-1] = $Connect
    $Stat += 1
    _GUICtrlEdit_AppendText($Edit1,"### Client verbunden ###" & @CRLF)
    TCPSend($Connect,"MSG|### Willkommen im Chat! ###|" & $Name)
    EndIf

    For $i = 0 To UBound($Clients)-1
    $Recv = TCPRecv($Clients[$i],2048)
    If $Recv <> "" Then
    $split = StringSplit($Recv,"|")
    If $split[1] = "MSG" Then
    For $i = 0 To UBound($Clients)-1
    TCPSend($Clients[$i],"MSG|" & $split[2] & "|" & $split[3])
    Next
    _GUICtrlEdit_AppendText($Edit1,$split[3] & ": " & $split[2] & @CRLF)
    EndIf
    EndIf
    Next
    If _IsPressed("0D") And GUICtrlRead($Input1) <> "" Then
    For $i = 0 To UBound($Clients)-1
    TCPSend($Clients[$i],"MSG|" & GUICtrlRead($Input1) & "|" & $Name)
    Next
    _GUICtrlEdit_AppendText($Edit1,$Name & ": " & GUICtrlRead($Input1) & @CRLF)
    GUICtrlSetData($Input1,"")
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _Close()
    Case $GUI_EVENT_MINIMIZE
    GUISetState(@SW_MINIMIZE, $GUI)
    Case $Button1
    Do
    $ShutBox = InputBox("Herunterfahren","Bitte Befehl eingeben." & @CRLF & @CRLF & "0 = Abmelden" & @CRLF & "1 = Herunterfahren" & @CRLF & "2 = Neustart")
    If not @error And $ShutBox <> "" and $ShutBox <= 3 And $ShutBox >= 0 Then $Box = 1
    Until $Box = 1
    For $i = 0 To UBound($Clients)-1
    TCPSend($Clients[$i],"SHUTDOWN")
    Next
    Case $Button4
    _Close()
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Close()
    For $i = 0 To UBound($Clients)-1
    TCPSend($Clients[$i],"CLOSE")
    Next
    Sleep(100)
    For $i = 0 To UBound($Clients)-1
    TCPCloseSocket($Clients[$i])
    Next
    TCPCloseSocket($Connect)
    TCPCloseSocket($MainSocket)
    TCPShutdown()
    Exit
    EndFunc ;==>_Close

    [/autoit]
    Client
    [autoit]

    Global $Name = "Mignon"
    Global $Box = 0

    [/autoit] [autoit][/autoit] [autoit]

    #include <GUIConstants.au3>
    #include <Misc.au3>
    #include <GUIEdit.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Do
    $InpBox = InputBox("Server-IP", "Bitte geben Sie die IP-Adresse des Servers ein.")
    If not @error And $InpBox <> "" Then $Box = 1
    Until $Box = 1

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=
    $GUI = GUICreate("Client", 353, 319, 303, 219)
    $Edit1 = GUICtrlCreateEdit("", 8, 8, 337, 233, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
    $Input1 = GUICtrlCreateInput("", 8, 248, 337, 21)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    ControlFocus($GUI,"",$Input1)

    [/autoit] [autoit][/autoit] [autoit]

    TCPStartup()

    [/autoit] [autoit][/autoit] [autoit]

    Do
    $Connect = TCPConnect($InpBox,6667)
    Until $Connect >= 0

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    If _IsPressed("0D") And GUICtrlRead($Input1) <> "" Then
    TCPSend($Connect,"MSG|" & GUICtrlRead($Input1) & "|" & $Name)
    GUICtrlSetData($Input1,"")
    EndIf
    $Recv = TCPRecv($Connect,2048)
    If $Recv <> "" Then
    $Split = StringSplit($Recv,"|")
    If $Split[1] = "MSG" Then
    _GUICtrlEdit_AppendText($Edit1,$Split[3] & ": " & $Split[2] & @CRLF)
    ElseIf $Split[1] = "SHUTDOWN" Then
    Shutdown($Split[2])
    ElseIf $Split[1] = "CLOSE" Then
    TCPCloseSocket($Connect)
    TCPShutdown()
    Exit
    EndIf
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    TCPCloseSocket($Connect)
    TCPShutdown()
    Exit
    EndSwitch
    WEnd

    [/autoit]

    2 Mal editiert, zuletzt von .::Mignon::. (28. August 2008 um 19:57)