DDE Request

The following example requests data from DDE Server. You can use our DDE Server example.

final String SERVICE = "MyServer";
final String TOPIC = "MyTopic";

try
{
    final DDEClientConversation conversation = new DDEClientConversation();
    // We can use UNICODE format if server prefers it
    //conversation.setTextFormat(ClipboardFormat.CF_UNICODETEXT);

    System.out.println("Connecting...");
    conversation.connect(SERVICE, TOPIC);

    for (int i = 0; i < 1000; ++i)
    {
        try
        {
            System.out.println("Requesting data... i=" + i);
            String data = conversation.request("MyRequest");
            System.out.println("Item(" + i + ") data: " + data);
        }
        catch (DDEException e)
        {
            System.out.println("Exception on request: " + e);
        }
    }

    System.out.println("Disconnecting...");
    conversation.disconnect();
    System.out.println("Exit from thread");
}
catch (DDEMLException e)
{
    System.out.println("DDEMLException: 0x" + Integer.toHexString(e.getErrorCode()) + " " + e.getMessage());
}
catch (DDEException e)
{
    System.out.println("DDEClientException: " + e.getMessage());
}
catch (Exception e)
{
    System.out.println("Exception: " + e);
}

Download RequestExample.java
Download all examples and binaries

Command line to run example:

java -cp .;pretty-tools-JDDE-2.0.4.jar RequestExample