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. You may find it helpful to minimize Program Manager to reduce screen clutter.
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 from the client:
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:
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'
If you wish, you could load one copy of J, and enter the following command to load the second copy as a server (change the directory reference as appropriate):
wd 'winexec "\j3\j.exe system\packages\dde\server1.ijs"'
You could also create a new Shortcut or Program Manager item, which loads J with this script file as its profile file.
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:
exit
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.