home support FAQ resources services partners contact us contact us
 Web Application Previous  Next  
 Tutorial

}
event_handler incoming_data()
{
update_traffic_counter();
case of ping: handle_event(ping);
}
while(not_done())
{
wait_for_event();
case of network_data: handle_event(incoming_data);
}

The code looks bigger, but also much clearer.The main loop waits for an event to
happen. If it finds that an event happened and that it was triggered due to incoming
network data, it dispatches this event using the central procedure handle_event().
This function then determines a handler for the event and calls it.The handler in turn
updates the traffic counter and launches another event if the first event was a ping.
After dispatching the event using handle_event() again, a pong is sent.
Alternatively, both ping() and incoming_data() could register themselves to
the event “incoming_data”. However, creating two different events gives a
greater variety of events and thus allows for much more detailed, targetoriented
processing.

It’s a bit strange at first getting used to event-based processing of information (it works
similarly to a finite-state machine), but it has many advantages:
n A modular structure is forced on the application. Each module works independently
of the other modules and can easily be changed, exchanged, or extended.
n Any part of the program can trigger any kind of event and thus enforce any
type of reaction in the application (in other words, you can control any part of
your code from any other part of your code).
Previous  Next  
Link Partners: Asia florist, Flowers to India, Hong kong flowers, Site submit, Cheap web hosting, China florist, Japan florist