找回密码
 加入
搜索
查看: 2061|回复: 3

[系统综合] 多进程共享数据的问题

[复制链接]
发表于 2012-2-15 12:43:20 | 显示全部楼层 |阅读模式
这是一个简单的端口检测程序,一旦检测到端口打开,则提示并退出,用了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 <> -1  Then
                $result = 1
        Else
                $result = 0
        EndIf
        _CoProcSend($gi_CoProcParent, $result)
        Sleep(3000)
        WEnd
EndFunc        
发表于 2012-2-18 11:20:24 | 显示全部楼层
我现在用笨办法UDP通讯让两个进程交换数据
发表于 2012-2-18 11:21:37 | 显示全部楼层
P版出手,肯定有更专业的办法
汇编对内存方面的操作能不能实现多个进程共享某一块内存里的数据呢
发表于 2012-2-18 15:24:28 | 显示全部楼层
等待大牛出手。。。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-20 17:48 , Processed in 0.105697 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表