Receiving Events from a Storyboard Application

In order to receive events the from a Storyboard application, a client program must first create a receive communication channel using the gre_io_open() function. This function takes the name of a channel to create and the mode in which to open the channel, for reading or writing. Receiving clients must open it for reading.

To receive events from a tcp socket, gre_io_open() needs to specify a tcp URI and optional channel name / port number. To specify the use of a tcp port, a tcp uri "tcp://" needs to prefix the optional Storyboard IO channel name when openning the read only channel. For example: gre_io_open("tcp://my_channel", GRE_IO_TYPE_RDONLY). Internally a channel name string is hashed into a tcp port number. The tcp sender should be configured with same channel name or port number.

Once the communication channel is created, then the client program then must call gre_io_receive() in order to receive and process events.

The client communication channel can be created in either a blocking or non-blocking mode.   By default the gre_io_receive() function will not return unless there is an event available or an error has occurred.

Once an event has been received the data can be unserialized into its standard components using the gre_io_unserialze() function.

char    *name = (char *)arg;
gre_io_t *rhandle;
gre_io_serialized_data_t *buffer = NULL;
int ret;
char *revent_name;
char *revent_target;
char *revent_format;
uint8_t *revent_data;
int offset, i, rnbytes;

rhandle = gre_io_open(name, GRE_IO_TYPE_RDONLY);
if(rhandle == NULL) {
    printf("Can't open IO channel %s\n", name);
    return 0;

printf("Waiting on channel [%s]\n", name);
while(1) {
    ret = gre_io_receive(rhandle, &buffer);
    if(ret < 0) {
        printf("Problem receiving data on channel [%s]\n", name);

     rnbytes = gre_io_unserialize(buffer,
                            (void **)&revent_data);
     printf("Event Received [%s] on channel [%s]:\n", revent_name, name);
     printf(" Event Target: [%s]\n", revent_target);    
     printf(" Event Format: [%s]\n", revent_format);    
     printf(" Event Data (%d bytes):\n", rnbytes);    

Was this article helpful?
1 out of 1 found this helpful