多进程共享数据的问题
这是一个简单的端口检测程序,一旦检测到端口打开,则提示并退出,用了CoProc来建立一个新的进程探测,如果不用多进程的话,主进程在探测时会卡死,现在的问题是全局变量无法在子进程中使用,比如我想传递$input中的IP或者端口进子进程是不行的,大家有什么好的办法么?#NoTrayIcon#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include "CoProc.au3"
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\Form2.kxf
$Form2 = GUICreate("端口探测程序", 413, 229, 298, 136)
$Label1 = GUICtrlCreateLabel("探测地址:", 24, 43, 74, 18)
GUICtrlSetFont(-1, 11, 400, 0, "宋体")
$Label2 = GUICtrlCreateLabel("探测端口:", 24, 99, 74, 18)
GUICtrlSetFont(-1, 11, 400, 0, "宋体")
$Input1 = GUICtrlCreateInput("61.135.169.105", 104, 39, 257, 22)
GUICtrlSetFont(-1, 11, 400, 0, "宋体")
$Input2 = GUICtrlCreateInput("80", 104, 95, 257, 22)
GUICtrlSetFont(-1, 11, 400, 0, "宋体")
$Start = GUICtrlCreateButton("开始", 72, 153, 97, 41)
GUICtrlSetFont(-1, 11, 400, 0, "宋体")
$Stop = GUICtrlCreateButton("停止", 232, 153, 97, 41)
GUICtrlSetFont(-1, 11, 400, 0, "宋体")
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$pid = 0
_CoProcReciver("Reciver")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
If $pid <> 0 Then ProcessClose($pid)
Exit
Case $Start
GUICtrlSetState($Start,$GUI_DISABLE)
GUICtrlSetState($Stop,$GUI_ENABLE)
$port = GUICtrlRead($Input2)
$pid = _CoProc("PortTest")
Case $Stop
GUICtrlSetState($Start,$GUI_ENABLE)
GUICtrlSetState($Stop,$GUI_DISABLE)
;MsgBox(1,"pid",$pid)
If $pid <> 0 Then ProcessClose($pid)
EndSwitch
WEnd
Func Reciver($vParameter)
If $vParameter = 1 Then
MsgBox(1,"Test","Open")
If $pid <> 0 Then ProcessClose($pid)
GUICtrlSetState($Start,$GUI_ENABLE)
GUICtrlSetState($Stop,$GUI_DISABLE)
EndIf
EndFunc
Func PortTest()
While ProcessExists($gi_CoProcParent)
TCPStartup()
$Socket = TCPConnect("61.135.169.105", 80)
TCPShutdown()
If $socket <> 1 And $socket <> 0 And $socket <> -1Then
$result = 1
Else
$result = 0
EndIf
_CoProcSend($gi_CoProcParent, $result)
Sleep(3000)
WEnd
EndFunc
我现在用笨办法UDP通讯让两个进程交换数据 P版出手,肯定有更专业的办法
汇编对内存方面的操作能不能实现多个进程共享某一块内存里的数据呢 等待大牛出手。。。。。
页:
[1]