leon460 发表于 2011-1-28 16:21:26

用什么函数可以把 CLOSE_WAIT 结束掉?

本帖最后由 leon460 于 2011-1-30 22:02 编辑

用哪个函数怎样结束掉Win98 和winxp系统里面的CLOSE_WAIT   状态????


我把代码贴出来了,不知道是否哪里有问题。
环境是在一台server上运行ftp server,然后将以下ftp 客户端运行在 win98系统上,发现一个问题:win98上运行ftp client(代码如下)一段时间后,就不能上传文件了。经过排除,ftp server确认没有问题。
不过我发现win98上有大量的 CLOSE_WAIT   状态 ,所以才请教大家是否有结束此函数,也不知道是否为其他问题。


我把代码贴出来#include <FTP.au3>
Opt("TrayIconHide",1);0:show the tray   1:Hides the AutoIt tray icon

$i=1
Do       
        ByFtp()            ;若文件共享不起作用,能ping通,当是网络共享文件夹不能使用时,尝试使用ftp功能
        Sleep(2000)
Until $i=0

Func ByFtp()
        $FtpServerIP = IniRead(@ScriptDir & "\setting.ini", "section", "FtpServerIP", "Not Found the FtpServerIP")
        $FtpServerPort = IniRead(@ScriptDir & "\setting.ini", "section", "FtpServerPort", "Not Found FtpServerPort")
        $username = IniRead(@ScriptDir & "\setting.ini", "section", "username", "Not Found Ftp usernames")
        $password = IniRead(@ScriptDir & "\setting.ini", "section", "password", "Not Found Ftp password")
        $DataPath=IniRead(@ScriptDir & "\setting.ini", "section", "LocalDataPath", "Not Found Local Data path")
        $filemode=IniRead(@ScriptDir & "\setting.ini", "section", "filemode", "Not Found file charactor")

        ;Local $username124 = "test";定义 Tencor6420 的ftp用户名和密码
        ;Local $pass124 = "123456"       

        ;$search = FileFindFirstFile($DataPath & "\*." & $filemode); Shows the filenames of all files in the current directory.
        ;If $search = -1 Then                ; Check if the search was successful
                ;MsgBox(0, "Error", "No files/directories matched the search pattern",1)
                ;Exit
        ;EndIf
        While 1
                $search = FileFindFirstFile($DataPath & "\*." & $filemode); Shows the filenames of all files in the current directory.
                $file = FileFindNextFile($search)
                MsgBox(0,"Filename",$file,1)
                ;sleep(2000)
                If @error Then
                        MsgBox(0,"@error",@error,1)
                        ExitLoop   
                Else
                        TCPStartup()              ;开始 tcp 服务
                        $ftpflag124=TCPConnect($FtpServerIP,$FtpServerPort)
                        If $ftpflag124 <> 0 Or $ftpflag124 <> -1 Then   ;如果 telnet tencor6220#2 FTP端口 21 成功,则开始连接并下载数据
                                $Open = _FTPOpen('MyFTP Control Tencor62202')      ;开始 一个ftp session
                                $Conn = _FTPConnect($Open, $FtpServerIP, $username , $password)
                                Local $h_Handle124
                                Local $s_RemoteFile124="/" & $file                                         ;定义远程ftp服务器的目录
                                Local $s_LocalFile124=$DataPath & "\" & $file                        ;定义本地存放路径及其文件名
                                $messageGet124=_FTPPutFile($Conn,$s_LocalFile124,$s_RemoteFile124)
                                MsgBox(0,"FTPputfile",$messageGet124,1)
                                If $messageGet124=1 Then
                                        _FTPClose($Open)
                                        FileDelete($s_LocalFile124)                                       
                                Else                                       
                                        ExitLoop
                                EndIf                               
                        EndIf
                        TCPCloseSocket($ftpflag124)
                        TCPShutdown()               
                EndIf
                FileClose($search)
        WEnd
        ;FileClose($search)
EndFunc谢谢啦

pusofalse 发表于 2011-1-28 19:30:00

把错字改过来就告诉你。

leon460 发表于 2011-1-28 23:47:59

