>> << Ndx Usr Pri Phr Dic Rel Voc !: wd Help User

# Examples

The following examples illustrate. First we set up a J to J connection manually:

Load two copies of J, and arrange the windows so that both are visible at the same time.

In one window (the server), define the service name as jserver:

       wd 'ddename jserver'

In the other window (the client), use the ddepoke command to send data to the server:

       wd 'ddepoke jserver abc xyz mydata'

In the server, check the value of `wdq`

       wdq
    +----------+-----------+
    |syshandler|sys_handler|
    +----------+-----------+
    |sysevent  |sys_ddepoke|
    +----------+-----------+
    |sysdefault|sys_default|
    +----------+-----------+
    |systopic  |abc        |
    +----------+-----------+
    |sysitem   |xyz        |
    +----------+-----------+
    |sysdata   |mydata     |
    +----------+-----------+

This indicates the character string `mydata` was sent to the J server, with topic `abc` and item `xyz`.

Now terminate the connection in the client window:

       wd 'ddedis'

In practice, you will want to set up a protocol that will enable client and server to communicate back and forth. To illustrate this we describe typical hot and cold links that use J as an execution server.

J to J Hot Link
The script system\packages\dde\server1.ijs implements the server side of a DDE hot link. The protocol is as follows:

- the server defines its service name to be: jserver
- the client issues a ddestart command, using any topic and item
- the client issues a ddepoke for this topic and item, with the data being an executable J sentence
- the server executes the sentence, and returns the result with a ddeadvise command
- the client can issue a ddepoke repeatedly. If the data is `close` the topic and item are closed. If the data is `exit` the J server program is exited. If the data is `off` the J server task is terminated.

  If you have not already done so, load 2 copies of J and minimize Program Manager to reduce screen clutter. In one copy of J (the server), enter:

         load 'system\packages\dde\server1.ijs'

  The server displays a Windows dialog box, which will be used to illustrate the conversation. If you wish, you can also minimize the server window.

  In the other copy of J (the client), enter the following to initialize the client

         load'system\examples\dde\client1.ijs'

  You should see some J code executed in the server window, and the result in the client session.

  You can now send J sentences to be evaluated:

         cmd 'i.4 5'
       0  1  2  3  4
       5  6  7  8  9
      10 11 12 13 14
      15 16 17 18 19

  `cmd` sends its argument using ddepoke:

      cmd=: 3 : 0
      wd 'ddepoke jserver top item *',y.
      )

  The server window shows the conversation.

  Try other expressions, for example, to create and use names:

         cmd 'mydata=: 2 3 5 7'
      2 3 5 7

         cmd '#mydata"'
      4

  To close the server, enter:

         cmd 'off'

  (The server does not respond.)

  J to J Cold Link
  The script system\packages\dde\server2.ijs implements the server side of a DDE cold link. The protocol is as follows:

- the server defines its service name to be: jserver
- the client issues a ddepoke for any topic and item, with the data being an executable J sentence
- the server executes the sentence, and saves the result with the topic and item
- the client issues a ddereq command for the topic and item
- the server responds with the corresponding result
- the client can issue a ddepoke and ddereq repeatedly. If the ddepoke data is `exit`
  the J server program is exited. If the data is `off` the J server task is terminated.

  As before, load 2 copies of J and minimize Program Manager. In the server copy of J, enter:

         load 'system\packages\dde\server2.ijs'

  then minimize the server window.

  To initialize the client copy of J:

         load'system\examples\dde\client1.ijs'

  Use cmd to set expressions:

         cmd 'i.4 5'
       0	 1	 2	 3	 4
       5	 6	 7	 8	 9
      10	11	12	13	14
      15	16	17	18	19

  `cmd` sends its argument using ddepoke, and retrieves the result using ddereq:

      cmd=: 3 : 0
      wd 'ddepoke jserver top item *',y.
      wd 'ddereq jserver top item'
      )

  Try other expressions, then to close the server, send:

         cmd 'off'

  (The server does not respond.)

  Note that the hot link protocol is simpler than the cold link protocol, since once it is set up, the client need only issue one command to send a sentence and retrieve the result. Also, the ddereq command used with the cold link may time out if the server is not ready to send the data item requested.

>> << Ndx Usr Pri Phr Dic Rel Voc !: wd Help User