Sending and Receiving Objects Over the Internet

February 18, 2011

Object Transmission Testing

Object Transmission Testing

http://www.silversmalltalk.com/

This is a small test to validate some ideas for a general object communication class.

There are two browsers open in the image. The test consists of sending a serialized Smalltalk object from one browser to the other and opening an inspector on the received object.

Here is the code for opening the channel:

Channel open: 'test-1'
handler: [:x | (Json decode:x) asObject inspect].

And the code for sending an object:

Channel send:
(Json encode: {{
sender: 'BROWSER ONE',
message: 'hello browser two'
}})

You need to open the channel first on both browsers. Then you can send as many message objects as you wish. Note that both browsers will receive all messages. An object communication class would mask senders from receiving their own messages.

A few notes about the code:

  • there is a new class Json for encoding/decoding objects
  • “asObject” is a new unary message that can be sent to any JavaScript object as well as any Smalltalk object. It will encapsulate a native JavaScript object in a NativeObject Smalltalk object.
  • in sending the message, I am using a shorthand way of creating a Dictionary

This is the basic underlying Smalltalk object transmission mechanism.

Now the task is to build some protocols on top of it for more conveniently communicating with objects.

After that, we can deal with objects that contain messages.

Advertisements

4 Responses to “Sending and Receiving Objects Over the Internet”

  1. Jose Says:

    Peter, the quicksilver URL http://www.silversmalltalk.com/ generates a js error:

    Error: console is not defined
    Archivo de origen: http://silversmalltalk.appspot.com/quicksilver/kernel/vm.js
    Línea: 42

    Showing background picture without Transcript Window, context menu not works…

    I use Firefox 3.6.13 on Mac OS X 10.6.6 (On Google chrome and Opera works fine)

  2. Peter Fisk Says:

    Jose,

    I have added a debug flag to the quicksilver.js file:

    Smalltalk.vars.debug = false;

    If the flag is not set, the logging code in Vm will not execute.

    Hopefully, this will fix the problem for you.

    — Peter

  3. Andy Burnett Says:

    I wonder if it worth defining an ‘application’ class that would be the default handler for channel communication. That way, the server – or other clients – could simply send message objects without needing to know the receiving object name.

    Ideally, I want to be able to e.g. have the server send the message “alert: ‘scheduled maintenance in 10 minutes'” , and all the listening clients would respond as appropriate.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: