Waiting for packets
Once everything is set up, and the script has announced its presence,
it really just needs to sit back and listen to the
<presence/> elements that come in.
If one of these is from the intended notification recipient, and the
availability state is right (i.e., not in dnd mode),
we know that the circumstances are appropriate for sending the
notification.
But the elements being sent over the stream from the server don’t
spontaneously get received, parsed, and dispatched; we can control
when that happens from the script.
This is the nub of the symbiosis between the
element events and the procedural routines, and it’s name is
process().
Calling process() will check on the stream to
see if any XML fragments have arrived and are waiting to be picked
up. If there are any, Steps 3 through 5, shown in
Figure 8-6 and described in
Section 8.3.4, are executed. The numeric value
specified in the call to process() is the number
of seconds to wait for incoming fragments if none is currently
waiting to be picked up. Specifying no value (or 0) means that
the method won’t hang around if nothing has arrived. Specifying a
value of 30 means that it will wait up to half a minute. We really
want something in between, and it turns out that waiting for up to a
second for fragments in a finite loop like this:
for i in range(5): con.process(1)
will allow for a slightly stuttered arrival of the
<presence/> elements that are sent to the script as a result of the server-initiated probes. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access