Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: endless loops for server and tk

by Errto (Vicar)
on Aug 03, 2007 at 04:50 UTC ( #630447=note: print w/replies, xml ) Need Help??

in reply to endless loops for server and tk

A couple of general points. One, yes, add a timeout to your receiving loop. In a similar example, I just used the timeout method of the IO::Socket module. That was for TCP, but I assume there's a UDP equivalent. Second, you can use the fact that you now know you'll iterate through your loop once every some interval, you can use that opportunity to call $mw->update. So the outline is:
# setup MainWindow $mw # setup socket with timeout sub myloop { while (1) { #read from socket; #if anything read, deal with it; $mw->update(); } } $mw->after(1, \&myloop); MainLoop;
This way the main loop initializes itself and renders your window, but then your code takes over and does the GUI update as often as needed.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://630447]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2017-02-23 16:32 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (349 votes). Check out past polls.