(解决不了算了~~哎~!)
本帖最后由 lm959680 于 2009-6-24 14:36 编辑实在是想不通了`~请大家帮帮忙啊!`
本来以为自己找到问题所在`(提前把全部代码删除只剩下自认为错误代码)~~可是很失望
自己改成进程方式的了,可以解决时间问题,
但新问题 来了一大堆`~~不写异常进Edit里数字不成比例,老问题 _TcpSocket() 函数还是卡~
如果还能指点优化,就更好`!!
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <CoProc.au3>
;#NoTrayIcon
Global $TSocket
Opt("GUIOnEventMode", 1)
opt("TrayIconDebug", 1)
if Not FileExists("srvmonitoring.ini") Then
MsgBox(0, "警告", "未发现配置文件,程序将自动退出!", 6)
Exit
EndIf
#Region ### START Koda GUI section ###
$Form1 = GUICreate("网络状态监控器 V1.0", 430, 160)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Label1 = GUICtrlCreateLabel("正在进行项目检测!", 1, 12, 430, 32, $SS_CENTER)
GUICtrlSetFont(-1, 18, 800, 0)
GUICtrlSetColor(-1, 0x0000FF)
$Edit1 = GUICtrlCreateEdit("", 0, 60, 430, 80, BitOr($WS_VSCROLL, $ES_READONLY))
GUICtrlSetBkColor(-1, 0xffffff)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
Dim $aParts =
_GUICtrlStatusBar_SetParts($StatusBar1, $aParts)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$TcpSocket = _CoProc("_TcpSocket");使用子进程运行_TcpSocket()函数,并返回子进程PID
_CoProcReciver("_Reciver");注册_Reciver()函数来接收子进程传递过来的消息
While 1
$begin =""
$begin = TimerInit()
While TimerDiff($begin) <10000
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & @YEAR & "/" & @MON & "/" & @MDAY & "" & @HOUR & ":" & @MIN & ":" & @SEC, 2)
If $TSocket = 1 Then;此判断开关是判断_TcpSocket()函数是否运行完,否则忽略
_CloseHandle($TcpSocket);关闭上一个子进程,由于我本人不知道 _TcpSocket()函数运行完 会不会结束~~
$TcpSocket = _CoProc("_TcpSocket");使用子进程运行_TcpSocket()函数,并返回子进程PID
$TSocket = 0;判断开关改为0
EndIf
Sleep(1000)
WEnd
Sleep(100)
WEnd
Func _TcpSocket()
Local $exp = "^(|\d|1\d\d|2\d|25)\.((|\d|1\d\d|2\d|25)\.){2}(|\d|1\d\d|2\d|25)[:](\d{1,5})[/]$"
Local $a, $d, $r
Local $i = 1, $dz = 1, $z = 0, $x
While 1 ;读配置文件的字段名 如果不连续(地址1..地址2..地址3..地址N) 则跳出循环
$a[$i] = IniRead("srvmonitoring.ini", "监控", "地址" & $dz, "NoNew")
If $a[$i] = "NoNew" Then ExitLoop
$dz += 1
$i += 1
Sleep(100)
WEnd
TCPStartUp()
For $i = $i - 1 To 1 Step -1
if StringRegExp(StringTrimRight($a[$i], StringLen($a[$i]) - StringInStr($a[$i], "/")), $exp) Then ;用正则表达式判断格式 192.168.1.2:11/包含对IP的检测端口 判断简写 最多5位数 可超过 65535
$d = StringSplit(StringReplace($a[$i], "/", ":"), ":");将格式 192.168.1.1:11/路由器 中的 / 符号 改成 : 再放进数组里
For $s = 3 to 1 Step -1
$r[$i][$s] = $d[$s]
Next
$Socket = TCPConnect($r[$i], $r[$i])
If $Socket = -1 Then
_CoProcSend($gi_CoProcParent, "Edit1|" & $r[$i])
FileWriteLine("LogTcpSocket" & @MON & @MDAY & ".txt", @MON & "/" & @MDAY & "" & @HOUR & ":" & @MIN & ":" & @SEC & " " & "[" & $r[$i] & "]" & " 出现网络异常!")
$z += 1
EndIf
$x += 1
TCPCloseSocket($Socket)
EndIf
_CoProcSend($gi_CoProcParent, "StatusBar1|" & $x)
_CoProcSend($gi_CoProcParent, "StatusBar11|" & $x - $z & "/" & $z)
Next
TCPShutdown()
_CoProcSend($gi_CoProcParent, "Label1|" & $z)
_CoProcSend($gi_CoProcParent, "process|ends")
EndFunc ;==>_TcpSocket
Func _Reciver($vParameter)
$aParam = StringSplit($vParameter, "|")
Select
Case $aParam = "Label1"
If $aParam <> 0 Then
GUICtrlSetData($Label1, "警告:检测到 " & $aParam & " 个异常!")
GUICtrlSetColor($Label1, 0xff0000)
Else
GUICtrlSetData($Label1, "全部项目检测正常!")
GUICtrlSetColor($Label1, 0x008000)
EndIf
Case $aParam = "Edit1"
GUICtrlSetData($Edit1, @MON & "/" & @MDAY & "" & @HOUR & ":" & @MIN & ":" & @SEC & " " & "[" & $aParam & "]" & " 出现网络异常!" & @CRLF, "Edit")
Case $aParam = "StatusBar1"
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "总项目:" & $aParam & "个", 0)
Case $aParam = "StatusBar11"
$data = StringSplit($aParam, "/")
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "正常:" & $data & "个 异常:" & $data & "个", 1)
Case $aParam = "process"
$TSocket = 1
EndSelect
EndFunc ;==>_Reciver
Func Form1Close()
exit
EndFunc ;==>Form1Close
保存 srvmonitoring.ini
[监控]
地址1=192.168.1.2:11/路由器
地址2=192.168.1.2:22/监控服务器
地址3=192.168.1.2:33/电影服务器
地址4=192.168.1.2:44/网络服务
地址5=192.168.1.2:55/服务器
CoProc.au3
下载地址:
http://www.brsbox.com/filebox/down/fc/ad14580ae34d142ec2c444b1f2777e31 本帖最后由 lm959680 于 2009-6-20 22:30 编辑
谢谢 3楼 4 楼的朋友帮助~~
原始版本#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;#NoTrayIcon
Opt("GUIOnEventMode", 1)
opt("TrayIconDebug", 1)
Global $time = 1
if Not FileExists("srvmonitoring.ini") Then
MsgBox(0, "警告", "未发现配置文件,程序将自动退出!", 6)
Exit
EndIf
#Region ### START Koda GUI section ###
$Form1 = GUICreate("网络状态监控器 V1.0", 430, 160)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Label1 = GUICtrlCreateLabel("正在进行项目检测!", 1, 12, 430, 32, $SS_CENTER)
GUICtrlSetFont(-1, 18, 800, 0)
GUICtrlSetColor(-1, 0x0000FF)
$Edit1 = GUICtrlCreateEdit("", 0, 60, 430, 80, BitOr($WS_VSCROLL, $ES_READONLY))
GUICtrlSetBkColor(-1, 0xffffff)
Global $StatusBar1 = _GUICtrlStatusBar_Create($Form1)
Global $aParts =
_GUICtrlStatusBar_SetParts($StatusBar1, $aParts)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$begin =""
$begin = TimerInit()
While TimerDiff($begin) < 10000
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & @YEAR & "/" & @MON & "/" & @MDAY & "" & @HOUR & ":" & @MIN & ":" & @SEC, 2)
if $time = 1 Then
$time = 0
_TcpSocket()
EndIf
Sleep(1000)
WEnd
Sleep(100)
WEnd
Func _TcpSocket()
Dim $a, $d, $r
Dim $i = 1, $dz = 1, $z = 0, $x
While 1
$a[$i] = IniRead("srvmonitoring.ini", "监控", "地址" & $dz, "NoNew")
If $a[$i] = "NoNew" Then ExitLoop
$dz += 1
$i += 1
Sleep(100)
WEnd
TCPStartUp()
For $i = $i - 1 To 1 Step -1
if StringRegExp(StringTrimRight($a[$i], StringLen($a[$i]) - StringInStr($a[$i], "/")), "^(|\d|1\d\d|2\d|25)\.((|\d|1\d\d|2\d|25)\.){2}(|\d|1\d\d|2\d|25)[:](\d{1,5})[/]$") Then
$d = StringSplit(StringReplace($a[$i], "/", ":"), ":")
For $s = 3 to 1 Step -1
$r[$i][$s] = $d[$s]
Next
$socket = TCPConnect($r[$i], $r[$i])
If $socket = -1 Then
GUICtrlSetData($Edit1, @MON & "/" & @MDAY & "" & @HOUR & ":" & @MIN & ":" & @SEC & " " & "[" & $r[$i] & "]" & " 出现网络异常!" & @CRLF, "Edit")
FileWriteLine("LogTcpSocket" & @MON & @MDAY & ".txt", @MON & "/" & @MDAY & "" & @HOUR & ":" & @MIN & ":" & @SEC & " " & "[" & $r[$i] & "]" & " 出现网络异常!")
$z += 1
EndIf
$x += 1
TCPCloseSocket($socket)
EndIf
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "总项目:" & $x & "个", 0)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "正常:" & $x - $z & "个 异常:" & $z & "个", 1)
Next
TCPShutdown()
If $z <> 0 Then
GUICtrlSetData($Label1, "警告:检测到 " & $z & " 个异常!")
GUICtrlSetColor($Label1, 0xff0000)
Else
GUICtrlSetData($Label1, "全部项目检测正常!")
GUICtrlSetColor($Label1, 0x008000)
EndIf
$time = 1
EndFunc ;==>_TcpSocket
Func Form1Close()
exit
EndFunc ;==>Form1Close 请吧$BIGIN放在WHILE外 楼主,可是要这种效果?
$begin = TimerInit()
While TimerDiff($begin) < 10000
If $time = 1 Then
$time = 0
_TcpSocket()
EndIf
Sleep(100)
WEnd
楼主,可是要这种效果?
$begin = TimerInit()
While TimerDiff($begin) < 10000
If $time = 1 Then
$time = 0
_TcpSocket()
EndIf
Sleep(100)
WEnd
tianji028 发表于 2009-6-20 17:55 http://www.autoitx.com/images/common/back.gif
正确 但对我的不对`~ 不知道是搞什么东东的,不懂,路过。。 那为高手帮帮忙啊`~~ 没有细看代码是什么回事
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;#NoTrayIcon
Opt("GUIOnEventMode", 1)
Opt("TrayIconDebug", 1)
Global $time = 1
If Not FileExists("srvmonitoring.ini") Then
MsgBox(0, "警告", "未发现配置文件,程序将自动退出!", 6)
Exit
EndIf
#Region ### START Koda GUI section ###
$Form1 = GUICreate("网络状态监控器 V1.0", 430, 160)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Label1 = GUICtrlCreateLabel("正在进行项目检测!", 1, 12, 430, 32, $SS_CENTER)
GUICtrlSetFont(-1, 18, 800, 0)
GUICtrlSetColor(-1, 0x0000FF)
$Edit1 = GUICtrlCreateEdit("", 0, 60, 430, 80, BitOR($WS_VSCROLL, $ES_READONLY))
GUICtrlSetBkColor(-1, 0xffffff)
Global $StatusBar1 = _GUICtrlStatusBar_Create($Form1)
Global $aParts =
_GUICtrlStatusBar_SetParts($StatusBar1, $aParts)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
AdlibEnable('SetStatusBar', 1000)
While 1
If $time = 1 Then
$time = 0
_TcpSocket()
EndIf
Sleep(1000)
WEnd
Func SetStatusBar()
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & @YEAR & "/" & @MON & "/" & @MDAY & "" & @HOUR & ":" & @MIN & ":" & @SEC, 2)
EndFunc
Func _TcpSocket()
Dim $a, $d, $r
Dim $i = 1, $dz = 1, $z = 0, $x
While 1
$a[$i] = IniRead("srvmonitoring.ini", "监控", "地址" & $dz, "NoNew")
If $a[$i] = "NoNew" Then ExitLoop
$dz += 1
$i += 1
Sleep(100)
WEnd
TCPStartup()
For $i = $i - 1 To 1 Step -1
If StringRegExp(StringTrimRight($a[$i], StringLen($a[$i]) - StringInStr($a[$i], "/")), "^(|\d|1\d\d|2\d|25)\.((|\d|1\d\d|2\d|25)\.){2}(|\d|1\d\d|2\d|25)[:](\d{1,5})[/]$") Then
$d = StringSplit(StringReplace($a[$i], "/", ":"), ":")
For $s = 3 To 1 Step -1
$r[$i][$s] = $d[$s]
Next
$socket = TCPConnect($r[$i], $r[$i])
If $socket = -1 Then
GUICtrlSetData($Edit1, @MON & "/" & @MDAY & "" & @HOUR & ":" & @MIN & ":" & @SEC & " " & "[" & $r[$i] & "]" & " 出现网络异常!" & @CRLF, "Edit")
FileWriteLine("LogTcpSocket" & @MON & @MDAY & ".txt", @MON & "/" & @MDAY & "" & @HOUR & ":" & @MIN & ":" & @SEC & " " & "[" & $r[$i] & "]" & " 出现网络异常!")
$z += 1
EndIf
$x += 1
TCPCloseSocket($socket)
EndIf
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "总项目:" & $x & "个", 0)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "正常:" & $x - $z & "个 异常:" & $z & "个", 1)
Next
TCPShutdown()
If $z <> 0 Then
GUICtrlSetData($Label1, "警告:检测到 " & $z & " 个异常!")
GUICtrlSetColor($Label1, 0xff0000)
Else
GUICtrlSetData($Label1, "全部项目检测正常!")
GUICtrlSetColor($Label1, 0x008000)
EndIf
$time = 1
EndFunc ;==>_TcpSocket
Func Form1Close()
Exit
EndFunc ;==>Form1Close
8# liongodmien
谢了朋友~~~
嘿嘿 看来_TcpSocket() 的问题 是解决不了了```算了 不研究!~
不知道是不是TCPConnect的问题`~~还是代码计算问题!~
页:
[1]