contents   index   previous   next



Using a DSP object

 

Once a DSP object is created using the method described above, every DSP object behaves in exactly the same way. Once the functions are set up, the transport layer of the protocol is hidden.

 

The basic idea is that all DSP objects are in fact references to objects on the remote side, and they will remain so except under certain circumstances (described below). When a connection is first established, it is a reference to the global object. Members of the remote global object can be accessed as members of the connection. But they remain references, so var print = connection.Clib.printf will not actually make a remote call to the server. At the appropriate time, print will be resolved into Clib.printf() and sent to the server in the appropriate manner. The circumstances which can trigger a de-referencing and remote call are:

 

Calling functions - When a DSP reference is called as a function, it gets resolved into the appropriate path and the function is called on the remote server. All parameters are converted to source with ToSource() and passed to the server, and set back afterwards (in case any were passed by reference). The client waits for the return value from the server and returns that as the result of the function call. This makes calling functions transparent to the client, so connection.Screen.writeln("hi") will actually call Screen.writeln on the server and print out "hi".

 

Setting a value - When a value is put to a DSP reference, such as connection.globalCount = 5, a remote call to the server is generated, and the remote value is updated. The above case acts just as if globalCount = 5 was executed on the server.

 

Implicitly - When a DSP reference is converted to a primitive, then it gets de-referenced. This implicit conversion happens mostly in operator expressions, in which both values are converted to primitives first. So var myCount = connection.globalCount + 1 will get the value of globalCount from the server and add one to it. This can also be accomplished explicitly with ToPrimitive(), but the method below is more straightforward and understandable. The explicit use of ToPrimitive() on DSP references is discouraged.

 

Explicitly - Any DSP reference can be explicitly de-referenced with a call to.dspGetValue. Once an object has been de-referenced this way, any subsequent accesses will not cause a remote call, and changes will only affect the local copy. Note that calling a function in this way will result in the function being called on the local client, not the server.

 


DSP object instance methods