- Callbacks are interfaces specifying methods to be executed when certain events occur.
- Callbacks give you an object-oriented approach to the advanced features of SmartSockets.
- SmartSockets provides a number of different types of callbacks including: subject, process, default, read, write, server create, server destroy, and error.
- The two most common types of callbacks used in a SmartSockets application are:
- process callbacks, specifying a
process
method that is invoked when a message of a given type is to be processed. In the Java library, this includes the functionality of subject callbacks in the C library.
- subject callbacks, specifying a
process
method that is invoked when a message addressed to a given subject is to be processed.
- default callbacks, specifying a
handle
method which is invoked when there is no subject callback available for the given message type.
- Subject, process, and default callbacks are invoked by a call to TipcSrv.process().
- Server create callbacks are executed whenever an RTclient connects or reconnects to RTserver. Server destroy callbacks are executed when an RTclient loses its connection to RTserver.
- The convenience method TipcSrv.mainLoop can be used to read and process incoming messages from RTserver. It replaces repeated calls to TipcSrv.next and TipcSrv.process.
- TipcMsg.setNumFields can be used to reset the data part of a message. This is useful if you want to re-use the message.
- In situations where there are no SmartSockets standard message types to meet your requirements, you can create user-defined message types.
- User-defined message types are created with a call to TipcSrv.createMt. This takes three arguments
- a name, which is an identifier
- a unique number (greater than zero)
- a grammar, which defines what the data part of the message looks like
- A user-defined message type must be defined consistently, with TipcSrv.createMt, in all programs that use the message type. Once defined, it is treated no differently from a SmartSockets standard message type.