Ticket #1206: UDPListen.au3

File UDPListen.au3, 1.2 KB (added by MrBeatnik <palebluecreations@…>, 15 years ago)

This is the receiving script - listening for UDP packets.

Line 
1#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
2#AutoIt3Wrapper_outfile=UDPListen.exe
3#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
4#include <GUIConstantsEx.au3>
5
6;Set VARS
7        ;Packet Vars
8        global $socketA
9        global $myIP = @IPAddress1, $myPort = 5001
10
11        ;Form Looping Vars
12        global $loopNum=0,$dataTXT="",$Form1,$Label1
13
14
15;Start App
16        _startup()
17
18        While 1
19                $data = UDPRecv($socketA, 500)
20                _updateForm($data)
21        WEnd
22
23
24Func _startup()
25        ;Setup Form to show receiving packets
26        $Form1 = GUICreate("Incoming UDP Packets", 633, 448, 193, 125)
27        $Label1 = GUICtrlCreateLabel("PacketOut", 56, 24, 500, 345)
28        GUISetState(@SW_SHOW)
29
30        ;Init UDP
31        UDPStartup()
32
33        ;Open socket to receive
34        $socketA = UDPBind($myIP, $myPort)
35        If @error <> 0 Then
36                msgbox(0,"Bind Error","Error: " & @error)
37                Exit
38        EndIf
39EndFunc
40
41
42
43Func _updateForm($data)
44        ;Start Update Form:
45        If $data == "" Then
46                $data="No data received..."
47        Else
48                $data="Data received: " & $data
49        EndIf
50        $loopNum += 1
51        if $loopNum == 25 Then
52                ;Clear form so it doesn't scroll off screen
53                $dataTXT=""
54                $loopNum=0
55        EndIf
56        $dataTXT &= @CRLF & $data
57        GUICtrlSetData($Label1,$dataTXT)
58EndFunc