找回密码
 加入
搜索
查看: 3463|回复: 1

[网络通信] 求监听本机任意端口的源代码

[复制链接]
发表于 2010-5-4 17:22:23 | 显示全部楼层 |阅读模式
悬赏50金钱未解决
局域网中,服务器程序是C++做的,不停的向本机指定端口发送数据,我想要做的就是接收并处理这些数据,但是照着帮助中的例子做,能打开端口却收不到数据,请各位帮帮忙,帮我写个代码,谢谢

发表于 2010-5-6 17:55:59 | 显示全部楼层
#AutoIt3Wrapper_run_debug_mode=Y
#include <ButtonConstants.au3>



#include <EditConstants.au3>



#include <GUIConstantsEx.au3>



#include <StaticConstants.au3>



#include <WindowsConstants.au3>



Opt("GUIOnEventMode", 1)



$ip=@IPAddress1



UDPStartup()



$socket = UDPBind(@IPAddress1, 65532)

msgBox(0,"发送",$socket)

If @error <> 0 Then Exit



$Form1 = GUICreate("测试-发送", 291, 208, 192, 114)



GUISetOnEvent($GUI_EVENT_CLOSE, "_ext")



$Edit1 = GUICtrlCreateEdit("", 8, 28, 273, 116, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_CLIPSIBLINGS,$ES_READONLY,$ws_VSCROLL))



GUICtrlSetData(-1, "")



$Button1 = GUICtrlCreateButton("退出[&Esc]", 168, 176, 113, 25, 0)



GUICtrlSetOnEvent(-1, "_ext")



GUISetState(@SW_SHOW)





While 1



$i = 1

While  $i<80000



        

    GUICtrlSetData($edit1, $i & @CRLF & GUICtrlRead($edit1))

        $connect = UDPOpen(@IPAddress1,514);udp发送数据测试

        $status = UDPSend($connect, StringToBinary($i ,4))

    $i=$i+1

WEnd



                     

WEnd





Func _ext()



    UDPCloseSocket($socket)



        UDPShutdown()



        Exit



EndFunc

----------------------------------------------------
#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

$ip=@IPAddress1

UDPStartup()

$socket = UDPBind(@IPAddress1, 514)
MsgBox(0,"接收",$socket)

If @error <> 0 Then Exit


$Form1 = GUICreate("测试-接收", 291, 208, 192, 114)

GUISetOnEvent($GUI_EVENT_CLOSE, "_ext")

$Edit1 = GUICtrlCreateEdit("", 8, 28, 273, 116, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_CLIPSIBLINGS,$ES_READONLY,$ws_VSCROLL))


GUICtrlSetData(-1, "")


$Button1 = GUICtrlCreateButton("退出[&Esc]", 168, 176, 113, 25, 0)

GUICtrlSetOnEvent(-1, "_ext")

GUISetState(@SW_SHOW)


While 1

        $data = UDPRecv($socket, 500,1)
        If $data <> "" Then
                        $data = BinaryToString($data,4)
                        GUICtrlSetData($edit1, $data & @CRLF & GUICtrlRead($edit1))
                EndIf

WEnd



Func _ext()

    UDPCloseSocket($socket)

        UDPShutdown()

        Exit

EndFunc
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-6 20:59 , Processed in 0.078261 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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