Jump to content

UDPRect is slow


 Share

Recommended Posts

I think UDPRect function is slow for my purpose. It stops the program for 100 miliseconds and wait if some data comes to udp (no matter number of data i receive). Can I speed it up somehow? For example check if there are data on udp (very fastly - 1-10 miliseconds) and if they are then read them (slowly - 100ms)

simple script :

while 1

UDPRecv($socket, 500) ; here it waits 100 ms every time

doSomething()

wend

Link to comment
Share on other sites

Before anyone has doubts, I've taken my time to confirm the claim in the OP. It seems rather problematic.

Test script:

UDPStartup()

OnAutoItExitRegister("Cleanup")

$socket = UDPBind("127.0.0.1", 1337)
If @error <> 0 Then Exit

While 1
    $init = TimerInit()
    $data = UDPRecv($socket, 50)
    ConsoleWrite("UDPRecv took: " & TimerDiff($init) & "ms" & @CRLF)
    If $data <> "" Then
        ConsoleWrite("UDP DATA: " & $data & @CRLF)
    EndIf
WEnd

Func Cleanup()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc

Result:

UDPRecv took: 99.7942725924949ms
UDPRecv took: 100.59651028205ms
UDPRecv took: 100.615390227676ms
UDPRecv took: 100.60259026454ms
UDPRecv took: 100.629790186204ms
UDPRecv took: 100.711069952119ms
UDPRecv took: 101.13154874114ms
UDPRecv took: 100.614430230441ms
UDPRecv took: 100.597790278364ms
UDPRecv took: 100.582430322601ms
UDPRecv took: 102.298585380074ms
UDPRecv took: 99.7955525888085ms
UDPRecv took: 100.615390227676ms
UDPRecv took: 100.625630198185ms
UDPRecv took: 100.58851030509ms
UDPRecv took: 100.631070182518ms
UDPRecv took: 100.684510028611ms
Edited by Manadar
Link to comment
Share on other sites

Oh, I've also found the answer. When there is NO DATA available, UDPRecv waits 100ms for any incoming data. The solution is to make sure there is always data available:

UDPStartup()

OnAutoItExitRegister("Cleanup")

$socket = UDPBind("127.0.0.1", 1337)
If @error <> 0 Then Exit

$h = UDPOpen("127.0.0.1", 1337)

While 1
    UDPSend($h, Chr(0))
    $init = TimerInit()
    $data = UDPRecv($socket, 50)
    ConsoleWrite("UDPRecv took: " & TimerDiff($init) & "ms" & @CRLF)
    If $data <> "" Then
        ConsoleWrite("UDP DATA: " & $data & @CRLF)
    EndIf
WEnd

Func Cleanup()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc

Result:

UDPRecv took: 0.0419198792707477ms
UDP DATA: 0x00
UDPRecv took: 0.0396798857219291ms
UDP DATA: 0x00
UDPRecv took: 0.034239901389084ms
UDP DATA: 0x00
UDPRecv took: 0.0323199069186681ms
UDP DATA: 0x00
UDPRecv took: 0.034239901389084ms
UDP DATA: 0x00
UDPRecv took: 0.0422398783491504ms
UDP DATA: 0x00
UDPRecv took: 0.0406398829571371ms
UDP DATA: 0x00
UDPRecv took: 0.0403198838787344ms

If you changed your condition to:

If $data <> "" AND $data <> Chr(0) Then
        ConsoleWrite("UDP DATA: " & $data & @CRLF)
    EndIf

The result would be:

UDPRecv took: 0.0495998571524114ms
UDPRecv took: 0.0412798811139424ms
UDPRecv took: 0.0275199207426283ms
UDPRecv took: 0.0243199299586017ms
Link to comment
Share on other sites

Its fucking smart :) How could you find solution so fast? I was thinking to use windows api directly but this is much more better

Anyway it seems to be working, I'm just doing some tests and evening I'll test in in game. Thx

Just note: I should not send Chr(0) after I receive data from external application, otwerwise it will increase number of unreceived datagrams

Edited by ivohlavsa
Link to comment
Share on other sites

  • Moderators

ivohlavsa,

I'll test in in game

I take it you have not read this. Perhaps you might choose your words more carefully the next time you post? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...