回复 2# pusofalse

看过了,,没有错别字哇,喔喔,告诉我下子,谢啦,现在正在排查一个通讯上的问题----
   
感谢

pusofalse 发表于 2011-1-28 23:52:53

回复 3# leon460


    把你看到的,本帖的题目截图 并贴上来。

smartzbs 发表于 2011-1-29 10:13:58

兄弟,你的标题Close写成Clost了,P版提醒你还不改呀.
你的命令是Netstat -an |find "21"吧?
假设是系统的FTP服务:
FTP服务你设成单线程可以解决大部分问题;正常这种情况是用户使用FTP工具没有送回结束,你要关闭Close_Wait进程一般要重启FTP服务(关闭再开).
假设是AU写的FTP服务:说明你的Client没有送回ShutDown,这要看你的源代码才好改.

baijiri 发表于 2011-1-29 10:29:39

{:face (131):}

leon460 发表于 2011-1-30 21:42:30

回复 4# pusofalse

改啦,改啦,,呵呵,不好意思阿

leon460 发表于 2011-1-30 22:05:15

回复 5# smartzbs

谢谢你哇,我更新了发帖的内容,具体了下问题内容,您再帮我看看哇,,您所说的FTP服务你设成单线程可以解决大部分问题;是否设置ftp server里面设置?
我发现的是ftp client 出现大量的这样的状态。。

再次感谢

pusofalse 发表于 2011-3-22 06:50:32

不知解决没。
Const $MIB_TCP_STATE_DELETE_TCB = 12
Const $tagMIB_TCPROW = "dword State;dword LocalAddr;dword LocalPort;dword RemoteAddr;dword RemotePort"

; 删除本机1234端口 与远程主机65.55.57.252 80端口的连接。
If _DeleteTCPEntry(@IPAddress2, 1234, "65.55.57.252", 80) Then
   ; Succeed.
Else
   ; Fail.
EndIf

Func _DeleteTCPEntry($sLocalAddr, $iLocalPort, $sRemoteAddr, $iRemotePort)
        Local $iResult, $tMibRow

        $tMibRow = DllStructCreate($tagMIB_TCPROW)
        DllStructSetData($tMibRow, "State", $MIB_TCP_STATE_DELETE_TCB)
        DllStructSetData($tMibRow, "LocalAddr", _inetaddr($sLocalAddr))
        DllStructSetData($tMibRow, "LocalPort", _htons($iLocalPort))
        DllStructSetData($tMibRow, "RemoteAddr", _inetaddr($sRemoteAddr))
        DllStructSetData($tMibRow, "RemotePort", _htons($iRemotePort))

        $iResult = DllCall("iphlpapi.dll", "long", "SetTcpEntry", "ptr", DllStructGetPtr($tMibRow))
        Return SetError($iResult, 0, $iResult = 0)
EndFunc        ;==>_DeleteTCPEntry

Func _inetaddr($sIPAddress)
        Local $iResult
        $iResult = DllCall("Ws2_32.dll", "long", "inet_addr", "str", $sIPAddress)
        Return $iResult
EndFunc        ;==>_inetaddr

Func _htons($wPort)
        Local $iResult
        $iResult = DllCall("Ws2_32.dll", "word", "htons", "word", $wPort)
        Return $iResult
EndFunc        ;==>_htons

另外,iphlpapi.GetTcpTable可以检测出所有连接和其状态,在调用_DeleteTCPEntry函数之前,先检查下连接状态是否为CLOSE_WAIT。

leon460 发表于 2011-3-22 12:09:22

回复 9# pusofalse

感谢大哥的帮助
“另外,iphlpapi.GetTcpTable可以检测出所有连接和其状态”这句句是否帮我写出代码?
类似dllcall("iphlpapi.dll","long","settcpentry","ptr",dllstructgetptr($tmibrow))
这样的语句我在论坛哪里可以找到相关资料?我不知道 iphlpapi.dll 对应有那些功能?在哪里可以找到起资料?

再次感谢
页: [1]
查看完整版本: 用什么函数可以把 CLOSE_WAIT 结束掉?