Sample Messaging Code?

4 views
Skip to first unread message

dbfreq

unread,
May 12, 2009, 8:51:23 AM5/12/09
to BLIP Protocol
Thanks for making these classes available, Jens.

I've looked through the documentation and the sample echo servers
included in the download. Is there any sample code available that
makes use of a message's properties to route messages, invoke methods
and return values? Specifically, I'd like to see BLIP used in a
manner similar to DO, where a message from a client invokes a method
on the server and receives the method's return value as its response.

I'm assuming that the server's BLIP dispatcher could read a property
on a message to determine which instance the message is directed to
and then formulate the method call, pass it to the instance, take the
return value and package that back up and send it back to the
requesting client as the response to the original request. But, if
sample codes exists to demonstrate the proper way to do this, I'd
really benefit from looking through it.


Thanks.

Brad

Jens Alfke

unread,
May 12, 2009, 11:37:38 AM5/12/09
to dbfreq, BLIP Protocol

On May 12, 2009, at 5:51 AM, dbfreq wrote:

> I'm assuming that the server's BLIP dispatcher could read a property
> on a message to determine which instance the message is directed to
> and then formulate the method call, pass it to the instance, take the
> return value and package that back up and send it back to the
> requesting client as the response to the original request.

Well, the dispatcher can be given rules (predicates), and when a rule
is matched, a particular message will be sent to a particular object.
But it can't do anything nearly as fancy as what you're saying — it
can't pull properties out and use them as parameters in the message
call, or call different objects based on different property values.
You'd have to write that code yourself.

—Jens

dbfreq

unread,
May 12, 2009, 12:47:47 PM5/12/09
to BLIP Protocol
I had another look through the dispatcher and I think I understand it
better now. It looks like the dispatcher, configured with the proper
predicates, does exactly what I'd like it to do.

I'm new to programming, so, please excuse me if this is a simple /
stupid question, but, is it possible to use the dispatcher to invoke a
method on another object, take the return value from the invoked
method, and send it back as the response to the original request?

For example, hitting the 'Play' button on the iPhone sends a BLIP
message with a body of @"dvdPlay", and a value of @"dvdPlayer" for the
profile parameter. The server's dispatcher has a predicate that tells
it that any messages with the profile parameter set to @"dvdPlayer"
get sent to the dvdPlayer instance. The dvdPlay method starts the DVD
playing and returns the new state of the DVD player (ie, isPlaying).
Is there any way to capture that return value and send it back as the
response to the original request? Or, is it better to have the
dvdPlay method send a separate BLIP message from the server back to
the client, telling the client that the state of the DVD Player has
changed? If it's better to have the server send a new message back to
the client with the current status of the DVD Player, what is the
response of the original request?

Thanks.

Brad

Jens Alfke

unread,
May 12, 2009, 1:47:30 PM5/12/09
to dbfreq, BLIP Protocol

On May 12, 2009, at 9:47 AM, dbfreq wrote:

> I'm new to programming, so, please excuse me if this is a simple /
> stupid question, but, is it possible to use the dispatcher to invoke a
> method on another object, take the return value from the invoked
> method, and send it back as the response to the original request?

No. The target methods called by the dispatcher are assumed to take
the BLIPRequest object as a parameter, and not return anything. It's
each target method's responsibility to interpret the contents of the
request, do whatever it needs to do, and optionally put response data
into the associated BLIPResponse object and send it.

It's certainly possible to implement something like what you're
talking about, but it would be a fair bit of work to marshal and
unmarshal parameters automatically.

—Jens

Reply all
Reply to author
Forward
0 new messages