ivohlavsa Posted February 23, 2011 Share Posted February 23, 2011 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 More sharing options...
jvanegmond Posted February 23, 2011 Share Posted February 23, 2011 (edited) 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 February 23, 2011 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
jvanegmond Posted February 23, 2011 Share Posted February 23, 2011 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 github.com/jvanegmond Link to comment Share on other sites More sharing options...
ivohlavsa Posted February 23, 2011 Author Share Posted February 23, 2011 (edited) 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 February 23, 2011 by ivohlavsa Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 23, 2011 Moderators Share Posted February 23, 2011 ivohlavsa,I'll test in in gameI take it you have not read this. Perhaps you might choose your words more carefully the next time you post? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now