I'm missing something like: 'isConnected' on ClientDolphin class (open-dolphin)

170 Views Asked by At

If I run following java class, no exception or error message occures, but I'm sure that connection cannot be established (GrailsApplication1 is not running, and 'url' is not pointing to any bean):

public class ConnectNow {

private void connect() {
    ClientDolphin dClient = new ClientDolphin();

    dClient.setClientModelStore(new ClientModelStore(dClient));
    String url = "http://localhost:8080/GrailsApplication1/";
    ClientConnector connector = new HttpClientConnector(dClient, url);
    connector.setCodec(new JsonCodec());
    dClient.setClientConnector(connector);
    dClient.send("Hi from client");
}

public static void main(String[] args) {
    ConnectNow cn = new ConnectNow();
    cn.connect();
    System.out.println("End");
}

}

Soo, how can I recognize if connection is established? I'm newbie in client/server dev, so maybe I'm missing something obvious.

Thanks for any advice, or doc reference!

1

There are 1 best solutions below

5
On

Now, I figured it out... Key is that I have to run the code as an Application, in this case javafx app. Then, if you try to transmit something (dClient send "Hi... - in this case), app tries to send a message, and you get ConnectException: Connection refused, if there is nothing running on url.

This seems to me as shortest version of open-dolphin server accessibity test:

import javafx.application.Application;
import javafx.stage.Stage;
import org.opendolphin.core.client.ClientDolphin;
import org.opendolphin.core.client.ClientModelStore;
import org.opendolphin.core.client.comm.ClientConnector;
import org.opendolphin.core.client.comm.HttpClientConnector;
import org.opendolphin.core.comm.JsonCodec;

/**
 *
 * @author Václav Hanton
 */
public class ConnectNow extends Application {

    private void connect() {
        ClientDolphin dClient = new ClientDolphin();

        ClientModelStore mStore = new ClientModelStore(dClient);
        dClient.setClientModelStore(mStore);
        String url = "http://localhost:8080/GrailsApplication1/";
        ClientConnector connector = new HttpClientConnector(dClient, url);
        connector.setCodec(new JsonCodec());

        dClient.setClientConnector(connector);
        dClient.send("Hi from client");
    }

    public static void main(String[] args) {
        ConnectNow cn = new ConnectNow();
        cn.connect();
        Application.launch();
    }

    @Override
    public void start(Stage stage) throws Exception {
        System.out.println("Started");
    }
}