[Stk] UdpSocket
Gary P. Scavone
gary@ccrma.Stanford.EDU
Wed, 3 Jan 2007 12:19:45 -0500
Hi Dan,
The base class of UdpSocket (Socket) offers a static function called
"setBlocking()" that can be used to set the socket as non-blocking.
I haven't used those classes extensively so I cannot say for sure how
the read() function will behave if the socket is non-blocking. It is
possible that it may return a -1 if no data is available, though that
might not be a problem for you.
Another option is to get the socket descriptor via the id() function
and then call the "select" function (not part of the class) to find
out if data is available for reading or not. The select() function
is available on most systems and is used in the Messager class in
this way.
Regards,
--gary
On 2-Jan-07, at 8:12 AM, Scholten, Dan wrote:
> I'm using the UdpSocket class from the STK and had a question on
> the readBuffer function. I want to call this method from a
> callback that runs on a set time interval (say every 30 seconds),
> but I'm not guaranteed to have received data since the last
> readBuffer call was made. It seems that this method will block
> until data is received before continuing. I wish the program to
> just continue execution regardless if any data was received or
> not. Is there a precheck I can make to see if the socket has
> received any data or a way to make the readBuffer call "timeout" if
> it does not receive data within a certain time frame?
>
> Thanks,
> Dan Scholten