Discussion of the DdeClient
For an application to become a DDE client, it simply creates an instance of the DdeClient class and connects it to a DDE server. The connection message to a DDE server includes the server name and the name of the topic the client is interested in. A DDE client can be established by running the following code:
ddeClient := DdeClient new.
ddeClient connect: serverName topic: topicName.
where serverName and topicName are instances of String.
Note:
Once a DdeClient connects to a server for a particular topic, it cannot connect to a different server or a different topic on the same server, unless it first terminates the existing connection and then reconnects to a new server, or topic, or both.
Queries
A client application can query for information about the DDE servers currently running. There are three methods of DdeClient that provide data on all of the available DDE servers:
queryAll
Queries all servers for all possible topics, and returns a Dictionary where the key is the application name and the value is a Set containing all of the topic names supported by that application.
queryServersFor:
Queries all servers for a specified topic, and returns a Set containing the names of the applications that handle the topic.
queryTopicsFrom:
Queries a particular named server for all of the topics it supports, and returns a Set containing the names of the topics handled by that server.
Requesting data
A client application can request a specific data item from the server using the requestData:format: message:
result := ddeClient requestData: item format: format
The format specification tells the server what format the client is interested in. If the server does not respond with data, the result is nil.
Hot- and warmlinking to items
A client application might want a DDE server to notify it when a particular data item changes. It does this by sending one of two messages to the DdeClient:
ddeClient hotLink: item format: format.
or
ddeClient warmLink: item format: format.
The format specification tells the server what format the client is interested in. The hotLink:format: or warmLink:format: messages return true to indicate that the server supports the data item in the specified format. However, if either message returns false, then the server either does not support the data item or it does not support the specified format for the data item.
For a client application to receive notification of a change for a hotlinked data item, it must register the DdeNdataCallback with its DdeClient object. When the hotlink callback runs, the actual changed data is passed in the DdeCallbackData object where it can be retrieved with the data message. For example, to register the DdeNdataCallback, a client application uses:
ddeClient
addCallback: DdeNdataCallback
receiver: self
selector: #hotLink:clientData:callData:
clientData: nil
The client's implementation of the hotlink callback method looks like:
hotLink: ddeClient clientData: clientData callData: callData
"The data at the server has changed. Go get the data."
| item format string data|
item := callData item.
format := callData format.
data := callData data.
String := data notNil
ifTrue: ['Data arrived %1 %2']
ifFalse: ['Data unavailable %1 %2'].
Transcript
cr;
show: (string bindWidth: item with: format).
Likewise, for a client application to receive notification of a change for a warmlinked data item, it must register the DdeNchangeCallback with its DdeClient object. However, unlike a hotlink callback, the changed data item is not passed to the callback in the DdeCallbackData object. To obtain the changed data, the client application must explicitly request it from the server by using the requestData:format: message on the DdeClient passed to the callback as the first parameter. This message returns the data from the server if it is available, otherwise it returns nil. The following code warmlinks the client application to an item and processes the event when that item changes at the server:
ddeClient
addCallback: DdeChangeCallback
receiver: self
selector: #warmLink:clientData:callData:
clientData: nil
and
warmLink: ddeClient clientData: clientData callData: callData
"The data at the server has changed. Go get the data."
| item format string data|
item := callData item.
format := callData format.
data := ddeClient requestData: item format: format.
string := data notNil
ifTrue: ['Data arrived %1; %2']
ifFalse ['Data unavailable %1; %2'].
Transcript
cr;
show: (string bindWidth: item with: format).
Coldlinking items
A client application unlinks from an item previously hot- or warmlinked by sending the coldLink:format: message to a DdeClient:
ddeClient coldLink: anItem format: aString.
This message returns true if the item successfully unlinks. It returns false if the item cannot be unlinked. An item cannot be unlinked if it was never linked, or if the item, its format, or both did not exist on the server. After this message is sent, the client application is no longer notified of updates to that item from the server. However, it can still use the requestData:format: method on the DdeClient to query the server for the data item.
Sending data to the server
A client application can send data to the DDE server by sending the sendItem:value:format: message to the DdeClient object:
ddeClient sendItem: item value: value format: format.
The form of this message is the same as sendItem:value:format: of a DdeServer object. Here, true is returned if the server accepts the data; otherwise, false is returned.
Executing commands at the server
A client application can ask a server to run a command by sending the message execute: to the DdeClient object along with a string containing the command to be run:
ddeClient execute: 'someCommand param1 param2'
Here, true is returned if the server runs the command, and false is returned if it cannot.
Last modified date: 01/29/2015